Когда у меня есть Dictionary
, а затем создается полностью новый Dictionary
с теми же значениями, что и фактические.
Вызов Assert.That (фактический, Is.EqualTo (ожидаемый));
обеспечивает выполнение теста.
При использовании Assert.That (фактическое, Is.EquivalentTo (ожидалось));
тест не прошел.
В чем разница между EqualTo ()
и EquivalentTo ()
?
Редактировать:
Сообщение об исключении, когда тест не проходит, выглядит следующим образом:
Zoozle.Tests.Unit.PredictionTests.ReturnsDriversSelectedMoreThanOnceAndTheirPositions:
Expected: equivalent to < [Michael Schumacher, System.Collections.Generic.List`1[System.Int32]] >
But was: < [Michael Schumacher, System.Collections.Generic.List`1[System.Int32]] >
Мой код выглядит следующим образом:
[Test]
public void ReturnsDriversSelectedMoreThanOnceAndTheirPositions()
{
//arrange
Prediction prediction = new Prediction();
Dictionary<string, List<int>> expected = new Dictionary<string, List<int>>()
{
{ "Michael Schumacher", new List<int> { 1, 2 } }
};
//act
var actual = prediction.CheckForDriversSelectedMoreThanOnce();
//assert
//Assert.That(actual, Is.EqualTo(expected));
Assert.That(actual, Is.EquivalentTo(expected));
}
public Dictionary<string, List<int>> CheckForDriversSelectedMoreThanOnce()
{
Dictionary<string, List<int>> expected = new Dictionary<string, List<int>>();
expected.Add("Michael Schumacher", new List<int> { 1, 2 });
return expected;
}