tags:

views:

128

answers:

3

How can I do something like this in NUnit?

class Foo
{
    int Value { get; set; }
    ...
}
...
ICollection<Foo> someFoos = GetSomeFoos();
Expect(List.Map(someFoos).Property("Value"), Has.Some.EqualTo(7));

List.Map() only accepts ICollection, not ICollection<T>.

A: 

well, you could conceptually use linq to objects extensions, something like:

Expect(someAs.Count(), Has.Some.EqualTo(7));

Paul
I'm not trying to test the number of elements in someFoos, but that some elements have the property Value equal to 7.
Victor Grigoriu
Ok, that was just an example. You could just as easily use a different extension, such as the Any operator.someAs.Any(a=>a.Value == 7)
Paul
A: 

What if you tried something like this instead:

List<Foo> someFoos = GetSomeFoos();

as List<T> does implement the ICollection interface.

Andrew Hare
A: 

Well, you could convert your ICollection<T> to something that implements ICollection. Array for instance:

ICollection<Foo> someFoos = GetSomeFoos();
var array = new Foo[10];
someFoos.CopyTo(array);
Expect(List.Map(array).Property("Value"), Has.Some.EqualTo(7));
DreamSonic