Exemplo n.º 1
0
        public void Map_To_IEnumerable_Class_Should_Pass()
        {
            ClassA classA = new ClassA()
            {
                Id = 123
            };

            ClassB classB = classA.Adapt <ClassB>();

            classB.Id.ShouldBe(classA.Id);
        }
Exemplo n.º 2
0
        public void BasicConvert()
        {
            var classA = new ClassA()
            {
                Id    = 123,
                Name  = "",
                Price = 23.3m
            };

            var classB = classA.Adapt <ClassB>();

            classB.Should().BeEquivalentTo(new ClassB()
            {
                Id    = 123,
                Name  = "",
                Price = 23.3m
            });
        }
Exemplo n.º 3
0
        public void BasicConvert_Type_Not_Same()
        {
            var classA = new ClassA()
            {
                Id    = 123,
                Name  = "",
                Price = 23.3m,
                Count = "3",
            };

            var classC = classA.Adapt <ClassC>();

            classC.Should().BeEquivalentTo(new ClassC()
            {
                Id    = "123",
                Name  = "",
                Price = "23.3",
                Count = 3,
            });
        }
        public void Basic()
        {
            var config = new TypeAdapterConfig();

            config.NewConfig <ClassA, ClassB>()
            .Map(b => b.Id, a => a.Id + 1)
            .Map(b => b.Name, a => "Name");

            var classA = new ClassA()
            {
                Id   = 1,
                Name = "Test"
            };
            var classB = classA.Adapt <ClassB>(config);

            classB.Should().BeEquivalentTo(new ClassB()
            {
                Id   = 2,
                Name = "Name"
            });
        }
Exemplo n.º 5
0
        public void CustomConvert()
        {
            TypeAdapterConfig <ClassA, ClassB>
            .NewConfig()
            .Ignore(b => b.Price)
            .Map(b => b.Name, a => $"{a.Id}_{a.Name}");

            var classA = new ClassA()
            {
                Id    = 1,
                Name  = "Test",
                Price = 12.34m
            };
            var classB = classA.Adapt <ClassB>();

            classB.Should().BeEquivalentTo(new ClassB()
            {
                Id    = 1,
                Name  = "1_Test",
                Price = 0m,
            });
        }