Ejemplo n.º 1
0
        public void Copy_FromAbstractObject_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedWithAbstractConverter));

            var obj = new CopyClass0()
            {
                A = 1
            };

            var res = dto.Copy(new CopyClass1(), new[] { obj });

            res.B.Should().Be("1");
        }
Ejemplo n.º 2
0
        public void Validate_WithTrimValidation_FactorySignature_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedCopierContainer0), typeof(NestedCopierContainer1));

            var obj = new CopyClass0()
            {
                A = -1
            };

            var issues = dto.Validate(obj, x => x.RuleFor(t => t).ValidateDto()).Issues;

            issues.Should().HaveCount(1);
        }
Ejemplo n.º 3
0
        public void Convert_NestedWithConvert_WithGeneric_Test1()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedWithConvert_WithGeneric));

            var src = new NestedWithConvert_WithGeneric.CopyClass_Int()
            {
                A = 1
            };
            var dst = new NestedWithConvert_WithGeneric.CopyClass_Int1();

            dto.Copy(dst, src);
            dst.A.Should().Be(1);
        }
Ejemplo n.º 4
0
        public void Validate_WithSeveralValidators_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedCopierContainer0), typeof(NestedCopierContainer1));

            var obj = new CopyClass1()
            {
                A = -1, B = "a"
            };

            var issues = dto.Validate(obj, x => x.RuleFor(t => t).ValidateDto()).Issues;

            issues.Should().HaveCount(2);
        }
Ejemplo n.º 5
0
        public void Update_Convert_NestedWithConvert_WithGeneric_Test1()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedWithConvert_WithGeneric));

            var src = new NestedWithConvert_WithGeneric.CopyClass_Decimal()
            {
                A = 1.1m
            };
            var dst = new NestedWithConvert_WithGeneric.CopyClass_Int();

            dto.Update(dst, src);
            dst.A.Should().Be(0);
        }
Ejemplo n.º 6
0
        public void Convert_NestedWithConvert_WithPartialGeneric_Test_2()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedWithConvert_WithPartialGeneric_SrcOnly));

            var dst = new NestedWithConvert_WithPartialGeneric_SrcOnly.CopyClass_Decimal();
            var src = new NestedWithConvert_WithPartialGeneric_SrcOnly.CopyClass_Int()
            {
                A = 1
            };

            dto.Copy(dst, src);
            dst.A.Should().Be(1m);
        }
Ejemplo n.º 7
0
        public void Copy_NestedWithGenericsTypedCast_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedWithGenericsTypedCast));

            var src = new NestedWithGenericsTypedCast.CopyClass0_string()
            {
                A = "1"
            };
            var dst = new NestedWithGenericsTypedCast.CopyClass0_int();

            var res = dto.Copy(dst, src);

            res.A.Should().Be(1);
        }
Ejemplo n.º 8
0
        public void Copy_FromSameClass_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedCopier_MultiDescriptionContainer0));

            var obj = new CopyClass1()
            {
                A = 1, B = "abc"
            };

            var res = dto.Copy(new CopyClass1(), obj);

            res.A.Should().Be(1);
            res.B.Should().Be("abc");
        }
Ejemplo n.º 9
0
        public void Update_ComplexClass_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedCopierContainer0), typeof(NestedCopierContainer1));

            var dst = new CopyClass1();
            var res = dto.Update(dst, new CopyClass1()
            {
                A = 2, B = "abc"
            }, nameof(CopyClass1.A));

            res.Should().BeSameAs(dst);
            res.A.Should().Be(2);
            res.B.Should().BeNull();
        }
Ejemplo n.º 10
0
        public void Copy_NestedWithGenerics_WithIgnore_Test1()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedWithGenerics_WithIgnore1));

            var src = new NestedWithGenerics_WithIgnore1.CopyClass0()
            {
                A = 1
            };
            var dst = new NestedWithGenerics_WithIgnore1.CopyClass_MyTemplateItem();

            var res = dto.Copy(dst, src);

            res.A.Should().BeNull();
        }
Ejemplo n.º 11
0
        public void Update_NestedWithGenerics_Test1()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedWithGenerics));

            var src = new CopyClass0()
            {
                A = 1
            };
            var dst = new CopyClass_MyTemplateItem();

            var res = dto.Update(dst, src);

            res.A.Should().BeNull();
        }
Ejemplo n.º 12
0
        public void As_ForOtherAdapter_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedCopierContainer1));

            var obj = new CopyClass1()
            {
                A = 1, B = "abc"
            };

            var adapter0 = dto.As <ICopyClass0>(obj);

            adapter0.A.Should().Be(1);

            dto.As <ICopyClass1>(adapter0).B.Should().Be("abc");
        }
Ejemplo n.º 13
0
        public void Copy_ToAbstractObject_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedWithAbstractConverter));

            var obj = new CopyClass0()
            {
                A = 1
            };

            var res = dto.Copy(new List <string>(), new CopyClass1()
            {
                B = "1"
            });

            res.Single().Should().Be("1");
        }
Ejemplo n.º 14
0
        public void Copy_NestedWithGenerics_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedWithGenerics));

            var src = new CopyClass_MyTemplateItem()
            {
                A = new MyTemplateItem()
                {
                    A = 1
                }
            };
            var dst = new CopyClass0();

            var res = dto.Copy(dst, src);

            res.A.Should().Be(1);
        }
Ejemplo n.º 15
0
        public void As_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedForAs));

            var obj = new CopyClass1()
            {
                A = 1
            };

            var t0 = dto.As <ICopyClass0>(obj);

            t0.Should().NotBeNull();
            t0.A.Should().Be(1);

            var t1 = dto.As <ICopyClass1>(obj);

            t1.Should().BeNull();
        }
Ejemplo n.º 16
0
        public void BaseClassValidation_Validate_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(BaseClassValidation));

            var obj = new BaseClassValidationChild()
            {
                A = -1
            };
            var issues = dto.Validate((object)obj, x => x.RuleFor(t => t).ValidateDto()).Issues;

            issues.Should().HaveCount(1);

            obj = new BaseClassValidationChild()
            {
                A = 1
            };
            issues = dto.Validate((object)obj, x => x.RuleFor(t => t).ValidateDto()).Issues;
            issues.Should().HaveCount(0);
        }
Ejemplo n.º 17
0
        public void UpdateAdaptedClasses_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedCopierContainer1));

            var obj0 = new CopyClass1()
            {
                A = 1, B = "abc"
            };
            var obj1 = new CopyClass1()
            {
                A = 2, B = "def"
            };

            var adapter0 = dto.As <ICopyClass0>(obj0);
            var adapter1 = dto.As <ICopyClass1>(obj1);

            dto.Update(adapter0, adapter1, nameof(obj0.A), nameof(obj0.B));

            obj0.A.Should().Be(2);
            obj0.B.Should().Be("def");
        }
Ejemplo n.º 18
0
        public void As_WithNull_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedForAs));

            AssertionExtensions.Should(() => dto.As <ICopyClass0>(null)).Throw <NullReferenceException>();
        }
Ejemplo n.º 19
0
        static void Convert <TDst>(ITemplateInterf1 <TDst> dst, ITemplateInterf1 <decimal> src, DtoComplex dto)
            where TDst : new()
        {
            dst.A = new TDst();
            var name = dto.As <IName>(dst.A);

            name.Name = src.A;
        }
Ejemplo n.º 20
0
 static void Convert <TDst>(ITemplateInterf1 <TDst> dst, ITemplateInterf1 <int> src, DtoComplex dto)
 {
     dst.A = (TDst)(object)(decimal)src.A;
 }
Ejemplo n.º 21
0
 static void Convert <TSrc>(ITemplateInterf1 <decimal> dst, ITemplateInterf1 <TSrc> src, DtoComplex dto)
 {
     dst.A = (decimal)(int)(object)src.A;
 }
Ejemplo n.º 22
0
 static void Convert <TDst>(ITemplateInterf1 <TDst> dst, ITemplateInterf1 <decimal> src, DtoComplex dto)
     where TDst : Item, new()
 {
     dst.A      = new TDst();
     dst.A.Name = src.A;
 }
Ejemplo n.º 23
0
 void IComplexAdapterRule.Init(object factory, DtoComplex complex)
 {
     Factory = (ValidationRuleFactory <T>)factory;
     Complex = complex;
 }
Ejemplo n.º 24
0
 static void Convert <TDst, TSrc>(ITemplateInterf1 <TDst> dst, ITemplateInterf1 <TSrc> src, DtoComplex dto)
 {
     dst.A = dto.CastValue(src.A, out TDst t);
 }