Skip to content

Instantly share code, notes, and snippets.

@hatelove
Last active January 8, 2017 13:46
Show Gist options
  • Save hatelove/ce7a7eca12a020fa7d70706112bb5426 to your computer and use it in GitHub Desktop.
Save hatelove/ce7a7eca12a020fa7d70706112bb5426 to your computer and use it in GitHub Desktop.
使用 ExpectedObjects 含集合型別的部分比較
[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);
}
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