0

All I want to do here is check that my lambda expression query returns the list of Customers that I expect.

So I've:

  1. Got the actual result of the query as a list of type Customer (from IEnumerable)
  2. Created an expected list of type Customer
  3. Used CollectionAssert to check each list has the same collection of members
  4. But the test fails due to:

enter image description here

I'm confused. As far as I can see I'm simply comparing 2 lists of the same generic type. What am I missing? Spent about an hour on this trying various casts etc., so any help appreciated.

Thanks

P.S. I'm just playing about with lambdas, linq and unit testing generally, but this is really bugging me!

code

user374770
  • 61
  • 1
  • 3
  • Sorry to say that but it's much easier if you post code not the image of code. Unless you want the image of an answer. – Szymon Nov 04 '13 at 03:01
  • Possible dublicate http://stackoverflow.com/questions/5194966/mstest-collectionassert-areequivalent-failed-the-expected-collection-contains – JleruOHeP Nov 04 '13 at 03:04
  • Apologies. This is my first question. I looked at the "Help" for code posting etiquette but couldn't see anything re images vs cut and paste. – user374770 Nov 04 '13 at 03:06
  • 1
    `new Customer("a") != new Customer("a")` – ta.speot.is Nov 04 '13 at 03:15

1 Answers1

0

I would suggest using FluentAssert to assert collections. You can use it pretty much for everything, but for collection it is really good.

Otherwise, you could do this kind of assertions.

Assert.AreEqual(2, actual.Count);
Assert.AreEqual("jim", actual[0].FirstName); //and more 

Or you need to have custom equality comparer for your object.

AD.Net
  • 13,352
  • 2
  • 28
  • 47