Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kkbruce/c5e069b647b42e7bda00cf49e37eb2dd to your computer and use it in GitHub Desktop.
Save kkbruce/c5e069b647b42e7bda00cf49e37eb2dd 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