Example #1
0
        public void TestInheritanceOuter()
        {
            Sample1 obj1 = new Sample1();
            Sample2 obj2 = new Sample2();

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

            helper.AddAllProperties();

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

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

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

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

            obj1.StringProp = "B";
            helper.ObjectEquals(obj1, obj2).Should().Be.True();
            helper.ObjectGetHashCode(obj2).Should().Be(helper.ObjectGetHashCode(obj1));
        }
Example #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());
        }
Example #3
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));
        }