Ejemplo n.º 1
0
        public void CompareEqualStrings()
        {
            var text1 = new StringBuilder().Append("abcd").ToString();
            var text2 = new StringBuilder().Append("abcd").ToString();

            Assert.That(DeepEqualityComparer.AreEqual(text1, text2), Is.True);
        }
Ejemplo n.º 2
0
        public void CompareEqualArrays()
        {
            var array1 = new[] { 1, 2, 3 };
            var array2 = new[] { 1, 2, 3 };

            Assert.That(DeepEqualityComparer.AreEqual(array1, array2), Is.True);
        }
        public void CompareSomeTypeWithCollectionsInstances()
        {
            var instance1 = new SomeTypeWithCollections {
                ComplexItems =
                {
                    new ComplexType {
                        Text = "a", Value = 1
                    },
                    new ComplexType {
                        Text = "b", Value = 2
                    },
                }
            };

            var instance2 = new SomeTypeWithCollections {
                ComplexItems =
                {
                    new ComplexType {
                        Text = "a", Value = 1
                    },
                    new ComplexType {
                        Text = "c", Value = 2
                    },
                }
            };

            var sut = DeepEqualityComparer.CreateConfiguration().SetIgnoreIndexer(true).CreateEqualityComparer();

            var result = sut.Equals(instance1, instance2);

            Assert.That(result, Is.False);
        }
Ejemplo n.º 4
0
        public void CompareArraysWithDifferntValues()
        {
            var array1 = new[] { 1, 2, 3 };
            var array2 = new[] { 1, 2, 4 };

            Assert.That(DeepEqualityComparer.AreEqual(array1, array2), Is.False);
        }
        public void CompareEqualEnumerables()
        {
            var enumerable1 = this.GetIntegerEnumeration1();
            var enumerable2 = this.GetIntegerEnumeration2();

            Assert.That(DeepEqualityComparer.AreEqual(enumerable1, enumerable2), Is.True);
        }
Ejemplo n.º 6
0
        public void PostConcert_Returns_Concert()
        {
            var concertResponse = ConcertTestData.GetCreatedConcert();
            var response        = _controller.CreateConcert(true, _concert);

            Assert.IsTrue(DeepEqualityComparer.AreEqual(concertResponse, response.Concert));
        }
        public void StructTypeTests()
        {
            var dateComparer = new DeepEqualityComparer <DateTime>();

            Assert.True(dateComparer.Equals(new DateTime(1900, 1, 1), new DateTime(1900, 1, 1)));
            Assert.False(dateComparer.Equals(new DateTime(2020, 1, 1), new DateTime(1900, 1, 1)));

            var intComparer = new DeepEqualityComparer <int?>();

            Assert.True(intComparer.Equals(3, 3));
            Assert.True(intComparer.Equals(null, null));
            Assert.False(intComparer.Equals(3, 2));
            Assert.False(intComparer.Equals(3, null));

            var structComparer = new DeepEqualityComparer <TestStruct>();

            Assert.True(structComparer.Equals(new TestStruct {
            }, new TestStruct {
            }));
            Assert.True(structComparer.Equals(new TestStruct {
                X = "Test", Y = 1
            }, new TestStruct {
                X = "Test", Y = 1
            }));
            Assert.False(structComparer.Equals(new TestStruct {
                X = "False", Y = 1
            }, new TestStruct {
                X = "Test", Y = 0
            }));
        }
        public void CompareDifferentEnumerables()
        {
            var enumerable1 = this.GetIntegerEnumeration1();
            var enumerable2 = this.GetIntegerEnumeration3();

            Assert.That(DeepEqualityComparer.AreEqual(enumerable1, enumerable2), Is.False);
        }
        public void ValueTypeTests()
        {
            var intComparer = new DeepEqualityComparer <int>();

            Assert.True(intComparer.Equals(3, 3));
            Assert.False(intComparer.Equals(3, 2));
        }
        public void CyclicTypeTests()
        {
            var cyclicComparer = new DeepEqualityComparer <CyclicClass>();

            var expected = new CyclicClass()
            {
                X     = "Test",
                Child = new CyclicClass()
                {
                    X = "AnotherTest",
                },
            };

            expected.Child.Parent = expected;

            var actual = new CyclicClass()
            {
                X     = "Test",
                Child = new CyclicClass()
                {
                    X = "AnotherTest",
                },
            };

            actual.Child.Parent = actual;

            Assert.True(cyclicComparer.Equals(actual, expected));

            actual.Child.X = "AnotherTest2";

            Assert.False(cyclicComparer.Equals(actual, expected));
        }
Ejemplo n.º 11
0
        public void Test()
        {
            var comparer = DeepEqualityComparer.CreateConfiguration()
                           .SetLoggingTextWriter(Console.Out, false)
                           .CreateEqualityComparer();

            var v1 = new Foo(1)
            {
                "x"
            };
            var v2 = new Foo(1)
            {
                "x"
            };
            var v3 = new Foo(1)
            {
                "x", "y"
            };
            var v4 = new Foo(1)
            {
                "y"
            };
            var v5 = new Foo(2)
            {
                "x"
            };

            Assert.IsTrue(comparer.Equals(v1, v2));
            Assert.IsFalse(comparer.Equals(v1, v3));
            Assert.IsFalse(comparer.Equals(v1, v4));
            Assert.IsFalse(comparer.Equals(v1, v4));
            Assert.IsFalse(comparer.Equals(v1, v5)); // fails
        }
Ejemplo n.º 12
0
        public void DefaultConfiguration()
        {
            var sut = DeepEqualityComparer.CreateDefault <string>();

            var result = sut.Equals("a", "b");

            Assert.That(result, Is.False);
        }
        public void ImplicitConversionToIComparer()
        {
            var configuration = DeepEqualityComparer.CreateConfiguration();

            DeepEqualityComparer comparer = configuration;

            Assert.That(1, Is.EqualTo(2).Using(comparer));
        }
Ejemplo n.º 14
0
        public static List <Route> GetRoutesToUpdate(List <Route> existingRoutes, List <Route> routes)
        {
            var comparer = DeepEqualityComparer.CraeteDefaultWithLogOnlyNotEqualToConsole <Route>();

            return(existingRoutes.Except(routes, comparer)
                   .Union(routes.Except(existingRoutes, comparer))
                   .ToList());
        }
Ejemplo n.º 15
0
        public void TreatNullAsEmptyString()
        {
            var comparer = DeepEqualityComparer
                           .CreateConfiguration()
                           .TreatNullAsEmptyString(true)
                           .CreateEqualityComparer();

            Assert.That(comparer.Equals(null, string.Empty), Is.True);
            Assert.That(comparer.Equals(string.Empty, null), Is.True);
        }
Ejemplo n.º 16
0
        public void CompareSomeObjects()
        {
            var so1 = new SomeObject {
                Number = 12, Text = "abc"
            };
            var so2 = new SomeObject {
                Number = 12, Text = "abc"
            };

            Assert.Equal(so2, so1, DeepEqualityComparer.CreateDefault <SomeObject>());
        }
        public void CompareEqualInstancesOfTypesWithoutEquals()
        {
            var instance1 = new SomeType {
                Text = new string(new[] { 'T' }), Number = 12
            };
            var instance2 = new SomeType {
                Text = new string(new[] { 'T' }), Number = 12
            };

            Assert.That(DeepEqualityComparer.AreEqual(instance1, instance2), Is.True);
        }
        public void CompareDifferentInstancesOfTypesWithoutEquals()
        {
            var instance1 = new SomeType {
                Text = "T", Number = 12
            };
            var instance2 = new SomeType {
                Text = "X", Number = 12
            };

            Assert.That(DeepEqualityComparer.AreEqual(instance1, instance2), Is.False);
        }
Ejemplo n.º 19
0
        public void IgnoreIndexer()
        {
            var so1 = new SomeObjectWithIndexer();
            var so2 = new SomeObjectWithIndexer();

            var comparer = DeepEqualityComparer.CreateConfiguration()
                           .SetIgnoreIndexer(true)
                           .CreateEqualityComparer();

            Assert.That(so1, Is.EqualTo(so2).Using(comparer));
        }
Ejemplo n.º 20
0
        public void CompareStringWithDifferentCasingAndConfigureStringComparison()
        {
            var text1 = "abcd";
            var text2 = "ABCD";

            var comparer =
                DeepEqualityComparer.CreateConfiguration()
                .ConfigureStringComparison(StringComparison.OrdinalIgnoreCase)
                .CreateEqualityComparer();

            Assert.That(comparer.Equals(text1, text2), Is.True);
        }
Ejemplo n.º 21
0
        public void ConfigureStringComparison()
        {
            var text1 = "abcd";
            var text2 = "ABCD";

            var comparer =
                DeepEqualityComparer.CreateConfiguration()
                .ConfigureStringComparison(StringComparison.OrdinalIgnoreCase)
                .CreateEqualityComparer();

            Assert.That(text1, Is.EqualTo(text2).Using(comparer));
        }
Ejemplo n.º 22
0
        public void TreatNullAsEmptyString()
        {
            var so1 = new SomeObject {
                Number = 12, Text = string.Empty
            };
            var so2 = new SomeObject {
                Number = 12, Text = null
            };

            var comparer = DeepEqualityComparer.CreateConfiguration().TreatNullAsEmptyString(true).CreateEqualityComparer();

            Assert.That(so1, Is.EqualTo(so2).Using(comparer));
        }
        public void StringTypeTests()
        {
            var stringComparer = new DeepEqualityComparer <string>();

            Assert.True(stringComparer.Equals("Test", "Test"));
            Assert.False(stringComparer.Equals("Test", "Wrong"));

            var stringBuilder = new StringBuilder();

            stringBuilder.Append("Te");
            stringBuilder.Append("st");

            Assert.True(stringComparer.Equals("Test", stringBuilder.ToString()));
        }
        public void CompareStruct()
        {
            var struct1 = new SomeStruct {
                Short = 234, Value = 456
            };
            var struct2 = new SomeStruct {
                Short = 234, Value = 456
            };
            var struct3 = new SomeStruct {
                Short = -234, Value = 1456
            };

            Assert.That(DeepEqualityComparer.AreEqual(struct1, struct2), Is.True);
            Assert.That(DeepEqualityComparer.AreEqual(struct1, struct3), Is.False);
        }
Ejemplo n.º 25
0
        public void TreatNullAsOtherStringIsNotEqual()
        {
            var item1 = new SampleData();
            var item2 = new SampleData()
            {
                Text = "X"
            };

            var sut = DeepEqualityComparer.CreateConfiguration()
                      .TreatNullAs <string>("Y")
                      .CreateEqualityComparer();

            var result = sut.Equals(item1, item2);

            Assert.That(result, Is.False);
        }
        public void CompareNotEqualInstances()
        {
            var instance1 = new SomeType {
                Text = "T", Number = 12
            };
            var instance2 = new SomeType {
                Text = "X", Number = 12
            };

            var sut = DeepEqualityComparer
                      .CreateConfiguration()
                      .IgnorePropertyByType(typeof(string))
                      .CreateEqualityComparer();

            Assert.That(instance1, Is.EqualTo(instance2).Using(sut));
        }
Ejemplo n.º 27
0
        public void IgnorePropertiesByName()
        {
            var so1 = new SomeObject {
                Number = 12, Text = "abc"
            };
            var so2 = new SomeObject {
                Number = 12, Text = "abcd"
            };

            var comparer = DeepEqualityComparer
                           .CreateConfiguration()
                           .IgnorePropertyByName("Text")
                           .CreateEqualityComparer();

            Assert.That(so1, Is.EqualTo(so2).Using(comparer));
        }
        public void CompareWithoutTypeSpecificComparer()
        {
            var so1 = new SomeClass {
                Text  = "Shibby",
                Value = 25,
            };

            var so2 = new SomeClass {
                Text  = "Shibby",
                Value = -25,
            };

            var comparer = DeepEqualityComparer.CreateConfiguration().CreateEqualityComparer();

            Assert.That(so1, Is.Not.EqualTo(so2).Using(comparer));
        }
        public void CompareWithTypeSpecificComparer()
        {
            var so1 = new SomeClass {
                Text  = "Shibby",
                Value = 25,
            };

            var so2 = new SomeClass {
                Text  = "Shibby",
                Value = -25,
            };

            var comparer = DeepEqualityComparer.CreateConfiguration()
                           .RegisterEqualityComparerForType(typeof(int), new AbsIntegerEqualityComparer())
                           .CreateEqualityComparer();

            Assert.That(so1, Is.EqualTo(so2).Using(comparer));
        }
Ejemplo n.º 30
0
        public void LogToTextWriter()
        {
            var so1 = new SomeObject {
                Number = 12, Text = "abc"
            };
            var so2 = new SomeObject {
                Number = 12, Text = "abc"
            };

            var textWriter = new StringWriter();

            var comparer = DeepEqualityComparer
                           .CreateConfiguration()
                           .SetLoggingTextWriter(textWriter)
                           .CreateEqualityComparer();

            Assert.That(so1, Is.EqualTo(so2).Using(comparer));
        }