Exemple #1
0
        public void Valid_Expression_Returns_Expected_Results()
        {
            var comparer = InstanceComparer.For <TestClass>()
                           .AddExpression(t => t.StringProperty.EndsWith("a"));

            var a = new TestClass {
                StringProperty = "cba"
            };
            var b = new TestClass {
                StringProperty = "a"
            };
            var c = new TestClass {
                StringProperty = "b"
            };

            Assert.IsTrue(comparer.Equals(a, a));
            Assert.IsTrue(comparer.Equals(b, b));
            Assert.IsTrue(comparer.Equals(a, b));
            Assert.IsFalse(comparer.Equals(a, null));
            Assert.IsFalse(comparer.Equals(b, null));
            Assert.IsFalse(comparer.Equals(c, null));
            Assert.IsFalse(comparer.Equals(a, c));
            Assert.IsFalse(comparer.Equals(b, c));

            Assert.AreEqual(comparer.GetHashCode(a), comparer.GetHashCode(b));
            Assert.AreNotEqual(comparer.GetHashCode(a), comparer.GetHashCode(c));
            Assert.AreNotEqual(comparer.GetHashCode(b), comparer.GetHashCode(c));
        }
Exemple #2
0
        public void Invalid_Field_Expression_Throws_Exception()
        {
            var comparer = InstanceComparer.For <TestClass>()
                           .AddField(c => c.StringProperty, StringComparer.OrdinalIgnoreCase);

            Assert.Fail();
        }
Exemple #3
0
        public void Valid_Field_Expression_Returns_Expected_Results()
        {
            var comparer = InstanceComparer.For <TestClass>()
                           .AddField(x => x.StringField, StringComparer.OrdinalIgnoreCase);

            var a = new TestClass {
                StringField = "a"
            };
            var b = new TestClass {
                StringField = "A"
            };
            var c = new TestClass {
                StringField = "b"
            };

            Assert.IsTrue(comparer.Equals(a, a));
            Assert.IsTrue(comparer.Equals(b, b));
            Assert.IsTrue(comparer.Equals(a, b));
            Assert.IsFalse(comparer.Equals(a, null));
            Assert.IsFalse(comparer.Equals(b, null));
            Assert.IsFalse(comparer.Equals(c, null));
            Assert.IsFalse(comparer.Equals(a, c));
            Assert.IsFalse(comparer.Equals(b, c));

            Assert.AreEqual(comparer.GetHashCode(a), comparer.GetHashCode(b));
            Assert.AreNotEqual(comparer.GetHashCode(a), comparer.GetHashCode(c));
            Assert.AreNotEqual(comparer.GetHashCode(b), comparer.GetHashCode(c));
        }
Exemple #4
0
        public void Null_Field_Expression_Throws_Exception()
        {
            Expression <Func <TestClass, string> > expr = null;
            var comparer = InstanceComparer.For <TestClass>().AddField(expr, StringComparer.OrdinalIgnoreCase);

            Assert.Fail();
        }