-
Notifications
You must be signed in to change notification settings - Fork 53
All types
The following checks are available for objects of any type.
Checks if the given value is equal to the expected value, fails otherwise.
var sut = "myResult";
// This one succeeds
Check.That(sut).IsEqualTo("myResult");
// This one fails
Check.That(sut).IsEqualTo("MyResult");
This is the go to checks for most of your needs. It is available for any type and has the following behaviour:
- if both values are equals from BCL point of view, they are considered equal (i.e. object.Equals(sut, expected) == true)
- for floating types (float and double), NFluent expects strict equality, but it will suggest to use IsCloseTo instead.
- for IEnumerable types, NFluent compares the content of the enumeration, recursively if necessary (for arrays of arrays, as an example). It expects items to be in the same order. If you want to compare the content of enumerations disregarding the order, please use IsEquivalentTo.
- for IDictionary types (IDictionary, IDictionary<K,V>, IReadOnlyDictionary<K,V>), NFluent checks that each key is present with the expected value.
Note: the comparison algorithm can be controlled through configuration.
Checks if the given value is equal to the expected value according to the provided comparern, customCompare.
var sut = "myResult";
Check.That(sut).IsEqualTo("myResult", new MyCustomComparer());
Checks if the given value is different to the reference value, fails otherwise.
var sut = "myResult";
// This one succeeds
Check.That(sut).IsNotEqualTo("TheResult");
// This one fails
Check.That(sut).IsNotEqualTo("myResult");
Note: the comparison algorithm can be controlled through configuration.
Checks if the given value is equal to the expected value, fails otherwise. Comparison is done using operator==.
var sut = "myResult";
// This one succeeds
Check.That(sut).HasSameValueAs("myResult");
// This one fails
Check.That(sut).HasSameValueAs("MyResult");
Checks if the given value is different to the reference value, fails otherwise. Comparison is done using operator!=.
var sut = "myResult";
// This one succeeds
Check.That(sut).HasDifferentValueThan("TheResult");
// This one fails
Check.That(sut).HasDifferentValueThan("myResult");
Checks if the given value is an instance of the specified type, fails otherwise. This check exists in generic and non generic format.
var sut = "myResult";
// Those one succeed
Check.That(sut.IsInstanceOf<string>();
Check.That(sut).IsInstanceOfType(typeof(string));
// This one fails
Check.That(sut).IsInstanceOf<int>();
You can use Which() keyword to add checks (behaves like a cast).
var sut = "myResult";
// Those one succeed
Check.That((object)sut).IsInstanceOf<string>().Which().IsEqualIgnoringCase("MYResult");
Checks if the given value is not an instance of the specified type, fails otherwise. This check exists in generic and non generic format.
var sut = "myResult";
// Those one succeed
Check.That(sut).IsNotInstanceOf<int>();
Check.That(sut).IsNotInstanceOfType(typeof(int));
// This one fails
Check.That(sut).IsNotInstanceOf<string>();
Checks if the given value is inherits from the given type, fails otherwise. This check exists in generic and non generic format.
var sut = "myResult";
// This one succeeds
Check.That(sut).InheritsFrom<object>();
Check.That(sut).InheritsFromType(typeof(object));
// This one fails
Check.That(sut).InheritsFrom<int>();
- Welcome
- How to start
- Customising error messages
-
Check.That
- All (Equality, Type)
- Reference types
- Members based
- IEnumerable (Properties, Content, Elements)
- String (Properties, Content, RegExp )
- Numeric Type(Properties, Comparisons, Floating)
- Dictionary
- Char (Properties, Value)
- IComparable
- DateTime
- DateTimeOffset
- Misc: Boolean, TimeSpan, Stream, Enum, EventWaitHandle
- Check.ThatCode
- Check.ThatDynamic
- Extensibility
- Auxiliary types (TimeUnit)
- Mocks