Skip to content

Instantly share code, notes, and snippets.

@joshilewis
Last active November 18, 2019 09:01
Show Gist options
  • Save joshilewis/e243ea124d317fdd57eaa0a2429ac497 to your computer and use it in GitHub Desktop.
Save joshilewis/e243ea124d317fdd57eaa0a2429ac497 to your computer and use it in GitHub Desktop.
using System;
using NUnit.Framework;
namespace Tests
{
[TestFixture]
public class Test
{
public class Temp
{
public string Prop1;
public string Prop2;
public int Prop3;
}
private readonly Func<Temp, Temp, bool> comparer = (x, y) =>
{
Assert.That(x.Prop1, Is.EqualTo(y.Prop1));
Assert.That(x.Prop2, Is.EqualTo(y.Prop2));
Assert.That(x.Prop3, Is.EqualTo(y.Prop3));
return true;
};
[Test]
public void Test1()
{
var temp1 = new Temp{Prop1 = "prop11", Prop2 = "prop12", Prop3 = 13};
var temp2 = new Temp { Prop1 = "prop21", Prop2 = "prop22", Prop3 = 23 };
var temp3 = new Temp { Prop1 = "prop31", Prop2 = "prop32", Prop3 = 33 };
//This passes
Assert.That(new[] {temp1, temp2, temp3},
Is.EquivalentTo(new[] {temp1, temp2, temp3})
.Using(comparer));
//This fails
Assert.That(new[] {temp1, temp2, temp3},
Is.EquivalentTo(new[] {temp2, temp1, temp3})
.Using(comparer));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment