This project is read-only.

lambda in contains()

Mar 3, 2010 at 12:27 PM
Edited Mar 3, 2010 at 12:29 PM


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 2: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 2: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 10:43 AM

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


Thank you.



Mar 5, 2010 at 6:21 PM

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

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