C# - Asserting two objects are equal in unit tests - c#

Either using Nunit or Microsoft.VisualStudio.TestTools.UnitTesting. Right now my assertion fails.
[TestMethod]
public void GivenEmptyBoardExpectEmptyBoard()
{
var test = new Board();
var input = new Board()
{
Rows = new List<Row>()
{
new Row(){Cells = new List<int>(){0,0,0,0}},
new Row(){Cells = new List<int>(){0,0,0,0}},
new Row(){Cells = new List<int>(){0,0,0,0}},
new Row(){Cells = new List<int>(){0,0,0,0}},
}
};
var expected = new Board()
{
Rows = new List<Row>()
{
new Row(){Cells = new List<int>(){0,0,0,0}},
new Row(){Cells = new List<int>(){0,0,0,0}},
new Row(){Cells = new List<int>(){0,0,0,0}},
new Row(){Cells = new List<int>(){0,0,0,0}},
}
};
var lifeOrchestration = new LifeOrchestration();
var actual = lifeOrchestration.Evolve(input);
Assert.AreEqual(expected, actual);
}

You've got two different Board instances, so your call to Assert.AreEqual will fail. Even if their entire contents appear to be the same, you're comparing references, not the underlying values.
You have to specify what makes two Board instances equal.
You can do it in your test:
Assert.AreEqual(expected.Rows.Count, actual.Rows.Count);
Assert.AreEqual(expected.Rows[0].Cells[0], actual.Rows[0].Cells[0]);
// Lots more tests of equality...
Or you can do it in your classes: (note I wrote this on-the-fly - you'll want to adjust this)
public class Board
{
public List<Row> Rows = new List<Row>();
public override bool Equals(object obj)
{
var board = obj as Board;
if (board == null)
return false;
if (board.Rows.Count != Rows.Count)
return false;
return !board.Rows.Where((t, i) => !t.Equals(Rows[i])).Any();
}
public override int GetHashCode()
{
// determine what's appropriate to return here - a unique board id may be appropriate if available
}
}
public class Row
{
public List<int> Cells = new List<int>();
public override bool Equals(object obj)
{
var row = obj as Row;
if (row == null)
return false;
if (row.Cells.Count != Cells.Count)
return false;
if (row.Cells.Except(Cells).Any())
return false;
return true;
}
public override int GetHashCode()
{
// determine what's appropriate to return here - a unique row id may be appropriate if available
}
}

I used to override getHasCode and equals, but I never liked it since I don't want to change my production code for the sake of unit testing.
Also it's kind of pain.
Then I turned too reflection to compare objects which was less invasive...but that's kind of lot of work (lots of corner cases)
In the end I use:
http://www.nuget.org/packages/DeepEqual/
Works great.
Update, 6 years later:
I now use the more general library fluentassertions for .NET
it does the same as above but with more features and a nice DSL, the specific replacement would be: https://fluentassertions.com/objectgraphs/
PM> Install-Package FluentAssertions
Also after some years of experience, I still not recommend the override route, I'd even consider it a bad practice. If you're not careful you could introduce performance issues when using some Collections like Dictionaries. Also when the time would come where you will have a real business case to overload these methods you'd be in trouble because you'd have this test code in there already. Production code and test code should be kept separated, test code should not rely on implementation details or hacks to achieve their goal, this make them hard to maintain and understand.

For trivial objects, like domain objects or DTOs or entities, you could simply serialize both instances to a string and compare that string:
var object1Json = JsonConvert.SerializeObject(object1);
var object2Json = JsonConvert.SerializeObject(object2);
Assert.AreEqual(object1Json, object2Json);
This of course has various caveats, so evaluate whether for your classes, the JSON contains the expected values that should be compared.
For example, if your class contains unmanaged resources or otherwise not serializable properties, those won't be properly compared. It also only serializes public properties by default.

ExpectedObjects would help you to compare equality by property value. It supports:
simple object: expected.ToExpectedObject().ShouldEqual(actual);
collection: expected.ToExpectedObject().ShouldEqual(actual);
composized object: expected.ToExpectedObject().ShouldEqual(actual);
partial compare: expected object need design with anonymous type, and use expected.ToExpectedObject().ShouldMatch(actual)
I love ExpectedObjects because of I only need to invoke 2 API for assertion of comparing object equality:
ShouldEqual()
ShouldMatch() for partial comparing

I wanted a solution that didn't require adding a dependency, worked with VS unit tests, compared the field values of two objects,and told me all unequal fields. This is what I came up with. Note it could be extended to work with property values as well.
In my case, this works well for comparing the results of some file-parsing logic to ensure two technically "different" entries have fields with the same values.
public class AssertHelper
{
public static void HasEqualFieldValues<T>(T expected, T actual)
{
var failures = new List<string>();
var fields = typeof(T).GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
foreach(var field in fields)
{
var v1 = field.GetValue(expected);
var v2 = field.GetValue(actual);
if (v1 == null && v2 == null) continue;
if(!v1.Equals(v2)) failures.Add(string.Format("{0}: Expected:<{1}> Actual:<{2}>", field.Name, v1, v2));
}
if (failures.Any())
Assert.Fail("AssertHelper.HasEqualFieldValues failed. " + Environment.NewLine+ string.Join(Environment.NewLine, failures));
}
}
[TestClass]
public class AssertHelperTests
{
[TestMethod]
[ExpectedException(typeof(AssertFailedException))]
public void ShouldFailForDifferentClasses()
{
var actual = new NewPaymentEntry() { acct = "1" };
var expected = new NewPaymentEntry() { acct = "2" };
AssertHelper.HasEqualFieldValues(expected, actual);
}
}

Since neither have yet been mentioned on this question, there are a couple of other well adopted libraries out there that can help with this problem:
Fluent Assertions - see object graph comparison
actual.Should().BeEquivalentTo(expected);
Semantic Comparison
Likeness<MyModel, MyModel>(actual).ShouldEqual(expected);
I personally prefer Fluent Assertions as provides greater flexibility with member exclusions etc and it supports the comparison of nested objects out of the box.
Hope this helps!

Assert methods rely on the object's Equals and GetHashcode. You can implement that, but if this object equality is not needed outside unit tests I would instead consider comparing the individual primitive types on the object.
Looks like the objects are simple enough and overriding of equals is not really warranted.

If you want to compare only properties of a complex type object,
Iterating over object properties will gives all the properties.
You can try below code.
//Assert
foreach(PropertyInfo property in Object1.GetType().GetProperties())
{
Assert.AreEqual(property.GetValue(Object1), property.GetValue(Object2));
}

Related

Moq Setup override

I have gone through all the previous answers and none of them solve my problem.
lets say that i have the following code:
public interface ISomeInterface
{
int SomeMethod(int a, string b);
}
Now i have a common mocking class that defines some default behaviour for the above method
public class CommonMock
{
public Mock<ISomeInterface> MockInterface = new Mock<ISomeInterface>().Setup(x => x.SomeMethod(It.IsAny<int>(), It.IsAny<string>())).Returns(It.IsAny<int>());
}
I need some default behaviour because I have a whole lot of test cases which need a default behaviour.
But in some specific test scenarios, in a totally separate test class, i need to be able to return a different value as i am testing some specific test case.
Something like below:
[Test]
public void TestSomeMethodSpecific()
{
var commonMock = new CommonMock();
commonMock.MockInterface.Setup(x => x.SomeMethod(It.IsAny<int>(), It.IsAny<string>())).Returns(42);
// Do some test based on the new return value
}
How can I achieve that?
Below i am attaching a bit of the actual code:
Common Setup
public class MockStore
{
public Mock<IProcessHandler> ProcessHandler = new Mock<IProcessHandler>();
ProcessHandler.Setup(x => x.GetCurrentProcessRunId()).Returns(It.IsAny<int>());
}
Overridden Setup in a test class
var mockstore = new MockStore();
mockStore.ProcessHandler.Setup(x => x.GetCurrentProcessRunId()).Returns(25);
And there are almost 50 to 70 such mocks each of which return from simple types to complex classes.
That should work? If you create a subsequent setup on a method and it's non-conditional (no constraints on the arguments) then it removes all previous setups for the method.
You can see my answer here that explains it with the source code.
If you want multiple Setups that are conditional, to return different values based on the arguments, then see How to setup a method twice for different parameters with mock.
Without seeing your full code, perhaps you are already using conditional Setups. In which case the order is important and perhaps you are overriding an earlier Setup with a more general one.
You could have global mock objects that you modify as you go. For instance I have this:
[TestClass]
public class StoreServiceTest
{
Mock<IAccess> mockAccess;
Mock<IAccess> mockAccessNoData;
Mock<IDataReader> mockReader;
Mock<IDataReader> mockReaderNoData;
Mock<IStoreService> mockStoreService;
And then on the TestInitiailize, I Setup the default implementation as follows:
mockReader = new Mock<IDataReader>();
mockReader.Setup(m => m.IsDBNull(It.IsAny<int>())).Returns(false);
mockReader.Setup(m => m.GetString(It.IsAny<int>())).Returns("stub");
mockReader.Setup(m => m.GetBoolean(It.IsAny<int>())).Returns(true);
mockReader.Setup(m => m.GetInt32(It.IsAny<int>())).Returns(32);
mockReader.SetupSequence(m => m.Read()).Returns(true).Returns(false); // setup sequence to avoid infinite loop
mockAccess = new Mock<IAccess>();
mockAccess.Setup(m => m.ReadData(It.IsAny<string>(), It.IsAny<object[]>())).Returns(mockReader.Object);
mockReaderNoData = new Mock<IDataReader>();
mockReaderNoData.Setup(m => m.Read()).Returns(false);
mockAccessNoData = new Mock<IAccess>();
mockAccessNoData.Setup(m => m.ReadData(It.IsAny<string>(), It.IsAny<object[]>())).Returns(mockReaderNoData.Object);
mockStoreService = new Mock<IStoreService>();
And now for a default kind of test, all I do is pass the mockReader.Object which should have the default implementation since every test begins with TestInitialize, and then for a special case, say I want to return "sub" instead of "stub" for IDataReader's GetString() method, I can do something like this:
mockReader.Setup(m => m.GetString(It.IsAny<int>())).Returns((int col) => {
if (col == 2) return "sub";
else return "stub";
});
Hope that helps!

Unable to get separate references during iteration

I am attempting to iterate through the members of a list which implement a particular interface, called ImplementsGraphics and then call the method GetModels and add the return result to a list.
However, whenever I attempt to iterate through my objects, and perform the casting operation, I appear to be overwriting the same reference during my iteration. I have deduced that my problem is something to do with where, when and how I am instantiating my variables, but I can not decipher exactly what the intended behavior is.
I've tried numerous permutations of the following code:
public List<Model> GetModels()
{
var models = new List<Model>();
foreach (Actor actor in registeredActors.Where(n=>n is ImplementsGraphics))
{
var graphicActor = (ImplementsGraphics)actor;
models.AddRange(graphicActor.GetModels());
}
return models;
}
The problem line is var graphicActor = (ImplementsGraphics)actor; but I don't know how to write it such that declaring graphicsActor does not overwrite the existing instances of it stored in models.
Before my first several rounds of troubleshooting, I had
public List<Model> GetModels()
{
var models = new List<Model>();
foreach (Actor actor in registeredActors)
{
if((ImplementsGraphics)actor != null)
models.AddRange(((ImplementsGraphics)actor).GetModels());
}
return models;
}
Which I expected to work, as I had thought actor was safe across iteration, but apparently not.
Desired Behavior:
Return a list, which is all the return results of GetModels() for ever Actor in RegisteredActors which implements ImplementsGraphics
Actual Behavior:
Returns a list, which is the same return value repeated for each Actor in Registered Actor, which implements ImplementsGraphics.
EDIT:
In the class StaticActor which is a child of Actor and implements ImplementsGraphics its defined as follows:
public List<Model> GetModels()
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = this.Transform.WorldMatrix;
}
}
return new List<Model> { Model };
}
Additonally, I have tried two other approaches which also failed. A for loop, which itereated through all of RegisteredActors, and checked if they implemented ImplementsGraphics, explicitly calling them by their index within RegisteredActors
And a LINQ query, which went
var models = RegisteredActors.Where(n=>n is ImplementsGraphics).SelectMany(n=>((ImplementsGraphics)n).GetModels())
EDIT 2:
The deinfitions of my classes are largely irrelevant, if you want a reproducable example of the behaviour I'm having trouble with, here is a far simpler example.
class MyClass
{
MyOtherClass foo = new MyOtherClass();
int bar = 0;
MyOtherClass GetOtherClass()
{
foo.bar = bar;
return foo;
}
}
class MyOtherClass
{
int bar = 0;
}
List<MyClass> MyCollection = new List<MyClass> {new MyClass(bar = 1), new MyClass(bar = 2), new Myclass(bar = 3)};
List<MyOtherClass> MyOtherCollection = new List<MyOtherClass>();
foreach(MyClass member in MyCollection)
{
MyOtherCollection.Add(member.GetOtherClass());
}
If you were to execute the above code, I expect that the value of MyOtherCollection's bar properties would be: 1, 2, 3
However, the actual result is that:
During the first iteration the values are 1
During the second iteration the values are 2, 2
During the third iteration the values are 3, 3, 3
I would appear, since none of the provided code states, only implies, that you are attempting to reuse a reference to single Model instance to draw multiple objects. Then you are adding multiple references of the same instance to the List.
The solution may be as simple as removing the static modifier from all Model variables and/or container objects.
Normally, the solution would be to create a Deep Copy of the object when it is added to the List, however, it is not directly possible to do this in XNA *1. (not that you would want to)
It would be better to allow each Actor, or StaticActor, object to directly pass its own Model(s) through the GetModels() method in the interface implementation, instead of using the additional class MyOtherClass.
*1. XNA does not expose a public constructor for the Model class. It is possible to do this using reflection. In MonoGame, there is a public Constructor available.
I tend to split my derived Classes and subsequent Lists based on properties like "StaticCollidables","DrawableStaticCollidables" and "DrawableMovingCollidables"...
This technique may require more upfront coding(and therefore is not as "elegant"), but, it is more efficient in terms of memory overhead(8 bytes + (4(32 bit) or 8(64 bit) bytes depending on sizeof(Object)) per List) and CPU overhead(no casting or is).
If you are attempting to reuse the same model, but place it in different locations, use the DrawInstancedPrimitives method using the VertexBuffers contained within each Mesh of the model.
Please comment on which of the above solutions worked for you(if any). If I have missed something please let me know, so I can correct the answer.

Is Moq mocking a subinterface return value and ignoring the intermediary step a bug or a feature?

I was recently building an app and a coworker wrote a setup I swore would fail. I was wrong. In it a factory method was set up with an expected value of true and would return an integer. Because we didn't mock our configuration, the bool would always be false.
The setup was:
var homeStoreDataServiceFactory = new Mock<IHomeStoreDataServiceFactory>();
homeStoreDataServiceFactory.Setup(service => service.Create(true).GetStoreNumber())
.Returns(5);
I thought that a call to factory.Create(false) would not generate the mock object, and thus we would get 0 for the integer instead of the mocked value 5. Instead, no matter what we changed the service.Create(X) to, calls to GetStoreNumber always return 5 as if we'd used It.IsAny().
I've built up an MVCE so that you can see what I'm confused about:
using System;
using Moq;
namespace MoqBugMCV
{
public interface IItemServiceFactory
{
IItemService Create(bool shouldCreateServiceA);
}
public class Item
{
public string Name { get; set; }
public decimal Price { get; set; }
}
public interface IItemService
{
Item GetItem();
}
public class ItemManager
{
private readonly IItemService _itemService;
public ItemManager(IItemServiceFactory itemServiceFactory)
{
_itemService = itemServiceFactory.Create(true); //<==== configured true (like by app.config at runtime or something)
}
public Item GetAnItem()
{
return _itemService.GetItem();
}
}
internal class Program
{
private static void Main(string[] args)
{
var itemServiceFactory = new Mock<IItemServiceFactory>();
var chrisItem = new Item {Name = "Chris's Amazing Item", Price = 1000000};
itemServiceFactory.Setup(factory => factory.Create(true).GetItem())
.Returns(chrisItem);
var itemManager = new ItemManager(itemServiceFactory.Object);
var theItem = itemManager.GetAnItem();
Console.WriteLine("The item is {0} and costs {1}", theItem.Name, theItem.Price);
var itemServiceFactoryBroken = new Mock<IItemServiceFactory>();
itemServiceFactoryBroken.Setup(factory => factory.Create(false).GetItem()).Returns(chrisItem); //expecting this to fail, because IItemServiceFactory.Create(true) is configured
itemManager = new ItemManager(itemServiceFactoryBroken.Object);
theItem = itemManager.GetAnItem();
Console.WriteLine("The item is {0} and costs {1}", theItem.Name, theItem.Price); //would expect the item would be null or values to be blank
}
}
}
So... is this a bug or feature, or am I not understanding something about Moq?
Yes, it seems that any filters applied to intermediate dereferences on recursive Moqs are ignored as per here - even with an It.Is<> matcher, the filter is ignored. i.e. at present, recursive mocks will always generate the equivalent of It.IsAny<> on any parameters on the intermediate dereferences, as you noted.
For now, I would break up:
.Setup(service => service.Create(true).GetStoreNumber()
and split this into:
mockFactory.Setup(f => f.Create(xx))
mockService.Setup(service => service.GetStoreNumber())
Applying this separation to your MVCE example, the below setup only mocks the factory.Create(false), leaving factory.Create(true) to its default return value of null for reference types:
var itemServiceFactory = new Mock<IItemServiceFactory>();
var itemService = new Mock<IItemService>();
itemService.Setup(svc => svc.GetItem()).Returns(chrisItem);
itemServiceFactory.Setup(factory => factory.Create(false))
.Returns(itemService.Object);
var itemManager = new ItemManager(itemServiceFactory.Object);
var theItem = itemManager.GetAnItem(); // Get NRE on _itemService.GetItem as expected
And accordingly, mocking factory.Create(true) will use the setup service, and GetAnItem() will return the amazing item.
Edit
It seems there is a way to achieve a filter on the intermediate step and to compress the setups of both factory and service mocks in one go, using Linq to Mocks:
var itemServiceFactory = Mock.Of<IItemServiceFactory>(
fac => fac.Create(false) == Mock.Of<IItemService>(
svc => svc.GetItem() == chrisItem));
var itemManager = new ItemManager(itemServiceFactory);
var theItem = itemManager.GetAnItem();
After wrestling a bit with a few other things, I returned to this to investigate further.
If you change the second example to:
var itemServiceFactoryBroken = new Mock<IItemServiceFactory>(MockBehavior.Strict); //Strict behavior is important!!
itemServiceFactoryBroken.Setup(factory => factory.Create(false).GetItem()).Returns(chrisItem); //expecting this to fail, because IItemServiceFactory.Create(true) is configured
itemManager = new ItemManager(itemServiceFactoryBroken.Object);
theItem = itemManager.GetAnItem();
Console.WriteLine("The item is {0} and costs {1}", theItem.Name, theItem.Price);
It will throw an exception because the setup was not configured. I still believe this is a bug, its definitely not what you would expect to happen. The GetItem should not be returning a chrisItem, as the factory is not set up to be outputting a mocked class that returns anything given the configuration of the system under test.
However strict behavior mocks appear to be "aware" that this setup is invalid and will throw an exception. There seems to be a gulf in the pattern of behavior in these instances.

AutoFixture Likeness - compare only matching properties

I want to be able to compare the two following objects for likeness using AutoFixture.SemanticComparison:
public class Object1
{
public int a;
}
public class Object2
{
public int a;
public int b;
}
Now, when I do it this way:
var o1 = new Object1 { a = 1 };
var o2 = new Object2 { a = 1, b = 2};
o1.AsSource().OfLikeness<Object2>().ShouldEqual(o2);
I get the following exception: "The following members did not match: - b."
I found out that I can omit the 'b' member like this:
var o1 = new Object1 { a = 1 };
var o2 = new Object2 { a = 1, b = 2};
o1.AsSource().OfLikeness<Object2>().Without(object2 => object2.b).ShouldEqual(o2);
However, I find that this is quite cumbersome, because whenever I add a new member to class Object2, I have to correct my unit tests (or at least unit test helpers).
Is there a way to say "I want to compare for likeness just for the subset that exists in both objects"?
It sounds like you'd like to compare two objects based on the intersection of their properties. This is not currently supported by the Likeness class. The reasoning is this:
Right now the destination type (in the above example, that would be Object2) is the decisive template upon which matching is done. This provides quite a strong statement for an assertion: every public property or field of this class must be matched.
However, a statement about matching the intersection of properties would be a very weak statement, because that intersection might be empty. This could result in False Negatives.
Even if you are TDDing and following the Red/Green/Refactor cycle and you've seen a unit test failing with such a hypothetical Likeness intersection, subsequent refactorings might turn such an assertion into a False Negative, as you remove the last property or field the two objects have in common - and you'll never notice.
However, AutoFixture is open source and all, so you're welcome to suggest this feature or send a pull request.

Union-ing two custom classes returns duplicates

I have two custom classes, ChangeRequest and ChangeRequests, where a ChangeRequests can contain many ChangeRequest instances.
public class ChangeRequests : IXmlSerializable, ICloneable, IEnumerable<ChangeRequest>,
IEquatable<ChangeRequests> { ... }
public class ChangeRequest : ICloneable, IXmlSerializable, IEquatable<ChangeRequest>
{ ... }
I am trying to do a union of two ChangeRequests instances. However, duplicates do not seem to be removed. My MSTest unit test is as follows:
var cr1 = new ChangeRequest { CRID = "12" };
var crs1 = new ChangeRequests { cr1 };
var crs2 = new ChangeRequests
{
cr1.Clone(),
new ChangeRequest { CRID = "34" }
};
Assert.AreEqual(crs1[0], crs2[0], "First CR in both ChangeRequests should be equal");
var unionedCRs = new ChangeRequests(crs1.Union<ChangeRequest>(crs2));
ChangeRequests expected = crs2.Clone();
Assert.AreEqual(expected, unionedCRs, "Duplicates should be removed from a Union");
The test fails in the last line, and unionedCRs contains two copies of cr1. When I tried to debug and step through each line, I had a breakpoint in ChangeRequest.Equals(object) on the first line, as well as in the first line of ChangeRequest.Equals(ChangeRequest), but neither were hit. Why does the union contain duplicate ChangeRequest instances?
Edit: as requested, here is ChangeRequests.Equals(ChangeRequests):
public bool Equals(ChangeRequests other)
{
if (ReferenceEquals(this, other))
{
return true;
}
return null != other && this.SequenceEqual<ChangeRequest>(other);
}
And here's ChangeRequests.Equals(object):
public override bool Equals(object obj)
{
return Equals(obj as ChangeRequests);
}
Edit: I overrode GetHashCode on both ChangeRequest and ChangeRequests but still in my test, if I do IEnumerable<ChangeRequest> unionedCRsIEnum = crs1.Union<ChangeRequest>(crs2);, unionedCRsIEnum ends up with two copies of the ChangeRequest with CRID 12.
Edit: something has to be up with my Equals or GetHashCode implementations somewhere, since Assert.AreEqual(expected, unionedCRs.Distinct(), "Distinct should remove duplicates"); fails, and the string representations of expected and unionedCRs.Distinct() show that unionedCRs.Distinct() definitely has two copies of CR 12.
Make sure your GetHashCode implementation is consistent with your Equals - the Enumerable.Union method does appear to use both.
You should get a warning from the compiler if you've implemented one but not the other; it's still up to you to make sure that both methods agree with each other. Here's a convenient summary of the rules: Why is it important to override GetHashCode when Equals method is overridden?
I don't believe that Assert.AreEqual() examines the contents of the sequence - it compares the sequence objects themselves, which are clearly not equal.
What you want is a SequenceEqual() method, that will actually examine the contents of two sequences. This answer may help you. It's a response to a similar question, that describes how to compare to IEnumerable<> sequences.
You could easily take the responder's answer, and create an extension method to make the calls look more like assertions:
public static class AssertionExt
{
public static bool AreSequencesEqual<T>( IEnumerable<T> expected,
IEnumerable<T> sequence )
{
Assert.AreEqual(expected.Count(), sequence .Count());
IEnumerator<Token> e1 = expected.GetEnumerator();
IEnumerator<Token> e2 = sequence .GetEnumerator();
while (e1.MoveNext() && e2.MoveNext())
{
Assert.AreEqual(e1.Current, e2.Current);
}
}
}
Alternatively you could use SequenceEqual(), to compare the sequences, realizing that it won't provide any information about which elements are not equal.
As LBushkin says, Assert.AreEqual will just call Equals on the sequences.
You can use the SequenceEqual extension method though:
Assert.IsTrue(expected.SequenceEqual(unionedCRs));
That won't give much information if it fails, however.
You may want to use the test code we wrote for MoreLINQ which was sequence-focused - if the sequences aren't equal, it will specify in what way they differ. (I'm trying to get a link to the source file in question, but my network connection is rubbish.)

Categories