DictionaryContainsKey Constraint
DictionaryContainsKeyConstraint
is used to test whether a dictionary
contains an expected object as a key.
Constructor
DictionaryContainsKeyConstraint(object)
Syntax
Contains.Key(object)
Does.ContainKey(object)
Does.Not.ContainKey(object)
Modifiers
...IgnoreCase
...IgnoreWhiteSpace // From version 4.2
...Using(IEqualityComparer comparer)
...Using(IComparer comparer)
...Using<T>(IEqualityComparer<T> comparer)
...Using<T>(IComparer<T> comparer)
...Using<T>(Comparison<T> comparer)
...Using<T>(Func<T, T, bool> comparer)
...UsingPropertiesComparer() // From version 4.1
...WithValue(object expectedValue)
Examples of Use
IDictionary<int, int> idict = new IDictionary<int, int> { { 1, 4 }, { 2, 5 } };
Assert.That(idict, Contains.Key(1));
Assert.That(idict, Does.ContainKey(2));
Assert.That(idict, Does.Not.ContainKey(3));
Assert.That(mydict, Contains.Key(myOwnObject).Using(myComparer));
Assert.That(mydict, Does.ContainKey("Hello").WithValue("World"));