1

Closed

Should be single

description

hey guys, I've run into this a couple times and implemented work-around, but I finally got around to creating proper extension methods for fluent assertions, it would be nice if it ended up as a native feature of Fluent Assertions.

I'm hoping that you can re purpose the testing suite on Should().Contain() to point at the throwing Should().ContainSingle(TItem) implementation.

cheers.

file attachments

Closed Aug 25, 2012 at 2:19 PM by
All done with the public beta of Fluent Assertions 2.0

comments

Groostav wrote Jul 18, 2012 at 10:45 PM

bump?

wrote Jul 21, 2012 at 6:47 PM

Associated with changeset 80488: Implemented ContainSingle on CollectionAssertions

wrote Jul 22, 2012 at 8:26 PM

Associated with changeset 80496: Moved ContainSingle from CollectionAssertions to GenericCollectionAssertions

mopdam wrote Jul 23, 2012 at 7:33 PM

I have implemented the GenericCollectionAssertions.ContainSingle method that takes a predicate argument.
That is working now. However I did not understand the overload that you have in the attached .cs file. What is the use of passing in a specific TElement instance to the ContainSingle assertion? You could then simply use the Contain assertion. Or am I missing something?

wrote Jul 24, 2012 at 6:51 PM

Associated with changeset 80552: Added overload for ContainInOrder that takes a params object[] as argument

Groostav wrote Aug 1, 2012 at 8:56 PM

The reason for the ContainSingle() is to assert that transforms on sets yield unique results, so the purpose of the TElement is for consistency, you can call ContainSingle() with a criteria or with an element just as you can call Contain() with a criteria or with an element.

I want to assert that a set is a set of one, probably because I did a transform on some collection and the result should be a unique element. Its annoying to have to call Single() on everything and the resulting error would be a little odd (the debugger would highlight the row and if it was done fluently, ie someset.Single().Should()... you would think its the condition that's failing when infact its the Single().

And thanks for including the first one!