我已经使用.NET Framework 4.X多年了,我刚刚切换到.NET Core.由于我想做TDD,我想使用模拟框架和微软假货.但是,我不清楚如何为.NET Core做到这一点,因为不支持经典解决方案.
有人能告诉我如何在.NET Core 1.1下使用Mocking和Fakes吗?
在我的一个测试中,我想确保集合中有某些项目.因此,我想将此集合与预期集合的项目进行比较,而不是关于项目的顺序.目前,我的测试代码看起来有点像这样:
[Fact]
public void SomeTest()
{
// Do something in Arrange and Act phase to obtain a collection
List<int> actual = ...
// Now the important stuff in the Assert phase
var expected = new List<int> { 42, 87, 30 };
Assert.Equal(expected.Count, actual.Count);
foreach (var item in actual)
Assert.True(expected.Contains(item));
}
Run Code Online (Sandbox Code Playgroud)
有没有更简单的方法来实现这个在xunit.net?我无法使用,Assert.Equal因为此方法检查两个集合中的项目顺序是否相同.我看了一下,Assert.Collection但是没有删除Assert.Equal(expected.Count, actual.Count)上面代码中的语句.
感谢您提前的答案.