Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public void TestBasicTypesEqualityInner()
        {
            Sample1 obj1 = new Sample1();
            Sample1 obj2 = new Sample1();

            EqualityHelper helper = new EqualityHelper(obj1);

            helper.Add((Sample1 x) => x.IntProp);
            helper.Add((Sample1 x) => x.StringProp);

            helper.ObjectEquals(obj2).Should().Be.True();

            obj1.IntProp = obj2.IntProp = 42;
            helper.ObjectEquals(obj2).Should().Be.True();
            helper.ObjectGetHashCode(obj2).Should().Be(helper.ObjectGetHashCode());

            obj1.StringProp = "A";
            helper.ObjectEquals(obj2).Should().Be.False();

            obj2.StringProp = "B";
            helper.ObjectEquals(obj2).Should().Be.False();

            obj1.StringProp = "B";
            helper.ObjectEquals(obj2).Should().Be.True();
            helper.ObjectGetHashCode(obj2).Should().Be(helper.ObjectGetHashCode());
        }
Exemplo n.º 3
0
        public void TestBasicTypesEqualityOuterUsingPrivateFields()
        {
            Sample5 obj1 = new Sample5();
            Sample5 obj2 = new Sample5();

            EqualityHelper helper = new EqualityHelper(typeof(Sample5));

            helper.Add("IntProp").Add("StringProp");

            helper.ObjectEquals(obj1, obj2).Should().Be.True();
        }
Exemplo n.º 4
0
        public void TestBasicTypesEqualityOuterUsingPrivateProperties()
        {
            Sample4 obj1 = new Sample4();
            Sample4 obj2 = new Sample4();

            EqualityHelper helper = new EqualityHelper <Sample4>();

            helper.Add("IntProp").Add("StringProp");

            helper.ObjectEquals(obj1, obj2).Should().Be.True();
        }
Exemplo n.º 5
0
        public void TestBasicTypesEqualityOuterWithCustomComparer()
        {
            Sample1 obj1 = new Sample1();
            Sample1 obj2 = new Sample1();

            var helper = new EqualityHelper <Sample1>();

            helper.Add(x => x.StringProp, StringComparer.InvariantCultureIgnoreCase);

            helper.ObjectEquals(obj1, obj2).Should().Be.True();

            obj1.StringProp = "A";
            helper.ObjectEquals(obj1, obj2).Should().Be.False();

            obj2.StringProp = "A";
            helper.ObjectEquals(obj1, obj2).Should().Be.True();

            obj1.StringProp = "a";
            helper.ObjectEquals(obj1, obj2).Should().Be.True();
            helper.ObjectGetHashCode(obj2).Should().Be(helper.ObjectGetHashCode(obj1));
        }