public void Can_map_when_target_exists()
 {
     var mapper = new MapperBuilder().BuildMapper();
     var dto = mapper.Convert(new Account { Number = "abc123", Owner = new Person { Id = 42 } }, new AccountWith3CtorsDto());
     Assert.Equal(42, dto.OwnerId);
     Assert.Equal("abc123", dto.Number);
 }
 public MappingDescriptorTests()
 {
     output = new StringBuilder();
     var builder = new MapperBuilder();
     builder.Settings.MappingDescriptorWriter = new StringWriter(output);
     mapper = builder.BuildMapper();
 }
Пример #3
0
        public void Can_register_mappings_via_catalog()
        {
            var builder = new MapperBuilder();
            builder.AddCatalogs(new DelegatingCatalog(b => b.Add(new MappingInfo(typeof (Account), typeof (AccountDto), null))));
            var mapper = builder.BuildMapper();

            mapper.Convert<AccountDto>(new Account { Number = "number", Owner = new Person { Id = 3 } });
        }
 public void Can_map_with_callsite_parameter()
 {
     var mapper = new MapperBuilder().BuildMapper();
     var dto = mapper.ConvertWithArguments<AccountWithAdditionalParameterDto>(new Account { Number = "abc123", Owner = new Person { Id = 42 } }, new { language = "en-AU" });
     Assert.Equal("en-AU", dto.Language);
     Assert.Equal(42, dto.OwnerId);
     Assert.Equal("abc123", dto.Number);
 }
        public void Can_map_using_custom_constructor()
        {
            var mapper = new MapperBuilder().BuildMapper();
            var dto = mapper.Convert<AccountWithCtorDto>(new Account { Number = "abc123", Owner = new Person { Id = 42 } });

            Assert.Equal(42, dto.OwnerId);
            Assert.Equal("abc123", dto.Number);
        }
 public void Can_map_when_harcoded_mapping()
 {
     var builder = new MapperBuilder();
     builder.Settings.AddConversionPatternType(typeof (AccountWith2ConstructorsMappingPattern));
     var mapper = builder.BuildMapper();
     var dto = mapper.Convert<AccountWith2CtorsDto>(new Account { Number = "abc123", Owner = new Person { Id = 42 } });
     Assert.Equal(42, dto.OwnerId);
     Assert.Equal("abc123", dto.Number);
 }
 public void Can_map_with_callsite_parameter_via_custom_mapping_step()
 {
     var builder = new MapperBuilder();
     builder.Settings.MappingPatterns = new IMappingPattern[] { new MapMissingCtorParametersFromCallSite(), };
     var mapper = builder.BuildMapper();
     var dto = mapper.ConvertWithArguments<AccountWithAdditionalParameterDto>(new Account { Number = "abc123", Owner = new Person { Id = 42 } }, new { language = "en-AU" });
     Assert.Equal("en-AU", dto.Language);
     Assert.Equal(42, dto.OwnerId);
     Assert.Equal("abc123", dto.Number);
 }
 public ComplexMappingTests()
 {
     builder = new MapperBuilder();
 }