public void ReturnsTrueForClassImplementingStructuralEqualityAndIsNotStructuralEqual()
        {
            object left = new OtherClassWithEquality {
                SomeNumber = 5
            };
            object right = new OtherClassWithEquality {
                SomeNumber = 6
            };
            var result = Testers.CheckInequality(left, right);

            Assert.True(result);
        }
        public void ReturnsTrueForDefaultClassEvenIfStructurallyEqual()
        {
            object left = new AnotherClass {
                SomeNumber = 5, SomeString = "Hi", someByte = 2, someChar = 'B'
            };
            object right = new AnotherClass {
                SomeNumber = 5, SomeString = "Hi", someByte = 2, someChar = 'B'
            };
            var result = Testers.CheckInequality(left, right);

            Assert.True(result);
        }
        public void ReturnsFalseIfNonOfTheObjectsMatchTheTypeOfThePopulatedItem()
        {
            object populatedItem = new OtherClassWithEquality {
                SomeNumber = 42
            };
            IEnumerable <object> others = new object[]
            {
                "Hello",
                5,
                'A',
            };
            var result = Testers.CheckInequality(others, populatedItem);

            Assert.True(result);
        }
示例#4
0
        private static bool TestPopulatedTypes(Type t, IDictionary <Type, Func <object> > constructors)
        {
            var ctor = constructors[t];
            var a    = ctor();
            var b    = ctor();
            var c    = ctor();

            var equalMembers = new[] { a, b, c };

            var tType = a.GetType();

            var(propertyValues, fieldValues) = Creator.GetPropertyAndFieldValues(tType, constructors);

            var memberUnequalItems = SetupEqualityChecksBasedOnProperties(propertyValues, equalMembers, ctor, fieldValues);
            var badFields          = SetupEqualityChecksBasedOnFields(fieldValues, equalMembers, ctor, propertyValues);

            memberUnequalItems.AddRange(badFields);

            var empty = ctor();

            var emptyInequality = Testers.CheckInequality(a, empty);

            var bEquality            = Testers.CheckEquality(a, b);
            var bCommutativeEquality = Testers.CheckEquality(b, a);

            var cEquality           = Testers.CheckEquality(a, c);
            var associativeEquality = Testers.CheckEquality(b, c);

            var memberInequality = Testers.CheckInequality(memberUnequalItems, a);

            var nullInequality = Testers.CheckNullInequality(a);
            var selfEquality   = Testers.CheckEquality(a, a);

            var typeInequality = Testers.CheckTypeInequality(tType, a);

            return
                (nullInequality &&
                 emptyInequality &&
                 bEquality &&
                 bCommutativeEquality &&
                 cEquality &&
                 associativeEquality &&
                 memberInequality &&
                 selfEquality &&
                 typeInequality);
        }
        public void ReturnsFalseForBasicObjectsIfOneOfThemIsThePopulatedItem()
        {
            object populatedItem = new AnotherClass {
                someChar = 'T', someByte = 32, SomeNumber = 42, SomeString = "String"
            };
            IEnumerable <object> others = new []
            {
                new AnotherClass {
                    someChar = 'T', someByte = 32, SomeNumber = 42, SomeString = "String"
                },
                populatedItem,
                new AnotherClass {
                    someChar = 'T', someByte = 32, SomeNumber = 42, SomeString = "String"
                },
            };
            var result = Testers.CheckInequality(others, populatedItem);

            Assert.False(result);
        }
        public void ReturnsFalseIfOneObjectIsThePopulatedObject()
        {
            object populatedItem = new OtherClassWithEquality {
                SomeNumber = 42
            };
            IEnumerable <object> others = new[]
            {
                new OtherClassWithEquality {
                    SomeNumber = 42
                },
                new OtherClassWithEquality {
                    SomeNumber = 40
                },
                populatedItem,
            };
            var result = Testers.CheckInequality(others, populatedItem);

            Assert.False(result);
        }
        public void ReturnsTrueForObjectsThatDifferStructurally()
        {
            IEnumerable <object> others = new[]
            {
                new OtherClassWithEquality {
                    SomeNumber = 39
                },
                new OtherClassWithEquality {
                    SomeNumber = 40
                },
                new OtherClassWithEquality {
                    SomeNumber = 41
                },
            };
            object populatedItem = new OtherClassWithEquality {
                SomeNumber = 42
            };
            var result = Testers.CheckInequality(others, populatedItem);

            Assert.True(result);
        }
        public void ReturnsTrueForBasicObjectsEvenIfStructurallyTheSame()
        {
            IEnumerable <object> others = new []
            {
                new AnotherClass {
                    someChar = 'T', someByte = 32, SomeNumber = 42, SomeString = "String"
                },
                new AnotherClass {
                    someChar = 'T', someByte = 32, SomeNumber = 42, SomeString = "String"
                },
                new AnotherClass {
                    someChar = 'T', someByte = 32, SomeNumber = 42, SomeString = "String"
                },
            };
            object populatedItem = new AnotherClass {
                someChar = 'T', someByte = 32, SomeNumber = 42, SomeString = "String"
            };
            var result = Testers.CheckInequality(others, populatedItem);

            Assert.True(result);
        }