lambda in contains()

Mar 3, 2010 at 11:27 AM
Edited Mar 3, 2010 at 11:29 AM


first of all I want to say your framework is very sexy :) And thank you for this work.


The question is how should i change my assertion:

Assert.IsTrue(container.SomeList.Any(x => x.Name == "a"));

so it could be something like:

container.SomeList.Should().Contain().Any(x => x.Name == "a");




Mar 3, 2010 at 1:33 PM

You have various ways.

container.SomeList.Satisfy(sl=> sl.Any(x => x.Name == "a"));
container.SomeList.Any(element=> element.Satisfy(x => x.Name == "a"));
This second will give you which is the difference

Mar 5, 2010 at 1:46 AM

Ups sorry...

what you want test is : the list of x.Name should contain "a"

Right ?

container.SomeList.Select(x=> x.Name).Should().Contain("a");
Mar 5, 2010 at 9:43 AM

Last one works perfectly, with good error message (something like: ["b","c"] should contain "a" ).


Thank you.



Mar 5, 2010 at 5:21 PM

You are welcome and sorry to not see it the first time...

the trick is "find" the real value under test ;)