我正在使用NUnit 2.5.7。我想测试某个特定类的自定义对象的集合是否包含某些基于类的属性的对象。测试集合是否包含基于特定属性的对象
例如一个人为的例子...
public class Person
{
public string Name { get; set; }
public Person(string name)
{
Name = name;
}
}
// ...
public List<Person> GetFavouritePeople()
{
List<Person> favouritePeople = new List<Person>();
favouritePeople.Add(new Person("joe"));
favouritePeople.Add(new Person("fred"));
favouritePeople.Add(new Person("jenny"));
return favouritePeople;
}
// ...
[Test]
public GetFavouritePeople()
{
List<Person> people = GetFavouritePeople();
// What I'd like to test, but not sure how to do it...
Assert.Contains(Name="joe", people);
Assert.Contains(Name="fred", people);
Assert.Contains(Name="jenny", people);
}
虽然它会在这个例子很简单,我不希望每个人创建模拟对象,并断言使用这些......我只是想检查依据在一个特定的属性(名称在这个例子中)