public void manually_configuring_dest_property_with_more_than_one_resolver() { var cfg = new DestinationConfiguration(typeof(TypicalViewModel)); cfg.From(typeof(TypicalEvent)); cfg.SetPropertyResolver(new PropertyNameCriterion("SomeId"), typeof(TypicalEvent), new StaticValueResolver(new Guid("8CF7C50E-792D-4A28-AB74-81879BC233A8"))); Action duplication = () => cfg.SetPropertyResolver(new PropertyNameCriterion("SomeId"), typeof(TypicalEvent), new StaticValueResolver(new Guid("1B8CF33D-92B8-4E82-9E8F-5EEDE7BA14F0"))); duplication.should_throw_because <DittoConfigurationException>("Destination property 'Ditto.Tests.TypicalViewModel:SomeId' already has a manually, or conventioned, configured resolver from source type 'Ditto.Tests.TypicalEvent'"); }
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 manually_configuring_dest_property_is_not_overriden_by_convention() { var cfg = new DestinationConfiguration(typeof(TypicalViewModel)); cfg.From(typeof(TypicalEvent)); cfg.SetPropertyResolver(new PropertyNameCriterion("SomeId"), typeof(TypicalEvent), new StaticValueResolver(new Guid("8CF7C50E-792D-4A28-AB74-81879BC233A8"))); Action duplication = () => cfg.ApplyingConvention(new PropertyNameCriterion("SomeId"), new StaticValueResolver(new Guid("1B8CF33D-92B8-4E82-9E8F-5EEDE7BA14F0"))); duplication.should_not_throw_an <DittoConfigurationException>(); var source = new TypicalEvent() { Id = Guid.NewGuid(), Name = "mikey" }; var dest = new TypicalViewModel(); var exec = cfg.ToExecutable(typeof(TypicalEvent)); var command = new DefaultMapCommand(exec, contextualizer); command.Map(source, dest); dest.SomeId.should_be_equal_to(new Guid("8CF7C50E-792D-4A28-AB74-81879BC233A8")); }
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 manually_configuring_dest_property_with_more_than_one_resolver() { var cfg = new DestinationConfiguration(typeof(TypicalViewModel)); cfg.From(typeof (TypicalEvent)); cfg.SetPropertyResolver(new PropertyNameCriterion("SomeId"),typeof(TypicalEvent),new StaticValueResolver(new Guid("8CF7C50E-792D-4A28-AB74-81879BC233A8"))); Action duplication=()=>cfg.SetPropertyResolver(new PropertyNameCriterion("SomeId"), typeof(TypicalEvent), new StaticValueResolver(new Guid("1B8CF33D-92B8-4E82-9E8F-5EEDE7BA14F0"))); duplication.should_throw_because<DittoConfigurationException>("Destination property 'Ditto.Tests.TypicalViewModel:SomeId' already has a manually, or conventioned, configured resolver from source type 'Ditto.Tests.TypicalEvent'"); }
public void manually_configuring_dest_property_is_not_overriden_by_convention() { var cfg = new DestinationConfiguration(typeof(TypicalViewModel)); cfg.From(typeof(TypicalEvent)); cfg.SetPropertyResolver(new PropertyNameCriterion("SomeId"), typeof(TypicalEvent), new StaticValueResolver(new Guid("8CF7C50E-792D-4A28-AB74-81879BC233A8"))); Action duplication = () => cfg.ApplyingConvention(new PropertyNameCriterion("SomeId"), new StaticValueResolver(new Guid("1B8CF33D-92B8-4E82-9E8F-5EEDE7BA14F0"))); duplication.should_not_throw_an<DittoConfigurationException>(); var source = new TypicalEvent() {Id = Guid.NewGuid(), Name = "mikey"}; var dest = new TypicalViewModel(); var exec = cfg.ToExecutable(typeof (TypicalEvent)); var command = new DefaultMapCommand(exec, contextualizer); command.Map(source, dest); dest.SomeId.should_be_equal_to(new Guid("8CF7C50E-792D-4A28-AB74-81879BC233A8")); }