public void MapToExistentTests() { var obj = new AutoMapperObjectMapper(); var result = new H2(); result = obj.Map(new H1 { Value = 42 }, result); Assert.AreEqual(result.Value, 42); }
/// <summary> /// 测试 - 初始化 /// </summary> public QueryServiceTest() { _id = Guid.NewGuid(); _id2 = Guid.NewGuid(); _entity = new EntitySample(_id) { Name = "A" }; _entity2 = new EntitySample(_id2) { Name = "B" }; _repository = Substitute.For <IRepositorySample>(); _service = new QueryServiceSample(_repository); _service.LazyServiceProvider = Substitute.For <ILazyServiceProvider>(); var allAssemblyFinder = new AppDomainAllAssemblyFinder(); var mapperProfileTypeFinder = new MapperProfileTypeFinder(allAssemblyFinder); var instances = mapperProfileTypeFinder .FindAll() .Select(type => Bing.Reflection.Reflections.CreateInstance <IObjectMapperProfile>(type)) .ToList(); var configuration = new MapperConfiguration(cfg => { foreach (var instance in instances) { Debug.WriteLine($"初始化AutoMapper配置:{instance.GetType().FullName}"); instance.CreateMap(); // ReSharper disable once SuspiciousTypeConversion.Global cfg.AddProfile(instance as Profile); } }); var mapper = new AutoMapperObjectMapper(configuration, instances); ObjectMapperExtensions.SetMapper(mapper); }
public void MapToNewTests() { var obj = new AutoMapperObjectMapper(); var result = obj.Map <H1, H2>(new H1 { Value = 42 }); Assert.AreEqual(result.Value, 42); }
public void MapToExistentTests() { var obj = new AutoMapperObjectMapper(); var result = new H2(); result = obj.Map(new H1 { Value = 42 }, result); Assert.AreEqual(result.Value, 42); }
public MapTest() { var allAssemblyFinder = new AppDomainAllAssemblyFinder(); var mapperProfileTypeFinder = new MapperProfileTypeFinder(allAssemblyFinder); var instances = mapperProfileTypeFinder .FindAll() .Select(type => Reflections.CreateInstance <IObjectMapperProfile>(type)) .ToList(); var configuration = new MapperConfiguration(cfg => { foreach (var instance in instances) { Debug.WriteLine($"初始化AutoMapper配置:{instance.GetType().FullName}"); instance.CreateMap(); // ReSharper disable once SuspiciousTypeConversion.Global cfg.AddProfile(instance as Profile); } }); var mapper = new AutoMapperObjectMapper(configuration, instances); ObjectMapperExtensions.SetMapper(mapper); }
public void MapToNewTests() { var obj = new AutoMapperObjectMapper(); var result = obj.Map<H1, H2>(new H1 {Value = 42}); Assert.AreEqual(result.Value, 42); }