-
Notifications
You must be signed in to change notification settings - Fork 53
Dictionaries
Cyrille DUPUYDAUBY edited this page Jan 26, 2020
·
5 revisions
The following checks can be used on generic dictionaries.
For compatibility as well as convenience, NFluent has a broad acceptance for dictionaries:
- IDictionary implementation (non generic).
- IReadOnly<,> implementations.
- IDictionary<,> implementations.
- IEnumerable<,> implementations (as of V2.7).
- Hashtable.
Checks that the sut is a dictionary containing expectedKey as a key; fails otherwise.
var dico = new Dictionary<string, string>();
dico["myKey"] = "myValue";
// this check succeeds
Check.That(dico).ContainsKey("myKey");
// this check fails
Check.That(dico).ContainsKey("otherKey");
Checks that the sut is a dictionary containing expectedKey as a key referring to expectedValue; fails otherwise.
var dico = new Dictionary<string, string>();
dico["myKey"] = "myValue";
// this check succeeds
Check.That(dico).ContainsPair("myKey", "myValue");
// those checks fail
Check.That(dico).ContainsPair("otherKey", "otherValue");
Check.That(dico).ContainsPair("myKey", "otherValue");
Check.That(dico).ContainsPair("otherKey", "myValue");
Checks that the sut is a dictionary containing expectedValue as a value; fails otherwise.
var dico = new Dictionary<string, string>();
dico["myKey"] = "myValue";
// this check succeeds
Check.That(dico).ContainsValue("myValue");
// this check fails
Check.That(dico).ContainsValue("otherValue");
- 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