Why you don't want to do it like that
I don't think creating a Likeness from any List<T>
does what you want it to do. As I understand, you want to compare the contents of two lists. That's not the same as comparing two lists...
Consider what Likeness does: it compares property values. What are the properties of List<T>
?
They are
As Nikos Baxevanis points out in his answer, you can use the Without method to ignore the value of the Capacity property, but that means that only the Count property remains.
In other words, if you did that, this:
expectedValutaListWithLikeness.ShouldEqual(actual.ToList());
would be functionally equivalent to this:
Assert.AreEqual(expected.Count, actual.Count)
In other words, the lists could have totally different data, but the test would still pass if only each list has the same amount of elements. That's probably not what you want...
What you should do
You can use Likeness to compare each element against each other. Something like this should work:
var expectedValutaList = new List<CodeTableItem>();
expectedValutaList.Add(new CodeTableItem("DKK", "DKK"));
expectedValutaList.Add(new CodeTableItem("EUR", "EUR"));
var expectedValutaListWithLikeness = from cti in expectedValutaList
select cti
.AsSource()
.OfLikeness<CodeTableItem>();
var target = new RepoDac();
var actual = target.GetValutaKd();
Assert.IsTrue(expectedValutaListWithLikeness.Cast<object>().SequenceEqual(
actual.Cast<object>()));
You may also be able to use CollectionAssert for the assertion, but it's been so many years since I last used MSTest that I can't remember the quirks of that method...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…