Ejemplo n.º 1
0
		//NOTE: compare object's values (not refs)
		public override bool Equals(object obj) {
			if (obj == null || obj.GetType() != GetType()) {
				return false;
			}

			return ObjectComparer.AreEqual(this, obj);
		}
Ejemplo n.º 2
0
        private void ValidateExpectedEvents(IEnumerable <IEvent> expected, IEnumerable <IEvent> actual)
        {
            var expectedSegment = new List <IEvent>();
            var actualSegment   = new List <IEvent>();
            int i = 0;

            foreach (var e in expected)
            {
                if (e is VerifyEventsNow)
                {
                    ObjectComparer.AreEqual(expectedSegment, actualSegment, false);
                    expectedSegment = new List <IEvent>();
                    actualSegment   = new List <IEvent>();
                }
                else
                {
                    expectedSegment.Add(e);

                    if (i < actual.Count())
                    {
                        actualSegment.Add(actual.ElementAt(i++));
                    }
                }
            }

            for (int x = i; x < actual.Count(); x++)
            {
                actualSegment.Add(actual.ElementAt(x));
            }

            ObjectComparer.AreEqual(expectedSegment, actualSegment, false);
        }
        public void TestBasicCompareFalse()
        {
            AnEntity entity1 = AnEntity.Create(10, "test", 100);
            AnEntity entity2 = AnEntity.Create(10, "test", 110);

            Assert.That(ObjectComparer.AreEqual(entity1, entity2), Is.False);
        }
        public void VerifyDoubleNull()
        {
            AnEntity entity1 = AnEntity.Create(10, null, 100);
            AnEntity entity2 = AnEntity.Create(10, null, 100);

            Assert.That(ObjectComparer.AreEqual(entity1, entity2));
        }
Ejemplo n.º 5
0
        public void EqualObjectsWithArrayProperties_ReturnsTrue()
        {
            var leftObject = new AdvArrayJson {
                Id = 1, Properties = new[] { BasicJson.GetDefault() }
            };
            var rightObject = new AdvArrayJson {
                Id = 1, Properties = new[] { BasicJson.GetDefault() }
            };

            Assert.IsTrue(ObjectComparer.AreEqual(leftObject, rightObject));
        }
Ejemplo n.º 6
0
        private void TestEqual <T>() where T : class
        {
            var factory = FindFactory <T>();

            var a = factory.New();
            var b = factory.New();

            var areEqual = ObjectComparer.AreEqual(a, b);

            Assert.True(areEqual);
        }
Ejemplo n.º 7
0
        public void CompareEqualObjectsWithArrayProperty()
        {
            var first = new AdvArrayJson {
                Id = 1, Properties = new[] { BasicJson.GetDefault() }
            };
            var second = new AdvArrayJson {
                Id = 1, Properties = new[] { BasicJson.GetDefault() }
            };

            Assert.IsTrue(ObjectComparer.AreEqual(first, second));
        }
Ejemplo n.º 8
0
        private void TestNotEqual <T>() where T : class, new()
        {
            var factory = FindFactory <T>();

            var a = factory.New();
            var b = new T();

            var areEqual = ObjectComparer.AreEqual(a, b);

            Assert.False(areEqual);
        }
        public void GetSingleMapper_Map_Success()
        {
            var singleMapper = CreateSingleMapper();

            var src  = new Src();
            var dest = new Dest();

            singleMapper.Map(src, dest);

            var result = ObjectComparer.AreEqual(src, dest);

            Assert.IsTrue(result.Success);
        }
Ejemplo n.º 10
0
        public void DictionaryCompareFalseComparisonDifferentElement2()
        {
            AnEntityWithDictionary e1 = new AnEntityWithDictionary()
            {
                Id = 1, Dictionary = { { "a", 1 } }
            };
            AnEntityWithDictionary e2 = new AnEntityWithDictionary()
            {
                Id = 1, Dictionary = { { "a", 1 }, { "b", 2 } }
            };

            Assert.That(ObjectComparer.AreEqual(e1, e2), Is.False);
        }
Ejemplo n.º 11
0
        public void DictionaryCompare()
        {
            AnEntityWithDictionary e1 = new AnEntityWithDictionary()
            {
                Id = 1, Dictionary = { { "a", 1 }, { "b", 2 } }
            };
            AnEntityWithDictionary e2 = new AnEntityWithDictionary()
            {
                Id = 1, Dictionary = { { "a", 1 }, { "b", 2 } }
            };

            Assert.That(ObjectComparer.AreEqual(e1, e2));
        }
Ejemplo n.º 12
0
        public void CollectionCompareDifferentNumberOfElement2()
        {
            AnEntityWithCollection e1 = new AnEntityWithCollection()
            {
                Id = 1, Collection = { "a", "b", "c" }
            };
            AnEntityWithCollection e2 = new AnEntityWithCollection()
            {
                Id = 1, Collection = { "a", "b" }
            };

            Assert.That(ObjectComparer.AreEqual(e1, e2), Is.False);
        }
Ejemplo n.º 13
0
        public void CollectionCompareFalseComparison()
        {
            AnEntityWithCollection e1 = new AnEntityWithCollection()
            {
                Id = 1, Collection = { "a", "b" }
            };
            AnEntityWithCollection e2 = new AnEntityWithCollection()
            {
                Id = 1, Collection = { "a", "c" }
            };

            Assert.That(ObjectComparer.AreEqual(e1, e2), Is.False);
        }
Ejemplo n.º 14
0
        public void ObjectReferenceEquals()
        {
            var nested = new ValueClassFactory().New();
            var a      = new HasNestedClass {
                NestedClassProperty = nested
            };
            var b = new HasNestedClass {
                NestedClassProperty = nested
            };

            var areEqual = ObjectComparer.AreEqual(a, b);

            Assert.True(areEqual);
        }
Ejemplo n.º 15
0
        public void StructsEquals_ReturnsTrue()
        {
            var leftStruct = new SampleStruct
            {
                Name  = nameof(SampleStruct),
                Value = 1,
            };

            var rightStruct = new SampleStruct
            {
                Name  = nameof(SampleStruct),
                Value = 1,
            };

            Assert.IsTrue(ObjectComparer.AreEqual(leftStruct, rightStruct));
        }
Ejemplo n.º 16
0
        public void Mapper_MapSimpleReferenceTypes_Success()
        {
            var config = new HappyConfig(cfg =>
            {
                cfg.CreateMap <Src, Dest>();
            });
            var mapper = config.CompileMapper();

            var src  = new Src();
            var dest = new Dest();

            mapper.Map(src, dest);

            var result = ObjectComparer.AreEqual(src, dest);

            Assert.IsTrue(result.Success);
        }
Ejemplo n.º 17
0
        public void ComparableIntEnumerableClassDifferentOrder()
        {
            var values = new List <ComparableIntClass>
            {
                new ComparableIntClass {
                    IntProperty = 1
                },
                new ComparableIntClass {
                    IntProperty = 2
                },
                new ComparableIntClass {
                    IntProperty = 3
                },
                new ComparableIntClass {
                    IntProperty = 4
                },
            };

            var reversedValues = new List <ComparableIntClass>
            {
                new ComparableIntClass {
                    IntProperty = 4
                },
                new ComparableIntClass {
                    IntProperty = 3
                },
                new ComparableIntClass {
                    IntProperty = 2
                },
                new ComparableIntClass {
                    IntProperty = 1
                },
            };

            var a = new ComparableIntEnumerableClass {
                EnumerableProperty = values
            };
            var b = new ComparableIntEnumerableClass {
                EnumerableProperty = reversedValues
            };

            var areEqual = ObjectComparer.AreEqual(a, b);

            Assert.True(areEqual);
        }
        public void RunTest <T>(Func <IQueryService, T> query) where T : class
        {
            var queryService = SetupQueryService();

            Exception caughtException = null;

            T result = default(T);

            try
            {
                result = query(queryService);
            }
            catch (Exception e)
            {
                if (ExpectedException() == null)
                {
                    throw;
                }

                caughtException = e;
            }

            if (caughtException != null || ExpectedException() != null)
            {
                if (caughtException != null && ExpectedException() != null)
                {
                    Assert.AreEqual(ExpectedException().GetType(), caughtException.GetType());
                }
                else
                {
                    Assert.Fail("There was an Expected Exception but none was thrown.");
                }
            }
            else
            {
                if (typeof(IEnumerable).IsAssignableFrom(typeof(T)))
                {
                    ObjectComparer.AreEqual(ExpectedDtos(), (IEnumerable <object>)result, false);
                }
                else
                {
                    ObjectComparer.AreEqual(ExpectedDto(), result);
                }
            }
        }
Ejemplo n.º 19
0
        public void Mapper_MapNestedReferenceTypes_Success()
        {
            var config = new HappyConfig(cfg =>
            {
                cfg.CreateMap <NestedSrc, NestedDest>();
            });
            var mapper = config.CompileMapper();

            var src  = new NestedSrc();
            var dest = new NestedDest();

            mapper.Map(src, dest);

            var result = ObjectComparer.AreEqual(src, dest);

            result.Errors.ForEach(Console.WriteLine);
            Assert.IsTrue(result.Success);
        }
        public void Mapper_MapSimpleTypes_Success()
        {
            var config = new HappyConfig(cfg =>
            {
                cfg.CreateMap <Src, Dest>();
            });
            var mapper = config.CompileMapper();

            var src = new Src {
                Id = 1
            };

            var dest = mapper.Map <Dest>(src);

            var result = ObjectComparer.AreEqual(src, dest);

            result.Errors.ForEach(Console.WriteLine);
            Assert.IsTrue(result.Success);
        }
Ejemplo n.º 21
0
        public void ValueSequenceDifferentOrder()
        {
            var values = new List <int> {
                1, 2, 3, 4
            };
            var reversedValues = new List <int> {
                4, 3, 2, 1
            };

            var a = new ValueEnumerableClass {
                EnumerableProperty = values
            };
            var b = new ValueEnumerableClass {
                EnumerableProperty = values
            };

            var areEqual = ObjectComparer.AreEqual(a, b);

            Assert.True(areEqual);
        }
Ejemplo n.º 22
0
        public void CollectionComplexCompare()
        {
            AnEntityWithComplexCollection e1 = new AnEntityWithComplexCollection()
            {
                Id = 1, Collection = { new AnEntity()
                                       {
                                           Name = "Test"
                                       } }
            };
            AnEntityWithComplexCollection e2 = new AnEntityWithComplexCollection()
            {
                Id = 1, Collection = { new AnEntity()
                                       {
                                           Name = "Test"
                                       } }
            };
            ObjectComparer comparer = new ObjectComparer();
            var            res      = comparer.FindDifferencies(e1, e2);

            Assert.That(ObjectComparer.AreEqual(e1, e2));
        }
Ejemplo n.º 23
0
        public void Assert()
        {
            /*
             * Plan is to invoke the command on the handler and retrieve the actual
             * events from the repository and eventbus, and compare both with the
             * expected events list passed-in using Regalo.Object compare.
             */

            InvokeHandler();

            var eventsStoredToEventStore = _context.GetGeneratedEvents();

            var comparer = new ObjectComparer().Ignore <Event, Guid?>(x => x.ParentVersion)
                           .Ignore <Event, Guid>(x => x.Version)
                           .Ignore <Event, Guid>(x => x.Id);

            ObjectComparisonResult result = comparer.AreEqual(_expected, eventsStoredToEventStore);

            if (!result.AreEqual)
            {
                throw new AssertionException(string.Format("Actual events did not match expected events. {0}", result.InequalityReason));
            }
        }
Ejemplo n.º 24
0
 public void NullType_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ObjectComparer.AreEqual(default(SampleStruct), default(SampleStruct), null));
 }
Ejemplo n.º 25
0
 public static bool IsNotEqualTo <T>(this T left, T right) where T : class
 {
     return(!ObjectComparer.AreEqual(left, right));
 }
        public void Map_ListOfLists_Success()
        {
            var config = new HappyConfig(cfg =>
            {
                cfg.CreateMap <Src, Dest>();
                cfg.CreateMap <SrcWrapLevel2, DestWrapLevel2>();
            });

            config.AssertConfigurationIsValid();
            var mapper = config.CompileMapper();

            var srcListA = new List <Src>();

            srcListA.Add(new Src {
                Value1 = Gen.Int()
            });
            srcListA.Add(new Src {
                Value1 = Gen.Int()
            });
            srcListA.Add(new Src {
                Value1 = Gen.Int()
            });

            var srcListB = new List <Src>();

            srcListB.Add(new Src {
                Value1 = Gen.Int()
            });
            srcListB.Add(new Src {
                Value1 = Gen.Int()
            });

            var srcListL2 = new List <List <Src> >();

            srcListL2.Add(srcListA);
            srcListL2.Add(srcListB);


            var destList   = new List <Dest>();
            var destListL2 = new List <List <Dest> >();

            destList.Add(new Dest());
            destListL2.Add(destList);

            var srcWrap = new SrcWrapLevel2 {
                P1 = srcListL2
            };
            var destWrap = new DestWrapLevel2 {
                P1 = destListL2
            };

            mapper.Map(srcWrap, destWrap);
            //Mapper_SrcWrapLevel2_DestWrapLevel2_8bae.Map(srcWrap, destWrap);

            for (int i = 0; i < srcWrap.P1.Count; i++)
            {
                for (int j = 0; j < srcWrap.P1[i].Count; j++)
                {
                    var src  = srcWrap.P1[i][j];
                    var dest = destWrap.P1[i][j];

                    var result = ObjectComparer.AreEqual(src, dest);

                    Assert.IsTrue(result.Success);
                }
            }
        }