Q: Is there a .NET Testing framework that can assert a collection contains elements based on an expression? I'm trying to test that a certain function I'm building will add objects to a collection when supplied with a collection of Ids.
My test looks something like this:
var someClass = new SomeClass();
var someIds = new List<Guid> { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };

someClass.AddIds(someIds);

Asset.That(someClass.IdsInClass, List.???);

The property IdsInClass is actually an IList and for the sake of argument lets say that it looks something like this:
public class SomeOtherClass
{
    public Guid Id { get; set; }
    public SomeClass Parent { get; set; }
    //other properties we don't care about for this test
}

I want to make sure that all the ids I made in my test are being added to someClass.IdsInClass
What is the best way to do that?
I was thinking maybe an expression would work like so:
Assert.That(someClass.IdsInClass, 
    List<SomeOtherClass>.HasAll(x => someIds.Contains(x.Id));

But I don't know if anything like that exists.

A: I would use Linq's All...
Assert.True( someIds.All( id => someClass.IdsInClass.Contains( id ) ) );


A: There is a dedicated assertion in Gallio/MbUnit for that specific test case:
Assert.ForAll(someIds, id => someClass.IdsInClass.Contains(id));

The benefit is that Gallio tells which particular elements of sequence are failing (if any). That's certainly better than just getting a generic message indicating that the expression evaluated by Assert.IsTrue is just not true.

A: You could use LINQ expressions that resolve to a boolean. For example, I write code similar to the following with NUnit tests:
List<string> items = ...
Assert.That(items.All(item => item.Contains("x")))

Does that help?
