1
我使用Fluent Assertions並願意測試我的集合是否包含使用深對象圖形比較的某個對象。我不想實施所有的平等成員。但是,我無法找到對收集中的某些對象進行等價控制的測試方法。例如,此測試失敗,我希望它通過:流利的斷言:檢查集合是否包含對象,相當於提供的對象?
class Student
{
public string Name { get; set; }
}
[Test]
public void ShouldContainStudent()
{
new[] { new Student { Name = "George" }, new Student { Name = "Anna" } }.Should()
.Contain(new Student { Name = "Anna" });
}
有沒有一些優雅的方式來做到這一點?像這樣?
[Test]
public void ShouldContainStudent()
{
new[] { new Student { Name = "George" }, new Student { Name = "Anna" } }.ShouldContainEquivalent(new Student { Name = "Anna" });
}
你不能這樣做,今天,但在技術上它不應該是複雜的,使之成爲可能。大部分內部組件已經足夠組合。 –