shouldly / shouldly

Should testing for .NET—the way assertions should be!

Home Page:https://docs.shouldly.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve ShouldContainKey (error message and return value for chaining)

protron opened this issue · comments

dictionary.ShouldContainKey(key) currently returns a worse error message when compared to dictionary.Keys.ShouldContain(key). Because the later actually shows the keys actually found in the dictionary.

  Shouldly.ShouldAssertException : dictionary.Keys
    should contain
zzz
    but was actually
[aaa, bbb, ccc]

And some asserts like ShouldBeAssignableTo are returning some useful values so you can chain that result with more asserts (in that case the object already converted to that type). In the case of ShouldContainKey I think it would make perfect sense to return the value found at that key.

So instead of:

dictionary.ShouldContainKey(key);
var value = dictionary[key];

we can have:

var value = dictionary.ShouldContainKey(key);