Skip to content

Official assertions

Nightowl edited this page Oct 2, 2024 · 4 revisions

This page contains information about the current, officially supported assertions from the OwlDomain.Testing.Assertions package.

All asserts that accept a struct value (booleans, integers, floats, e.t.c) have a variant that accepts a nullable version of the struct.

Boolean asserts

Asserts related to the System.Boolean type.

  • IsTrue - Asserts that the given boolean value is true.
  • IsNotTrue - Asserts that the given boolean value is not true.
  • IsFalse - Asserts that the given boolean value is false.
  • IsNotFalse - Asserts that the given boolean value is not false.

Comparison asserts

Asserts used for comparing multiple values to each other.

All asserts have overloads for using the IComparable<T> and the IComparer<T> interfaces.

  • IsGreaterThan - Asserts that the given value is greater than the given expected threshold.
  • IsGreaterThanOrEqualTo - Asserts that the given value is greater than or equal to the given expected threshold.
  • IsNotGreaterThan - Asserts that the given value is not greater than the given expected threshold.
  • IsNotGreaterThanOrEqualTo - Asserts that the given value is not greater or equal to than the given expected threshold.
  • IsLessThan - Asserts that the given value is less than the expected threshold.
  • IsLessThanOrEqualTo - Asserts that the given value is less than or equal to the expected threshold.
  • IsNotLessThan - Asserts that the given value is not less than the given expected threshold.
  • IsNotLessThanOrEqualTo - Asserts that the given value is not less than or equal to the given expected threshold.
  • IsBetween - Asserts that the given value is between the given (inclusive) minimum and maximum range.
  • IsNotBetween -Asserts that the given value is not between the given (inclusive) minimum and maximum range.

Enum asserts

Asserts related to enums.

  • HasFlag - Asserts that the given value has the expected flag(s) set.
  • DoesNotHaveFlag - Asserts that the given value does not have the expected flag(s) set.

Equality asserts

Asserts used to determine equality (and inequality) between two values.

The AreEqual and the AreNotEqual asserts provide overloads for using the IEquatable<T> and the IEqualityComparer<T> interfaces.

  • AreEqual - Asserts that the two given values are considered equal. Equality is determined by using EqualityComparer<T>.Default.
  • AreNotEqual - Asserts that the two given values are not considered equal. Equality is determined by using EqualityComparer<T>.Default.
  • AreSameInstance - Asserts that the two given instances are the same instance. This check is performed using Object.ReferenceEquals, if both instances are null they are considered the same instance.

Exception asserts

Asserts related to exceptions.

The ThrowsAnyException, ThrowsExceptionOfType and ThrowsExactException asserts have overloads that provide you with the exception that was caught, in case you need to perform extra asserts on it.

Each of these asserts also contains async variants.

  • ThrowsAnyException - Asserts that the given action throws any type of an exception when invoked.
  • ThrowsExceptionOfType - Asserts that the given action throws an exception of the given type (or a derived type) when it's invoked.
  • ThrowsExactException - Asserts that the given action throws an exception exactly of the given type when it's invoked.
  • DoesNotThrowAnyException - Asserts that the given action does not throw any exception when invoked.

Numerical asserts

Asserts related to numbers and numerical values.

All asserts have support for the following numerical types: Byte, SByte, UInt16 (ushort), Int16 (short), UInt32 (uint), Int32 (int), UInt64 (ulong), Int64 (long), Single (float), Double, Decimal and for the generic math interfaces that were added for .NET 7.

  • AreEqual (within a delta) - Asserts that two numerical values are considered equivalent within a given acceptable level of inaccuracy.
  • AreNotEqual (within a delta) - Asserts that two numerical values are not considered equivalent within a given acceptable level of inaccuracy.

Null asserts

Asserts related to the nullability of a value.

  • IsNull - Asserts that the given object value is null.
  • IsNotNull - Asserts that the given object value is not null.

Default asserts

Asserts related to checking against a default value of a struct type.

  • IsDefault - Asserts that the given value is equal to the default value of the given struct type.
  • IsNotDefault - Asserts that the given value is not equal to the default value of the given struct type.