Forked from hatelove/PartialCompareWithAnonymousCollection.cs
Created
January 8, 2017 13:46
-
-
Save kkbruce/c5e069b647b42e7bda00cf49e37eb2dd to your computer and use it in GitHub Desktop.
使用 ExpectedObjects 含集合型別的部分比較
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void TestCollection() | |
{ | |
var expected = new | |
{ | |
//Orders = (new List<int> { 11, 12 }).Select(p => new { Id = p }) | |
Orders = new[] | |
{ | |
new { Id = 11 }, | |
new { Id = 12 } | |
} | |
}; | |
var actual = new Person | |
{ | |
Orders = new List<Order> | |
{ | |
new Order { Id = 11, Price = 900 }, | |
new Order { Id = 12, Price = 910 } | |
} | |
}; | |
expected.ToExpectedObject().ShouldMatch(actual); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var expected = new | |
{ | |
Orders = (new List<int> { 11, 12 }).Select(p => new { Id = p }) | |
}; | |
var actual = new Person | |
{ | |
Orders = new List<Order> | |
{ | |
new Order { Id = 11, Price = 900 }, | |
new Order { Id = 12, Price = 910 } | |
} | |
}; | |
//如何部分比較 Person 裡面的 Order 集合,只比較Id是否相等 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment