public void configurations_can_be_bound_to_one_another_using_binding_container() { var cfg = new DestinationConfigurationContainer(null, configFactory); cfg.Map(typeof(ViewModelComponent)).From(typeof(EventComponent)); cfg.Map(typeof(ComplexViewModel)).From(typeof(ComplexEvent)); var binding = cfg.ToBinding(); binding.Bind(); binding.Assert(); var source = new ComplexEvent() { Name = "RootName", Component = new EventComponent() { Name = "ComponentName" } }; var dest = new ComplexViewModel(); var command = binding.CreateCommand(typeof(ComplexEvent), typeof(ComplexViewModel)); command.Map(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_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 can_map_from_component_property_of_diff_name() { var cfg = new DestinationConfigurationContainer(null, configFactory); cfg.Map <ComplexViewModel>() .From(typeof(ComplexEventWithDifferentNamedComponent)).Redirecting <ComplexEventWithDifferentNamedComponent>(its => its.DifferentName, its => its.Component); var binding = cfg.ToBinding(); binding.Bind(); Action validation = binding.Assert; validation.should_not_throw_an <DittoConfigurationException>(); var cmd = binding.CreateCommand(typeof(ComplexEventWithDifferentNamedComponent), typeof(ComplexViewModel)); var src = new ComplexEventWithDifferentNamedComponent() { DifferentName = new EventComponent() { Name = "monsters" } }; var dest = new ComplexViewModel(); cmd.Map(src, dest); dest.Component.Name.should_be_equal_to("monsters"); }
public void it_should_map_nested_components() { container.Map(typeof (ViewModelComponent)).From(typeof (EventComponent)); container.Map(typeof (ComplexViewModel)).From(typeof (ComplexEvent)); var bindable = container.ToBinding(); bindable.Bind(); bindable.Assert(); var source = new ComplexEvent(){Name = "RootName", Component = new EventComponent() {Name = "ComponentName"}}; var dest = new ComplexViewModel(); var executable = bindable.CreateCommand(typeof (ComplexEvent), typeof (ComplexViewModel)); executable.Map(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 complex_model_should_map_to_itself_okay() { container.Map(typeof (ViewModelComponent)).ForCloningOnly(); container.Map(typeof (ComplexViewModel)).ForCloningOnly(); var bindable = container.ToBinding(); bindable.Bind(); bindable.Assert(); bindable.Accept(new CacheInitializer(new Fasterflection())); var source = new ComplexViewModel() {Component = new ViewModelComponent() {Name = "mikey"}, Name = "tasha"}; var dest = new ComplexViewModel(); var executable = bindable.CreateCommand(typeof(ComplexViewModel), typeof(ComplexViewModel)); executable.Map(source, dest); dest.Name.should_be_equal_to("tasha"); dest.Component.should_not_be_null(); dest.Component.Name.should_be_equal_to("mikey"); }
public void configurations_can_be_bound_to_one_another_using_binding_container() { var cfg = new DestinationConfigurationContainer(null, configFactory); cfg.Map(typeof(ViewModelComponent)).From(typeof(EventComponent)); cfg.Map(typeof(ComplexViewModel)).From(typeof(ComplexEvent)); var binding = cfg.ToBinding(); binding.Bind(); binding.Assert(); var source = new ComplexEvent() { Name = "RootName", Component = new EventComponent() { Name = "ComponentName" } }; var dest = new ComplexViewModel(); var command = binding.CreateCommand(typeof(ComplexEvent), typeof(ComplexViewModel)); command.Map(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 can_map_from_component_property_of_diff_name() { var cfg = new DestinationConfigurationContainer(null,configFactory); cfg.Map<ComplexViewModel>() .From(typeof(ComplexEventWithDifferentNamedComponent)).Redirecting<ComplexEventWithDifferentNamedComponent>(its => its.DifferentName, its => its.Component); var binding = cfg.ToBinding(); binding.Bind(); Action validation = binding.Assert; validation.should_not_throw_an<DittoConfigurationException>(); var cmd=binding.CreateCommand(typeof (ComplexEventWithDifferentNamedComponent), typeof (ComplexViewModel)); var src = new ComplexEventWithDifferentNamedComponent(){DifferentName = new EventComponent() {Name = "monsters"}}; var dest = new ComplexViewModel(); cmd.Map(src, dest); dest.Component.Name.should_be_equal_to("monsters"); }
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_redirect_nested_mappings_to_dest_property() { container.Map <ComplexViewModel>() .From <ComplexEvent, TypicalEvent>() .Nesting <TypicalEvent, ViewModelComponent>(its => its.Component, cfg => { }); var bindable = container.ToBinding(); bindable.Bind(); bindable.Assert(); var source = new TypicalEvent() { Name = "RedirectingName", }; var dest = new ComplexViewModel(); var executable = bindable.CreateCommand(typeof(TypicalEvent), typeof(ComplexViewModel)); executable.Map(source, dest); dest.Component.should_not_be_null(); dest.Component.Name.should_be_equal_to("RedirectingName"); }
public void complex_model_should_map_to_itself_okay() { container.Map(typeof(ViewModelComponent)).ForCloningOnly(); container.Map(typeof(ComplexViewModel)).ForCloningOnly(); var bindable = container.ToBinding(); bindable.Bind(); bindable.Assert(); bindable.Accept(new CacheInitializer(new Fasterflection())); var source = new ComplexViewModel() { Component = new ViewModelComponent() { Name = "mikey" }, Name = "tasha" }; var dest = new ComplexViewModel(); var executable = bindable.CreateCommand(typeof(ComplexViewModel), typeof(ComplexViewModel)); executable.Map(source, dest); dest.Name.should_be_equal_to("tasha"); dest.Component.should_not_be_null(); dest.Component.Name.should_be_equal_to("mikey"); }
public void it_should_map_nested_components() { container.Map(typeof(ViewModelComponent)).From(typeof(EventComponent)); container.Map(typeof(ComplexViewModel)).From(typeof(ComplexEvent)); var bindable = container.ToBinding(); bindable.Bind(); bindable.Assert(); var source = new ComplexEvent() { Name = "RootName", Component = new EventComponent() { Name = "ComponentName" } }; var dest = new ComplexViewModel(); var executable = bindable.CreateCommand(typeof(ComplexEvent), typeof(ComplexViewModel)); executable.Map(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_unflatten_components_into_property() { container.Map <ViewModelComponent>().From <FlattenedComponentEvent>().Redirecting <FlattenedComponentEvent>( from => from.DifferentName, to => to.Name); container.Map <ComplexViewModel>() .From <FlattenedComponentEvent>() .UsingValue <FlattenedComponentEvent>("blah", to => to.Name) .Unflattening <FlattenedComponentEvent>(to => to.Component); var bindable = container.ToBinding(); bindable.Bind(); bindable.Assert(); var source = new FlattenedComponentEvent() { DifferentName = "FlattenedName", }; var dest = new ComplexViewModel(); var executable = bindable.CreateCommand(typeof(FlattenedComponentEvent), typeof(ComplexViewModel)); executable.Map(source, dest); dest.Component.should_not_be_null(); dest.Component.Name.should_be_equal_to("FlattenedName"); }
public void it_should_map_nested_components_by_type_with_generic_sugar() { container.Map <ComplexViewModel>() .From <ComplexEventWithDifferentNamedComponent>() .Redirecting <ComplexEventWithDifferentNamedComponent, ViewModelComponent>(from => from.DifferentName, to => to.Component, nested => {}); var binding = container.ToBinding(); binding.Bind(); binding.Assert(); var source = new ComplexEventWithDifferentNamedComponent() { Name = "RootName", DifferentName = new EventComponent() { Name = "ComponentName" } }; var dest = new ComplexViewModel(); var cmd = binding.CreateCommand(source.GetType(), dest.GetType()); cmd.Map(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_map_nested_components_by_type_with_generic_sugar() { container.Map<ComplexViewModel>() .From<ComplexEventWithDifferentNamedComponent>() .Redirecting<ComplexEventWithDifferentNamedComponent,ViewModelComponent>(from => from.DifferentName, to => to.Component,nested=>{}); var binding = container.ToBinding(); binding.Bind(); binding.Assert(); var source = new ComplexEventWithDifferentNamedComponent() { Name = "RootName", DifferentName = new EventComponent() { Name = "ComponentName" } }; var dest = new ComplexViewModel(); var cmd=binding.CreateCommand(source.GetType(), dest.GetType()); cmd.Map(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_unflatten_components_into_property() { container.Map<ViewModelComponent>().From<FlattenedComponentEvent>().Redirecting<FlattenedComponentEvent>( from => from.DifferentName, to => to.Name); container.Map<ComplexViewModel>() .From<FlattenedComponentEvent>() .UsingValue<FlattenedComponentEvent>("blah",to=>to.Name) .Unflattening<FlattenedComponentEvent>(to=>to.Component); var bindable = container.ToBinding(); bindable.Bind(); bindable.Assert(); var source = new FlattenedComponentEvent() { DifferentName = "FlattenedName", }; var dest = new ComplexViewModel(); var executable = bindable.CreateCommand(typeof(FlattenedComponentEvent), typeof(ComplexViewModel)); executable.Map(source, dest); dest.Component.should_not_be_null(); dest.Component.Name.should_be_equal_to("FlattenedName"); }
public void it_should_redirect_nested_mappings_to_dest_property() { container.Map<ComplexViewModel>() .From<ComplexEvent,TypicalEvent>() .Nesting<TypicalEvent,ViewModelComponent>(its=>its.Component,cfg => { }); var bindable = container.ToBinding(); bindable.Bind(); bindable.Assert(); var source = new TypicalEvent() { Name = "RedirectingName",}; var dest = new ComplexViewModel(); var executable = bindable.CreateCommand(typeof (TypicalEvent), typeof (ComplexViewModel)); executable.Map(source, dest); dest.Component.should_not_be_null(); dest.Component.Name.should_be_equal_to("RedirectingName"); }