I'm implementing a special case of an immutable dictionary, which for convenience implements IEnumerable<KeyValuePair<Foo, Bar>>
. Operations that would ordinarily modify the dictionary should instead return a new instance.
So far so good. But when I try to write a fluent-style unit test for the class, I find that neither of the two fluent assertion libraries I've tried (Should and Fluent Assertions) supports the NotBeSameAs()
operation on objects that implement IEnumerable
-- not unless you first cast them to Object
.
When I first ran into this, with Should, I assumed that it was just a hole in the framework, but when I saw that Fluent Assertions had the same hole, it made my think that (since I'm a relative newcomer to C#) I might be missing something conceptual about C# collections -- the author of Should implied as much when I filed an issue.
Obviously there are other ways to test this -- cast to Object
and use NotBeSameAs()
, just use Object.ReferenceEquals
, whatever -- but if there's a good reason not to, I'd like to know what that is.
Object
, why would you need to cast? – PharrIEnumerable
, which unlike the less-specific one forObject
, doesn't support theNotBeSameAs()
operation. – Meander