请考虑以下代码:
public static IEnumerable<object[]> TestData
{
get
{
yield return new object[]
{
"hello",
ImmutableList<string>.Empty.AddRange(
new List<string>()
{
"one",
"two"
}
)
};
}
}
[TestMethod]
[DynamicData(nameof(TestData))]
public void Sandbox(string myString, ImmutableList<string> myList)
{
var sameListInstantiatedHere = ImmutableList<string>.Empty.AddRange(
new List<string>()
{
"one",
"two"
}
);
sameListInstantiatedHere.Count.Should().Be(2);
myString.Should().Be("hello");
myList.Count.Should().Be(2);
}
我得到这个错误:
MyList.Count应为2,但发现为0(相差-2).
我真的不明白为什么myList
只有零件物品.请注意,我甚至使用相同的代码在Sandbox
方法中实例化它,以及sameListInstantiatedHere.Count.Should().Be(2);
如何通过测试,而myList.Count.Should().Be(2);
不能.
为什么会这样呢?我做错了什么?