Esempio n. 1
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);
    }
Esempio 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);
    }
Esempio n. 3
0
    public void CanAddTransitiveMappers()
    {
        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", 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);
    }
Esempio n. 4
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();
    }
Esempio n. 5
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);
        }