Exemple #1
0
        public void Equal_TrueToSecondOnDatesDifferingByLessThanASecondWithCustomComparer()
        {
            DateTime one = DateTime.Parse("07:27:15.01"),
                     two = DateTime.Parse("07:27:15.49");

            Assert.True(MemberComparer.Equal(one, two, new[] { new DateComparer(DateComparisonType.TruncatedToSecond) }));
        }
Exemple #2
0
        public void Equal_FalseOnDifferentObjectsWithDifferentValues()
        {
            Guid sharedGuid = Guid.NewGuid();

            Assert.False(MemberComparer.Equal(new { PropertyA = "B", Integer = 23, Guid = sharedGuid },
                                              new { PropertyA = "A", Integer = 23, Guid = sharedGuid }));
        }
Exemple #3
0
        public void Equal_FalseOnAnonymousObjectsWithNestedObjectsWithDifferentValues()
        {
            var sub1 = new { PropertyB = "b1" };
            var sub2 = new { PropertyB = "b2" };

            Assert.False(MemberComparer.Equal(sub1, sub2));
        }
Exemple #4
0
        public void Equal_TrueOnExceptionsWithinSameScopeOfSameType()
        {
            var exception  = new ArgumentNullException("foo");
            var exception2 = new ArgumentNullException("foo");

            Assert.True(MemberComparer.Equal(exception, exception2));
        }
Exemple #5
0
        public void Equal_TrueOnAnonymousObjectsWithNestedObjects()
        {
            var sub1 = new { PropertyB = "b1" };
            var sub2 = new { PropertyB = "b1" };

            Assert.True(MemberComparer.Equal(sub1, sub2));
        }
Exemple #6
0
        public void Equal_TrueOnMatchedDictionaryObjectInstances()
        {
            DictionaryObj dobj1 = new DictionaryObj {
                ObjectDictionary = new Dictionary <int, ClassWithFieldsAndProperties>
                {
                    { 1, new ClassWithFieldsAndProperties()
                      {
                          Foo = "one", Bar = "two"
                      } }, { 2, new ClassWithFieldsAndProperties()
                             {
                                 Foo = "three", Bar = "four"
                             } }
                }
            };
            DictionaryObj dobj2 = new DictionaryObj {
                ObjectDictionary = new Dictionary <int, ClassWithFieldsAndProperties>
                {
                    { 1, new ClassWithFieldsAndProperties()
                      {
                          Foo = "one", Bar = "two"
                      } }, { 2, new ClassWithFieldsAndProperties()
                             {
                                 Foo = "three", Bar = "four"
                             } }
                }
            };

            Assert.True(MemberComparer.Equal(dobj1, dobj2));
        }
Exemple #7
0
        public void Equal_FalseOnDatesDifferingByLessThanASecond()
        {
            DateTime one = DateTime.Parse("07:27:15.01"),
                     two = DateTime.Parse("07:27:15.49");

            Assert.False(MemberComparer.Equal(one, two));
        }
Exemple #8
0
        public void Equal_FalseOnObjectsWithNestedObjectsWithDifferentValues()
        {
            var sub1 = new { PropertyB = "b1" };
            var sub2 = new { PropertyB = "b2" };

            Assert.False(MemberComparer.Equal(new { PropertyA = "A", Integer = 23, Sub = sub1 },
                                              new { PropertyA = "A", Integer = 23, Sub = sub2 }));
        }
Exemple #9
0
        public void Equal_TrueOnObjectsWithNestedObjects()
        {
            var sub1 = new { PropertyB = "b1" };
            var sub2 = new { PropertyB = "b1" };

            Assert.True(MemberComparer.Equal(new { PropertyA = "A", Integer = 23, Sub = sub1 },
                                             new { PropertyA = "A", Integer = 23, Sub = sub2 }));
        }
Exemple #10
0
        public void Equal_TrueOnDifferentObjectsWithSameValues()
        {
            Guid     sharedGuid = Guid.NewGuid();
            DateTime now        = DateTime.Now;

            Assert.True(MemberComparer.Equal(new { PropertyA = "A", Integer = 23, Guid = sharedGuid, Date = now },
                                             new { PropertyA = "A", Integer = 23, Guid = sharedGuid, Date = now }));
        }
Exemple #11
0
        public void Equal_TrueOnDoubleNestedObjectsWithSameValues()
        {
            //we've nested two levels deep
            var sub2 = new { PropertyC = "b2" };
            var sub1 = new { PropertyB = "b1", Sub = sub2 };

            Assert.True(MemberComparer.Equal(new { PropertyA = "A", Integer = 23, Sub = sub1 },
                                             new { PropertyA = "A", Integer = 23, Sub = sub1 }));
        }
Exemple #12
0
 public void Equal_TrueOnInterfaces()
 {
     Assert.True(MemberComparer.Equal <IFoo>(new Foo()
     {
         Integer = 5
     }, new Foo()
     {
         Integer = 5
     }));
 }
Exemple #13
0
        public void Equal_FalseOnObjectsWithOneNullNestedObjectAndOneNonNullNestedObject()
        {
            var sub1 = new { PropertyB = "b1" };
            var sub2 = new { PropertyB = "b2" };

            sub2 = null;

            Assert.False(MemberComparer.Equal(new { PropertyA = "A", Integer = 23, Sub = sub1 },
                                              new { PropertyA = "A", Integer = 23, Sub = sub2 }));
        }
Exemple #14
0
 public void Equal_ScopesComparisonToSpecifiedType()
 {
     Assert.True(MemberComparer.Equal <A>(new B()
     {
         Integer = 4, String = "Foo"
     }, new B()
     {
         Integer = 4, String = "Bar"
     }));
 }
Exemple #15
0
        public void Equal_TrueToSecondOnNestedDatesDifferingByLessThanASecondWithCustomComparer()
        {
            DateTime one = DateTime.Parse("07:27:15.01"),
                     two = DateTime.Parse("07:27:15.49");

            var a = new { Foo = 5, Bar = new { Now = one } };
            var b = new { Foo = 5, Bar = new { Now = two } };

            Assert.True(MemberComparer.Equal(one, two, new[] { new DateComparer(DateComparisonType.TruncatedToSecond) }));
        }
Exemple #16
0
        public void Equal_FalseOnClassWithMismatchFieldValues()
        {
            string Bar = "bar";

            Assert.False(MemberComparer.Equal(new ClassWithFieldsAndProperties()
            {
                Foo = "456", Bar = Bar
            }, new ClassWithFieldsAndProperties()
            {
                Foo = "4567", Bar = Bar
            }));
        }
Exemple #17
0
        public void Equal_TrueOnClasswithPropertiesAndFields()
        {
            string Bar = "123", Foo = "456";

            Assert.True(MemberComparer.Equal(new ClassWithFieldsAndProperties()
            {
                Bar = Bar, Foo = Foo
            }, new ClassWithFieldsAndProperties()
            {
                Bar = Bar, Foo = Foo
            }));
        }
Exemple #18
0
        public void Equal_TrueOnNullAnonymousObjects()
        {
            //anonymous types that look the same like these actually share a static type (as constructed by the compiler)
            var sub1 = new { PropertyB = "b1" };

            sub1 = null;
            var sub2 = new { PropertyB = "b1" };

            sub2 = null;

            Assert.True(MemberComparer.Equal(sub1, sub2));
        }
Exemple #19
0
        public void Equal_TrueOnNestedRefToSameException()
        {
            var exception = new ArgumentNullException("foo");

            Assert.True(MemberComparer.Equal(new ExceptionHolder()
            {
                Exception = exception
            }, new ExceptionHolder()
            {
                Exception = exception
            }));
        }
Exemple #20
0
        public void Equal_TrueOnClassWithMismatchedPropertiesAndFieldsWithCustomComparer()
        {
            string Bar = "bar";

            Assert.True(MemberComparer.Equal(new ClassWithFieldsAndProperties()
            {
                Foo = "456", Bar = Bar
            }, new ClassWithFieldsAndProperties()
            {
                Foo = "4567", Bar = Bar
            },
                                             new[] { new GenericEqualityComparer <ClassWithFieldsAndProperties>((a, b) => a.Bar == b.Bar) }));
        }
Exemple #21
0
        public void Equal_TrueOnObjectsWithNullNestedObjects()
        {
            //anonymous types that look the same like these actually share a static type (as constructed by the compiler)
            var sub1 = new { PropertyB = "b1" };

            sub1 = null;
            var sub2 = new { PropertyB = "b1" };

            sub2 = null;

            Assert.True(MemberComparer.Equal(new { PropertyA = "A", Integer = 23, Sub = sub1 },
                                             new { PropertyA = "A", Integer = 23, Sub = sub2 }));
        }
Exemple #22
0
        public void Equal_FalseOnObjectsWithNestedCollections()
        {
            var nestedCollection1 = new { Property = "value", NestedProperties = new List <string>()
                                          {
                                              "a", "b"
                                          } };
            var nestedCollection2 = new { Property = "value", NestedProperties = new List <string>()
                                          {
                                              "b", "a"
                                          } };

            Assert.False(MemberComparer.Equal(nestedCollection1, nestedCollection2));
        }
Exemple #23
0
        public void Equal_IgnoresStatics()
        {
            var a = new ClassWithStatics()
            {
                Value = "Foo"
            };
            var b = new ClassWithStatics()
            {
                Value = "Foo"
            };

            Assert.True(MemberComparer.Equal(a, b));
        }
Exemple #24
0
 public void Equal_TrueOnNestedInterfaces()
 {
     Assert.True(MemberComparer.Equal <IBar>(new Bar()
     {
         Foo = new Foo()
         {
             Integer = 5
         }
     }, new Bar()
     {
         Foo = new Foo()
         {
             Integer = 5
         }
     }));
 }
Exemple #25
0
        public void Equal_TrueOnSameObject()
        {
            var anonymous = new { PropertyA = "A", Integer = 23, Guid = Guid.NewGuid() };

            Assert.True(MemberComparer.Equal(anonymous, anonymous));
        }
Exemple #26
0
 public void Equal_FalseOnMismatchedPrimitive()
 {
     Assert.False(MemberComparer.Equal(5, 15));
 }
Exemple #27
0
 public void Equal_TrueOnKeyValuePair()
 {
     Assert.True(MemberComparer.Equal(new KeyValuePair <int, string>(1, "one"),
                                      new KeyValuePair <int, string>(1, "one")));
 }
Exemple #28
0
 public void Equal_TrueOnPrimitive()
 {
     Assert.True(MemberComparer.Equal(3, 3));
 }
Exemple #29
0
 public void Equal_FalseOnMismatchedString()
 {
     Assert.False(MemberComparer.Equal("foo", "bar"));
 }
Exemple #30
0
 public void Equal_TrueOnString()
 {
     Assert.True(MemberComparer.Equal("foo", "foo"));
 }