public void global_behavioral_resolvers_are_applied() { WithConfiguration <SystemPersonConfiguration>(); var configurations = container.Resolve <IInitializeDitto>(); Guid id = Guid.Empty; var testGlobals = new TestGlobals(container, null, new Dictionary <IPropertyCriterion, IResolveValue> { { PropertyNameCriterion.From <SystemPerson>(p => p.SystemId), new LambdaResolver <SystemPerson>(o => id = Guid.NewGuid()) }, { new TypePropertyCriterion(typeof(int)), new LambdaResolver <PersonalInfo>(val => val.Age + 2) } }); container.Register(Component.For <IConfigureGlobalConventions>().Instance(testGlobals)); configurations.Initialize(); var mapper = container.Resolve <IMap>(); var output = mapper.Map <SystemPerson>(new PersonalInfo() { Age = 3, Name = "mikey", }); output.Name.should_be_equal_to("mikey"); output.SystemId.should_be_equal_to(id); output.Age.should_be_equal_to(5); container.Release(mapper); container.Release(configurations); }
public void global_converters_are_applied() { WithConfiguration <PeopleConfiguration>(); var configurations = container.Resolve <IInitializeDitto>(); var testGlobals = new TestGlobals(container, new List <IConvertValue> { new DateTimeUtcConverter() }, null); container.Register(Component.For <IConfigureGlobalConventions>().Instance(testGlobals)); configurations.Initialize(); var mapper = container.Resolve <IMap>(); var notUtc = new DateTime(2004, 12, 7, 5, 4, 3); var output = mapper.Map <Person>(new PersonalInfo() { Age = 3, Name = "mikey", Birthdate = notUtc }); output.Age.should_be_equal_to(3); output.Name.should_be_equal_to("mikey"); output.MothersName.should_be_equal_to(null); output.Birthdate.should_be_equal_to(notUtc.ToUniversalTime()); output.Birthdate.Kind.should_be_equal_to(DateTimeKind.Utc); container.Release(mapper); container.Release(configurations); }
public void global_ignore_resolvers_are_applied() { WithConfiguration <SystemPersonConfiguration>(); var configurations = container.Resolve <IInitializeDitto>(); var testGlobals = new TestGlobals(container, null, new Dictionary <IPropertyCriterion, IResolveValue> { { PropertyNameCriterion.From <SystemPerson>(p => p.SystemId), new IgnoreResolver() } }); container.Register(Component.For <IConfigureGlobalConventions>().Instance(testGlobals)); configurations.Initialize(); var mapper = container.Resolve <IMap>(); var output = mapper.Map <SystemPerson>(new PersonalInfo() { Age = 3, Name = "mikey", }); output.Age.should_be_equal_to(3); output.Name.should_be_equal_to("mikey"); output.Age.should_be_equal_to(3); output.SystemId.should_be_equal_to(Guid.Empty); container.Release(mapper); container.Release(configurations); }