public void it_should_give_priority_to_manually_configured_mappings() { var src1 = new PersonalInfo() { Age = 3, Name = "mikey" }; var destination = new SystemPerson() { MothersName = "ignoremeplease" }; Guid systemId = Guid.NewGuid(); Guid myManualSystemId = new Guid("EE99B786-B3A2-426A-BA46-53B990383DA1"); var cfg = new DestinationConfiguration <SystemPerson>(new TestConfigurationFactory()); cfg.From(typeof(PersonalInfo), typeof(Parents)); cfg.ApplyingConvention(new StaticValueResolver(systemId), m => m.SystemId); cfg.UsingValue <PersonalInfo>(myManualSystemId, on => on.SystemId); var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); var executable = bindable.CreateExecutableMapping(typeof(PersonalInfo)); executable.Execute(contextualizer.CreateContext(src1, destination)); destination.SystemId.should_not_be_equal_to(systemId); destination.SystemId.should_be_equal_to(myManualSystemId); }
public void it_should_map_nested_components_by_type() { var componentConfig = new DestinationConfiguration(typeof(ViewModelComponent)); componentConfig.From(typeof(EventComponent)); var modelConfig = new DestinationConfiguration(typeof(ComplexViewModel)); modelConfig.From(typeof(ComplexEventWithDifferentNamedComponent)); modelConfig.SetPropertyResolver( PropertyNameCriterion.From <ComplexViewModel>(m => m.Component), typeof(ComplexEventWithDifferentNamedComponent), new RedirectingConfigurationResolver(MappableProperty.For <ComplexEventWithDifferentNamedComponent>(s => s.DifferentName), configFactory.CreateBindableConfiguration(componentConfig.TakeSnapshot()))); var bindable = configFactory.CreateBindableConfiguration(modelConfig.TakeSnapshot()); var source = new ComplexEventWithDifferentNamedComponent() { Name = "RootName", DifferentName = new EventComponent() { Name = "ComponentName" } }; var dest = new ComplexViewModel(); var executable = bindable.CreateExecutableMapping(typeof(ComplexEventWithDifferentNamedComponent)); executable.Execute(contextualizer.CreateContext(source, dest)); dest.Name.should_be_equal_to("RootName"); dest.Component.should_not_be_null(); dest.Component.Name.should_be_equal_to("ComponentName"); }
public void it_should_apply_convention_during_mapping() { var src1 = new PersonalInfo() { Age = 3, Name = "mikey" }; var destination = new SystemPerson() { MothersName = "ignoremeplease" }; Guid systemId = Guid.NewGuid(); var cfg = new DestinationConfiguration <SystemPerson>(new TestConfigurationFactory()); cfg.From(typeof(PersonalInfo), typeof(Parents)) .ApplyingConvention(new StaticValueResolver(systemId), m => m.SystemId); var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); var executable = bindable.CreateExecutableMapping(typeof(PersonalInfo)); executable.Execute(contextualizer.CreateContext(src1, destination)); destination.Age.should_be_equal_to(3); destination.MothersName.should_be_equal_to("ignoremeplease"); destination.SystemId.should_be_equal_to(systemId); destination.Name.should_be_equal_to("mikey"); }
public void can_map_from_property_of_diff_name() { var cfg = new DestinationConfiguration<TypicalViewModel>(configFactory); cfg.From(typeof (TypicalEvent)).Redirecting<TypicalEvent>(its => its.Id, its => its.SomeId); var bindable = configFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); Action validation = bindable.Assert; validation.should_not_throw_an<DittoConfigurationException>(); }
public void can_map_static_value_to_property() { var cfg = new DestinationConfiguration<TypicalViewModel>(configFactory); cfg.From(typeof (TypicalEvent)).UsingValue<TypicalEvent>(Guid.NewGuid(), its => its.SomeId); var bindable = configFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); Action validation = bindable.Assert; validation.should_not_throw_an<DittoConfigurationException>(); }
public collection_resolver_tests() { var factory = new TestConfigurationFactory(); var cfg = new DestinationConfiguration(typeof (IntegerDest)); cfg.From(typeof (IntegerSource)); integerComponentElementConfig = factory.CreateBindableConfiguration(cfg.TakeSnapshot()); contextualizer = new TestContextualizer(); }
public collection_resolver_tests() { var factory = new TestConfigurationFactory(); var cfg = new DestinationConfiguration(typeof(IntegerDest)); cfg.From(typeof(IntegerSource)); integerComponentElementConfig = factory.CreateBindableConfiguration(cfg.TakeSnapshot()); contextualizer = new TestContextualizer(); }
public void it_should_determine_candidate_properties() { var modelConfig = new DestinationConfiguration(typeof(DestinationWithComponentArray)); modelConfig.From(typeof (SourceWithComponentArray)); var cfg = configFactory.CreateBindableConfiguration(modelConfig.TakeSnapshot()); var binder = new ListPropertyBinder(null); var candidates = binder.GetCandidateDestinationProperties(cfg); candidates.should_have_item_matching(its => its.PropertyType == typeof (IntegerDest[])); }
public void can_map_from_property_of_diff_name() { var cfg = new DestinationConfiguration <TypicalViewModel>(configFactory); cfg.From(typeof(TypicalEvent)).Redirecting <TypicalEvent>(its => its.Id, its => its.SomeId); var bindable = configFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); Action validation = bindable.Assert; validation.should_not_throw_an <DittoConfigurationException>(); }
public void can_map_static_value_to_property() { var cfg = new DestinationConfiguration <TypicalViewModel>(configFactory); cfg.From(typeof(TypicalEvent)).UsingValue <TypicalEvent>(Guid.NewGuid(), its => its.SomeId); var bindable = configFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); Action validation = bindable.Assert; validation.should_not_throw_an <DittoConfigurationException>(); }
public void missing_property_mapping_throws() { var cfg = new DestinationConfiguration(typeof(Person)); cfg.From(typeof(PersonalInfo), typeof(Parents)); var bindable = configFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); Action validation = bindable.Assert; validation.should_throw_an <DittoConfigurationException>(); validation.should_throw_because <DittoConfigurationException>("The following properties are not mapped for '" + typeof(Person) + "':" + Environment.NewLine + "FathersName" + Environment.NewLine); }
public void it_should_determine_candidate_properties() { var modelConfig = new DestinationConfiguration(typeof(DestinationWithComponentArray)); modelConfig.From(typeof(SourceWithComponentArray)); var cfg = configFactory.CreateBindableConfiguration(modelConfig.TakeSnapshot()); var binder = new ListPropertyBinder(null); var candidates = binder.GetCandidateDestinationProperties(cfg); candidates.should_have_item_matching(its => its.PropertyType == typeof(IntegerDest[])); }
public void it_should_support_other_property_specifications() { var cfg = new DestinationConfiguration(typeof(SystemPerson)); cfg.From(typeof(PersonalInfo), typeof(Parents)) .ApplyingConvention(new PrefixPropertyCriterion("System"), new IgnoreResolver()); var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); Action validation = bindable.Assert; validation.should_not_throw_an <DittoConfigurationException>(); }
public void it_should_include_conventions_in_validation() { var cfg = new DestinationConfiguration(typeof(SystemPerson)); cfg.From(typeof(PersonalInfo), typeof(Parents)) .ApplyingConvention(new PropertyNameCriterion("SystemId"), new IgnoreResolver()); var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); Action validation = bindable.Assert; validation.should_not_throw_an <DittoConfigurationException>(); }
public void it_should_apply_conventions_to_types_of_properties() { var src1 = new PersonalInfo() { Age = 3, Name = "mikey" }; var destination = new ManyDates(); var dateTime = new DateTime(2009, 8, 1, 0, 0, 0); var cfg = new DestinationConfiguration(typeof(ManyDates)); cfg.From(typeof (PersonalInfo), typeof (Parents)) .ApplyingConvention(new TypePropertyCriterion(typeof (DateTime)), new StaticValueResolver(dateTime)); var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); var executable = bindable.CreateExecutableMapping(typeof (PersonalInfo)); executable.Execute(contextualizer.CreateContext(src1, destination)); destination.DateTime1.should_be_equal_to(dateTime); destination.DateTime2.should_be_equal_to(dateTime); destination.Name.should_be_equal_to("mikey"); }
public void it_should_give_priority_to_manually_configured_mappings() { var src1 = new PersonalInfo() { Age = 3, Name = "mikey" }; var destination = new SystemPerson() { MothersName = "ignoremeplease" }; Guid systemId = Guid.NewGuid(); Guid myManualSystemId = new Guid("EE99B786-B3A2-426A-BA46-53B990383DA1"); var cfg = new DestinationConfiguration<SystemPerson>(new TestConfigurationFactory()); cfg.From(typeof(PersonalInfo), typeof(Parents)); cfg.ApplyingConvention(new StaticValueResolver(systemId), m => m.SystemId); cfg.UsingValue<PersonalInfo>(myManualSystemId, on => on.SystemId); var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); var executable = bindable.CreateExecutableMapping(typeof(PersonalInfo)); executable.Execute(contextualizer.CreateContext(src1, destination)); destination.SystemId.should_not_be_equal_to(systemId); destination.SystemId.should_be_equal_to(myManualSystemId); }
public void it_should_apply_convention_during_mapping() { var src1 = new PersonalInfo() { Age = 3, Name = "mikey" }; var destination = new SystemPerson(){MothersName = "ignoremeplease"}; Guid systemId=Guid.NewGuid(); var cfg = new DestinationConfiguration<SystemPerson>(new TestConfigurationFactory()); cfg.From(typeof(PersonalInfo), typeof(Parents)) .ApplyingConvention(new StaticValueResolver(systemId), m=>m.SystemId); var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); var executable = bindable.CreateExecutableMapping(typeof (PersonalInfo)); executable.Execute(contextualizer.CreateContext(src1,destination)); destination.Age.should_be_equal_to(3); destination.MothersName.should_be_equal_to("ignoremeplease"); destination.SystemId.should_be_equal_to(systemId); destination.Name.should_be_equal_to("mikey"); }
public void it_should_map_nested_components_by_type() { var componentConfig = new DestinationConfiguration(typeof(ViewModelComponent)); componentConfig.From(typeof(EventComponent)); var modelConfig = new DestinationConfiguration(typeof(ComplexViewModel)); modelConfig.From(typeof (ComplexEventWithDifferentNamedComponent)); modelConfig.SetPropertyResolver( PropertyNameCriterion.From<ComplexViewModel>(m=>m.Component), typeof(ComplexEventWithDifferentNamedComponent), new RedirectingConfigurationResolver(MappableProperty.For<ComplexEventWithDifferentNamedComponent>(s => s.DifferentName), configFactory.CreateBindableConfiguration(componentConfig.TakeSnapshot()))); var bindable = configFactory.CreateBindableConfiguration(modelConfig.TakeSnapshot()); var source = new ComplexEventWithDifferentNamedComponent() { Name = "RootName", DifferentName= new EventComponent() { Name = "ComponentName" } }; var dest = new ComplexViewModel(); var executable = bindable.CreateExecutableMapping(typeof(ComplexEventWithDifferentNamedComponent)); executable.Execute(contextualizer.CreateContext(source, dest)); dest.Name.should_be_equal_to("RootName"); dest.Component.should_not_be_null(); dest.Component.Name.should_be_equal_to("ComponentName"); }
public void it_should_apply_conventions_to_types_of_properties() { var src1 = new PersonalInfo() { Age = 3, Name = "mikey" }; var destination = new ManyDates(); var dateTime = new DateTime(2009, 8, 1, 0, 0, 0); var cfg = new DestinationConfiguration(typeof(ManyDates)); cfg.From(typeof(PersonalInfo), typeof(Parents)) .ApplyingConvention(new TypePropertyCriterion(typeof(DateTime)), new StaticValueResolver(dateTime)); var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); var executable = bindable.CreateExecutableMapping(typeof(PersonalInfo)); executable.Execute(contextualizer.CreateContext(src1, destination)); destination.DateTime1.should_be_equal_to(dateTime); destination.DateTime2.should_be_equal_to(dateTime); destination.Name.should_be_equal_to("mikey"); }
public void it_should_include_conventions_in_validation() { var cfg = new DestinationConfiguration(typeof(SystemPerson)); cfg.From(typeof (PersonalInfo), typeof (Parents)) .ApplyingConvention(new PropertyNameCriterion("SystemId"), new IgnoreResolver()); var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); Action validation = bindable.Assert; validation.should_not_throw_an<DittoConfigurationException>(); }
public void missing_property_mapping_throws() { var cfg = new DestinationConfiguration(typeof(Person)); cfg.From(typeof (PersonalInfo), typeof (Parents)); var bindable = configFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); Action validation = bindable.Assert; validation.should_throw_an<DittoConfigurationException>(); validation.should_throw_because<DittoConfigurationException>("The following properties are not mapped for '" + typeof(Person) + "':" + Environment.NewLine + "FathersName" + Environment.NewLine); }
public void it_should_support_other_property_specifications() { var cfg = new DestinationConfiguration(typeof(SystemPerson)); cfg.From(typeof(PersonalInfo), typeof(Parents)) .ApplyingConvention(new PrefixPropertyCriterion("System"), new IgnoreResolver()); var bindable = bindableFactory.CreateBindableConfiguration(cfg.TakeSnapshot()); Action validation = bindable.Assert; validation.should_not_throw_an<DittoConfigurationException>(); }