Esempio n. 1
0
        public void OneType_GetDifferences_ReturnsDifferences()
        {
            var firstToCompare = new FirstToCompare {
                AProperty = "Test", BProperty = 1
            };
            var secondToCompare = new FirstToCompare {
                AProperty = "Test", BProperty = 5000
            };

            var comparisons = new List <PropertyComparison <FirstToCompare> >
            {
                new PropertyComparison <FirstToCompare>(
                    nameof(firstToCompare.AProperty)),
                new PropertyComparison <FirstToCompare>(
                    nameof(firstToCompare.BProperty))
            };

            var differences = new ObjectComparer <FirstToCompare>(comparisons)
                              .GetDifferences(firstToCompare, secondToCompare);

            var propertyComparisons = differences.ToList();

            Assert.AreEqual(1, propertyComparisons.Count);
            Assert.AreEqual(propertyComparisons.First().FirstPropertyName, nameof(FirstToCompare.BProperty));
        }
Esempio n. 2
0
        public void TwoTypes_DifferentPropertyNames_DefaultEqualityComparer()
        {
            var firstToCompare = new FirstToCompare {
                AProperty = "Test"
            };
            var secondToCompare = new SecondToCompare {
                CProperty = "Test"
            };

            var comparisons = new List <PropertyComparison <FirstToCompare, SecondToCompare> >
            {
                new PropertyComparison <FirstToCompare, SecondToCompare>(
                    nameof(firstToCompare.AProperty), nameof(secondToCompare.CProperty))
            };

            var differences = new ObjectComparer <FirstToCompare, SecondToCompare>(comparisons)
                              .GetDifferences(firstToCompare, secondToCompare);

            Assert.IsFalse(differences.Any());
        }
Esempio n. 3
0
        public void TwoTypes_GetDifferences_ReturnsNoDifferences()
        {
            var firstToCompare = new FirstToCompare {
                AProperty = "Test", BProperty = 5000
            };
            var secondToCompare = new SecondToCompare {
                AProperty = "Test", BProperty = 5000
            };

            var comparisons = new List <PropertyComparison <FirstToCompare, SecondToCompare> >
            {
                new PropertyComparison <FirstToCompare, SecondToCompare>(
                    nameof(firstToCompare.AProperty)),
                new PropertyComparison <FirstToCompare, SecondToCompare>(
                    nameof(firstToCompare.BProperty))
            };

            var differences = new ObjectComparer <FirstToCompare, SecondToCompare>(comparisons)
                              .GetDifferences(firstToCompare, secondToCompare);

            Assert.IsFalse(differences.Any());
        }
Esempio n. 4
0
        public void OneType_NewIncludingOnlyDifferences_ReturnsNewOfSpecifiedType()
        {
            var firstToCompare = new FirstToCompare {
                AProperty = "Test", BProperty = 1
            };
            var secondToCompare = new FirstToCompare {
                AProperty = "Test", BProperty = 5000
            };

            var comparisons = new List <PropertyComparison <FirstToCompare> >
            {
                new PropertyComparison <FirstToCompare>(
                    nameof(firstToCompare.AProperty)),
                new PropertyComparison <FirstToCompare>(
                    nameof(firstToCompare.BProperty))
            };

            var newInstance = new ObjectComparer <FirstToCompare>(comparisons)
                              .NewIncludingOnlyDifferences <FirstToCompare>(firstToCompare, secondToCompare);

            Assert.IsInstanceOfType(newInstance, typeof(FirstToCompare));
            Assert.IsNull(newInstance.AProperty);
            Assert.AreEqual(newInstance.BProperty, 5000);
        }