Skip to content

Instantly share code, notes, and snippets.

@juanplopes
Created December 28, 2010 20:37
Show Gist options
  • Save juanplopes/757680 to your computer and use it in GitHub Desktop.
Save juanplopes/757680 to your computer and use it in GitHub Desktop.
[Test]
public void ShouldServeAsNonGenericIEqualityComparer()
{
Sample1 obj1 = new Sample1();
EqualityHelper<Sample1> helper = new EqualityHelper<Sample1>();
helper.Add(x => x.IntProp);
helper.Add(x => x.StringProp);
var hash = new Hashtable(helper);
hash.Add(new Sample1() { IntProp = 2, StringProp = "asd" }, "doesn't matter");
hash.ContainsKey(new Sample1() { IntProp = 2, StringProp = "asd" }).Should().Be.True();
hash.ContainsKey(new Sample1() { IntProp = 3, StringProp = "asd" }).Should().Be.False();
}
[Test]
public void ShouldServeAsGenericIEqualityComparer()
{
Sample1 obj1 = new Sample1();
EqualityHelper<Sample1> helper = new EqualityHelper<Sample1>();
helper.Add(x => x.IntProp);
helper.Add(x => x.StringProp);
var hash = new Dictionary<Sample1, string>(helper);
hash.Add(new Sample1() { IntProp = 2, StringProp = "asd" }, "doesn't matter");
hash.ContainsKey(new Sample1() { IntProp = 2, StringProp = "asd" }).Should().Be.True();
hash.ContainsKey(new Sample1() { IntProp = 3, StringProp = "asd" }).Should().Be.False();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment