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); }
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); }
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); }
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(); }
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); }