Ejemplo n.º 1
0
        public void Validate_WithTrimValidation_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedCopierContainer0), typeof(NestedCopierContainer1));

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

            obj = dto.FixValue(obj, nameof(obj), x => x.ValidateDto());
            obj.B.Should().Be("b");
        }
Ejemplo n.º 2
0
        public void Update_WithTransformFunction_IgnoreField_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedWithConvert));

            var dst = new CopyClass1();
            var res = dto.Update(dst, new CopyClass0()
            {
                A = 2
            });

            res.B.Should().BeNull();
        }
Ejemplo n.º 3
0
        public void Update_WithTransformFunction_ForExactMatch_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedWithConvertWithExactMatch));

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

            res.B.Should().Be("2");
        }
Ejemplo n.º 4
0
        public void Copy_WithTransformFunction_Test()
        {
            var dto = new DtoComplex().ByNestedClasses(typeof(NestedWithConvert));

            var dst = new CopyClass1();
            var res = dto.Copy(dst, new CopyClass0()
            {
                A = 2
            });

            res.B.Should().Be("2");
        }
Ejemplo n.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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");
        }