示例#1
0
        public override ITypeCompareResult <ManufacturerDto> Compare(ManufacturerDto left,
                                                                     ManufacturerDto right,
                                                                     MemberInfo memberInfo = null)
        {
            if (left == null && right == null)
            {
                return(NullParamsTypeCompareResultBuilder.Build <ManufacturerDto>(memberInfo));
            }

            var membersResults = new List <ICompareResult>();

            membersResults.Add(new MemberCompareResult <Guid?>
            {
                Left   = left?.Id,
                Right  = right?.Id,
                Member = Properties[nameof(ManufacturerDto.Id)],
                Match  = _guidComparer.Equals(left?.Id, right?.Id)
            });

            membersResults.Add(new MemberCompareResult <string>
            {
                Left   = left?.Name,
                Right  = right?.Name,
                Member = Properties[nameof(ManufacturerDto.Name)],
                Match  = _stringComparer.Equals(left?.Name, right?.Name)
            });

            var collectionResults           = _contactsTypeComparer.Compare(left?.Contacts, right?.Contacts);
            var collectionBothNullOrNotNull = _bothNullOrNotNullComparer.Equals(left?.Contacts, right?.Contacts);

            membersResults.Add(new CollectionCompareResult <ContactDto>
            {
                Left              = left?.Contacts,
                Right             = right?.Contacts,
                Member            = Properties[nameof(ManufacturerDto.Contacts)],
                CollectionResults = collectionResults,
                Match             = (!collectionResults.Any() || collectionResults.All(cr => cr.Match)) && collectionBothNullOrNotNull
            });

            var bothNullOrNotNull = _bothNullOrNotNullComparer.Equals(left, right);

            return(new TypeCompareResult <ManufacturerDto>
            {
                Match = membersResults.TrueForAll(m => m.Match) && bothNullOrNotNull,
                Left = left,
                Right = right,
                Member = memberInfo,
                MembersResults = membersResults
            });
        }
        public void Equals_Check(object testObject1, object testObject2, bool expected)
        {
            var comparer = new BothNullOrNotNullComparer();
            var result   = comparer.Equals(testObject1, testObject2);

            Assert.Equal(expected, result);
        }
示例#3
0
        public override ITypeCompareResult <CarDto> Compare(CarDto left, CarDto right, MemberInfo memberInfo = null)
        {
            if (left == null && right == null)
            {
                return(NullParamsTypeCompareResultBuilder.Build <CarDto>(memberInfo));
            }

            var membersResults = new List <ICompareResult>();

            membersResults.Add(new MemberCompareResult <Guid?>
            {
                Left   = left?.Id,
                Right  = right?.Id,
                Member = Properties[nameof(CarDto.Id)],
                Match  = _guidComparer.Equals(left?.Id, right?.Id)
            });

            membersResults.Add(new MemberCompareResult <DateTime?>
            {
                Left   = left?.ManufactureDate,
                Right  = right?.ManufactureDate,
                Member = Properties[nameof(CarDto.ManufactureDate)],
                Match  = _dateTimeComparer.Equals(left?.ManufactureDate, right?.ManufactureDate)
            });

            membersResults.Add(new MemberCompareResult <string>
            {
                Left   = left?.ModelName,
                Right  = right?.ModelName,
                Member = Properties[nameof(CarDto.ModelName)],
                Match  = _stringComparer.Equals(left?.ModelName, right?.ModelName)
            });

            membersResults.Add(new MemberCompareResult <decimal?>
            {
                Left   = left?.Price,
                Right  = right?.Price,
                Member = Properties[nameof(CarDto.Price)],
                Match  = _decimalComparer.Equals(left?.Price, right?.Price)
            });

            membersResults.Add
            (
                _manufacturerComparer
                .Compare(left?.Manufacturer,
                         right?.Manufacturer,
                         Properties[nameof(CarDto.Manufacturer)]
                         )
            );

            var collectionResults           = _codesComparer.Compare(left?.WheelCodes, right?.WheelCodes);
            var collectionBothNullOrNotNull = _bothNullOrNotNullComparer.Equals(left?.WheelCodes, right?.WheelCodes);

            membersResults.Add(new CollectionCompareResult <string>
            {
                Left              = left?.WheelCodes,
                Right             = right?.WheelCodes,
                Member            = Properties[nameof(CarDto.WheelCodes)],
                CollectionResults = collectionResults,
                Match             = (!collectionResults.Any() || collectionResults.All(cr => cr.Match)) && collectionBothNullOrNotNull
            });

            var bothNullOrNotNull = _bothNullOrNotNullComparer.Equals(left, right);

            return(new TypeCompareResult <CarDto>
            {
                Match = membersResults.TrueForAll(m => m.Match) && bothNullOrNotNull,
                Left = left,
                Right = right,
                Member = memberInfo,
                MembersResults = membersResults
            });
        }
示例#4
0
        public override ITypeCompareResult <ContactDto> Compare(ContactDto left, ContactDto right,
                                                                MemberInfo memberInfo = null)
        {
            if (left == null && right == null)
            {
                return(NullParamsTypeCompareResultBuilder.Build <ContactDto>(memberInfo));
            }

            var membersResults = new List <ICompareResult>();

            membersResults.Add(new MemberCompareResult <Guid?>
            {
                Left   = left?.Id,
                Right  = right?.Id,
                Member = Properties[nameof(ContactDto.Id)],
                Match  = _guidComparer.Equals(left?.Id, right?.Id)
            });

            membersResults.Add(new MemberCompareResult <ContactType?>
            {
                Left   = left?.Type,
                Right  = right?.Type,
                Member = Properties[nameof(ContactDto.Type)],
                Match  = _contactTypeComparer.Equals(left?.Type, right?.Type)
            });

            membersResults.Add(new MemberCompareResult <int?>
            {
                Left   = left?.Order,
                Right  = right?.Order,
                Member = Properties[nameof(ContactDto.Order)],
                Match  = _intComparer.Equals(left?.Order, right?.Order)
            });

            membersResults.Add(new MemberCompareResult <string>
            {
                Left   = left?.Value,
                Right  = right?.Value,
                Member = Properties[nameof(ContactDto.Value)],
                Match  = _stringComparer.Equals(left?.Value, right?.Value)
            });

            membersResults.Add(new MemberCompareResult <string>
            {
                Left   = left?.Description,
                Right  = right?.Description,
                Member = Properties[nameof(ContactDto.Description)],
                Match  = _stringComparer.Equals(left?.Description, right?.Description)
            });

            var bothNullOrNotNull = _bothNullOrNotNullComparer.Equals(left, right);

            return(new TypeCompareResult <ContactDto>
            {
                Match = membersResults.TrueForAll(m => m.Match) && bothNullOrNotNull,
                Left = left,
                Right = right,
                Member = memberInfo,
                MembersResults = membersResults
            });
        }