Exemplo n.º 1
0
    public void CanAddCombineMappers()
    {
        var mapper1 = new AOTMapperBuilder()
                      .AddMapper <TestUser, TestUserEntity>((m, s)
                                                            => new TestUserEntity
        {
            Name = s.Name,
            Age  = s.Age,
            Role = m.Map <TestUserRoleEntity>(s.Role)
        })
                      .Build();

        var mapper2 = new AOTMapperBuilder()
                      .AddMapper <TestUserRole, TestUserRoleEntity>((m, s)
                                                                    => new TestUserRoleEntity
        {
            Name = s.Name
        })
                      .Build();

        var mapper = AOTMapperBuilder
                     .FromMappers(mapper1, mapper2)
                     .Build();

        var user = new TestUser {
            Name = "John", Age = 30, Role = new TestUserRole {
                Name = "Admin"
            }
        };
        var userEntity = mapper.Map <TestUserEntity>(user);

        userEntity.Name.Should().Be(user.Name);
        userEntity.Age.Should().Be(user.Age);
        userEntity.Role.Name.Should().Be(user.Role.Name);
    }
Exemplo n.º 2
0
    public void CanAddMultipleMappers()
    {
        var mapper = new AOTMapperBuilder()
                     .AddMapper <TestUser, TestUserEntity>((m, s)
                                                           => new TestUserEntity
        {
            Name = s.Name,
            Age  = s.Age
        })
                     .AddMapper <TestUserRole, TestUserRoleEntity>((m, s)
                                                                   => new TestUserRoleEntity
        {
            Name = s.Name
        })
                     .Build();

        var userRole = new TestUserRole()
        {
            Name = "Admin",
        };

        var userRoleEntity = mapper.Map <TestUserRoleEntity>(userRole);

        userRole.Name.Should().Be(userRoleEntity.Name);
    }
Exemplo n.º 3
0
    public void MissingPropertiesAreIgnored()
    {
        var mapper = new AOTMapperBuilder()
                     .AddMapper <TestUser, TestUserEntity>((m, s)
                                                           => new TestUserEntity
        {
            Name = s.Name,
            Age  = s.Age,
            Role = m.Map <TestUserRoleEntity>(s.Role)
        })
                     .AddMapper <TestUserRole, TestUserRoleEntity>((m, s)
                                                                   => new TestUserRoleEntity
        {
            Name = s.Name
        })
                     .Build();

        var user = new TestUser {
            Name = "John"
        };
        var userEntity = mapper.Map <TestUserEntity>(user);

        userEntity.Name.Should().Be(user.Name);
        userEntity.Age.Should().Be(0);
        userEntity.Role.Should().BeNull();
    }
Exemplo n.º 4
0
    public async Task AOTMapperExtensionWorks()
    {
        var assembly = await TestProject.Project.CompileToRealAssembly();

        var type   = assembly.GetType("AOTMapper.Core.AOTMapperForAOTMapperTestProject");
        var method = type.GetMethod("AddAOTMapperTestProject")
                     .CreateDelegate <Func <AOTMapperBuilder, AOTMapperBuilder> >();

        var builder = new AOTMapperBuilder();

        method.Invoke(builder);

        Assert.NotEmpty(builder.Descriptors);
    }
Exemplo n.º 5
0
    public static void Main()
    {
        var mapper = new AOTMapperBuilder()
                     .AddAOTMapperTestProject()
                     .Build();

        var entity = mapper.Map <UserEntity>(new User
        {
            FirstName = "John",
            LastName  = "Doe",
        });

        var user = mapper.Map <User>(entity);
    }
Exemplo n.º 6
0
        public void CanPinType()
        {
            var mapper = new AOTMapperBuilder()
                         .AddMapper <IUser, TestUserEntity>((m, s)
                                                            => new TestUserEntity
            {
                Name = s.Name,
                Age  = s.Age
            })
                         .Build();

            var user = new TestUser {
                Name = "John", Age = 30
            };
            var userEntity = mapper.Map <TestUserEntity, IUser>(user);

            userEntity.Name.Should().Be(user.Name);
            userEntity.Age.Should().Be(user.Age);
        }