Dictionaries
ReadOnlyDictionaryAssertions<TDictionary, TKey, TValue> is available for IReadOnlyDictionary<TKey, TValue> and Dictionary<TKey, TValue> via .Should().
Key Presence
csharp
var dict = new Dictionary<string, int>
{
["one"] = 1,
["two"] = 2
};
dict.Should().ContainKey("one");
dict.Should().NotContainKey("three");See ContainKey and NotContainKey.
Chaining
Chainable methods return an AssertionsChain<TAssertions, T>:
csharp
dict.Should()
.ContainKey("one")
.And.ContainKey("two")
.And.NotContainKey("three");All object-level assertions are also available:
csharp
Dictionary<string, int>? maybeNull = GetDict();
maybeNull.Should().NotBeNull().And.ContainKey("key");