我对字典的 CollectionAssert.AreEqual 感到困惑。我已经写了以下测试。
[Test]
public void DictionaryAssertTest()
{
const int count = 2;
IDictionary<string, string> dictionary = new Dictionary<string, string>();
for (int i = 0; i < count; i++)
dictionary.Add(i.ToString(), i.ToString());
IDictionary<string, string> reversedictionary = new Dictionary<string, string>();
for (int i = count -1; i >= 0 ; i--)
reversedictionary.Add(i.ToString(), i.ToString());
//NOTE: Expecting this to fail but does not
CollectionAssert.AreEqual(dictionary, reversedictionary);
//NOTE: When I first convert to List and then pass as parameter it fails
CollectionAssert.AreEqual(dictionary.ToList(), reversedictionary.ToList());
}
我就是为什么这不会通过单元测试
CollectionAssert.AreEqual(dictionary, reversedictionary);