Assert.Contains uses ComparisonSemantics.Equals to determine whether any
element of the enumeration equals the specified instance.
 
ComparisonSemantics.Equals has some special logic for comparing collection
types by contents.  However, it enforces a constraint that the objects that
are compared are simple collection types that don't override Equals
themselves.  It also ensures that the objects to be compared are of the same
type.
 
So ComparisonSemantics.Equals(new[] { 1, 2 }, new List<int>() { 1, 2 })
returns false because the objects are of different types.
 
You may wish to use something like the following instead:
 
Assert.Contains(en, new[] { 'a', 'x' },
GenericCollectionUtils.ElementsEqual).
 
Jeff.

  _____  

From: [email protected] [mailto:[email protected]] On
Behalf Of Josh Buedel
Sent: Sunday, December 13, 2009 4:11 PM
To: [email protected]
Subject: MbUnit Understanding Assert.Contains


My unit test calls Assert.Contains like so:



Assert.Contains(en, new[] { 'a', 'x' });



en is an IEnumerable<IEnumerable<char>>.


And the output is:



Expected the value to appear within the enumeration.

Expected Value : ['a', 'x']
Enumeration    : [['d'], ['x'], ['d', 'x'], ['e'], ['x'], ['e', 'x'], ['a'],
['x'], ['a', 'x'], ['a', 'd'], ['x'], ['a', 'd', 'x'], ['a', 'e'], ['x'],
['a', 'e', 'x'], ['b'], ['x'], ['b', 'x'], ['b', 'd'], ['x'], ['b', 'd',
'x'], ['b', 'e'], ['x'], ['b', 'e', 'x'], ['c'], ['x'], ['c', 'x'], ['c',
'd'], ['x'], ['c', 'd', 'x'], ['c', 'e'], ['x'], ['c', 'e', 'x']]



The test is failing, but the output seems to clearly show that the expected
value is in the enumeration.  (I've marked it red & bold).  Why is that?

Thanks,
Josh

--

You received this message because you are subscribed to the Google Groups
"MbUnit.User" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/mbunituser?hl=en.

--

You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/mbunituser?hl=en.


Reply via email to