Ejemplo n.º 1
0
        public static PersonEx2 CreatePersonEx2(bool nullDate = false)
        {
            PersonEx2 p = CreatePersonCore <PersonEx2>();

            p.BirthDate = nullDate ? (DateTime?)null : DateTime.Now.AddYears(-21);
            return(p);
        }
        public void CompareUsesFormatStringsFromConfiguration()
        {
            //Arrange.
            PersonEx2 p1        = ModelsHelper.CreatePersonEx2();
            PersonEx2 p2        = ModelsHelper.CreatePersonEx2();
            DateTime  birthDate = DateTime.Now.AddYears(-20);

            p1.BirthDate = p2.BirthDate = birthDate;
            string fs1    = "yyyyMMdd";
            string fs2    = "ddMMyyyy";
            var    config = ComparerConfigurator.Configure <PersonEx2>(true)
                            .MapProperty(src => src.BirthDate, dst => dst.BirthDate, true, fs1, fs2);
            ObjectComparer comparer = config.CreateComparer();

            //Act.
            var result = comparer.Compare(p1, p2, out bool _);

            //Assert.
            result.Should().NotBeNull();
            PropertyComparisonResult pcr = result[nameof(PersonEx2.BirthDate)];

            pcr.Should().NotBeNull();
            (pcr.Result & ComparisonResult.StringCoercion).Should().Be(ComparisonResult.StringCoercion);
            (pcr.Result & ComparisonResult.NotEqual).Should().Be(ComparisonResult.NotEqual);
            pcr.MapUsed.Should().NotBeNull();
            pcr.MapUsed.ForceStringValue.Should().BeTrue();
            pcr.MapUsed.FormatString.Should().Be(fs1);
            pcr.MapUsed.TargetFormatString.Should().Be(fs2);
            pcr.Value1.Should().NotBeNull();
            pcr.Value1.Should().BeOfType <string>();
            pcr.Value1.Should().Be(birthDate.ToString(fs1));
            pcr.Value2.Should().NotBeNull();
            pcr.Value2.Should().BeOfType <string>();
            pcr.Value2.Should().Be(birthDate.ToString(fs2));
        }
Ejemplo n.º 3
0
        public void CompareNullablePropertiesSameType(bool date1Null, bool date2Null)
        {
            //Arrange.
            PersonEx2WithPropertyMap p1 = ModelsHelper.CreatePersonEx2WithPropertyMap(date1Null);
            PersonEx2      p2           = ModelsHelper.CreatePersonEx2(date2Null);
            ObjectComparer comparer     = ObjectComparer.Create <PersonEx2WithPropertyMap, PersonEx2>();

            //Act.
            var result = comparer.Compare(p1, p2, out bool _);

            //Assert.
            result.Should().NotBeNull();
            PropertyComparisonResult propResult = result[nameof(PersonEx2WithPropertyMap.DateOfBirth)];

            propResult.Should().NotBeNull();
        }
Ejemplo n.º 4
0
        public void CompareCoercesToStringOnPropertyTypeMismatch()
        {
            //Arrange.
            PersonEx2           p1       = ModelsHelper.CreatePersonEx2();
            PersonEx2StringDate p2       = ModelsHelper.CreatePersonEx2StringDate();
            ObjectComparer      comparer = ObjectComparer.Create <PersonEx2, PersonEx2StringDate>();

            //Act.
            var result = comparer.Compare(p1, p2, out bool _);

            //Assert.
            result.Should().NotBeNull();
            PropertyComparisonResult propResult = result[nameof(PersonEx2.BirthDate)];

            propResult.Should().NotBeNull();
            (propResult.Result & ComparisonResult.StringCoercion).Should().Be(ComparisonResult.StringCoercion);
        }
Ejemplo n.º 5
0
        public void CompareNonNullableToNullableSameBaseType(bool nullDate)
        {
            //Arrange.
            PersonEx2NonNullable p1       = ModelsHelper.CreatePersonEx2NonNullable();
            PersonEx2            p2       = ModelsHelper.CreatePersonEx2(nullDate);
            ObjectComparer       comparer = ObjectComparer.Create <PersonEx2NonNullable, PersonEx2>();

            //Act.
            var result = comparer.Compare(p1, p2, out bool _);

            //Assert.
            result.Should().NotBeNull();
            PropertyComparisonResult propResult = result[nameof(PersonEx2.BirthDate)];

            propResult.Should().NotBeNull();
            (propResult.Result & ComparisonResult.StringCoercion).Should().Be(ComparisonResult.Undefined, "Comparison without coercion is possible.");
        }
Ejemplo n.º 6
0
        public void CompareCoercesToStringOnAttributedDemand(bool date1Null, bool date2Null)
        {
            //Arrange.
            PersonExWithStringCoerce p1 = ModelsHelper.CreatePersonExWithStringCoerce(date1Null);
            PersonEx2      p2           = ModelsHelper.CreatePersonEx2(date2Null);
            ObjectComparer comparer     = ObjectComparer.Create <PersonExWithStringCoerce, PersonEx2>();

            //Act.
            var result = comparer.Compare(p1, p2, out bool _);

            //Assert.
            result.Should().NotBeNull();
            PropertyComparisonResult propResult = result[nameof(PersonExWithStringCoerce.DateOfBirth)];

            propResult.Should().NotBeNull();
            (propResult.Result & ComparisonResult.StringCoercion).Should().Be(ComparisonResult.StringCoercion);
        }