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"); }
private static void ConfigureDitto() { try { var container = new DestinationConfigurationContainer(null, new TestConfigurationFactory()); container.Map <BenchDestinationProps.Int1>().From <BenchSourceProps.Int1>(); container.Map <BenchDestinationProps.Int2>().From <BenchSourceProps.Int2>(); container.Map <BenchDestinationProps>().From <BenchSourceProps>(); var bindable = container.ToBinding(); bindable.Bind(); bindable.Assert(); var contextualizer = new TestContextualizer(); var cacher = new CacheInitializer(contextualizer); bindable.Accept(cacher); dittoMapCommand = bindable.CreateCommand(typeof(BenchSourceProps), typeof(BenchDestinationProps)); } catch (Exception ex) { Console.WriteLine(ex); throw; } }
private static void ConfigureDitto() { try { var container = new DestinationConfigurationContainer(null, new TestConfigurationFactory()); container.Map<BenchDestinationProps.Int1>().From<BenchSourceProps.Int1>(); container.Map<BenchDestinationProps.Int2>().From<BenchSourceProps.Int2>(); container.Map<BenchDestinationProps>().From<BenchSourceProps>(); var bindable = container.ToBinding(); bindable.Bind(); bindable.Assert(); var contextualizer = new TestContextualizer(); var cacher = new CacheInitializer(contextualizer); bindable.Accept(cacher); dittoMapCommand = bindable.CreateCommand(typeof (BenchSourceProps), typeof (BenchDestinationProps)); } catch (Exception ex) { Console.WriteLine(ex); throw; } }
public void executing_mapping_on_collection_with_unmapped_elements_throws() { // container.Map(typeof(IntegerDest)).From(typeof(IntegerSource)); container.Map(typeof(DestinationWithComponentArray)).From(typeof(SourceWithComponentArray)); var bindable = container.ToBinding(); bindable.Bind(); bindable.Assert(); var source = new SourceWithComponentArray() { IntegerComponents = new[] { new IntegerSource() { AnInt = 1 }, new IntegerSource() { AnInt = 3 }, } }; var dest = new DestinationWithComponentArray(); var executable = bindable.CreateCommand(typeof(SourceWithComponentArray), typeof(DestinationWithComponentArray)); Action executing = () => executable.Map(source, dest); executing.should_throw_because <DittoExecutionException>("'Ditto.Tests.DestinationWithComponentArray:IntegerComponents' requires a collection configuration which was not provided. " + Environment.NewLine + "Be sure you have either provided configuration for the element type ('Ditto.Tests.IntegerDest'), or the collection."); }
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 multiple_source_implementations_work() { var cfg = new DestinationConfigurationContainer(null, new TestConfigurationFactory()); cfg.Map <DestinationWithSpecialSauce>().From <IWorkOkay, YetAnotherImplementation>(); var binding = cfg.ToBinding(); binding.Bind(); binding.Assert(); binding.Accept(new CacheInitializer(new Fasterflection())); var dest = new DestinationWithSpecialSauce(); var cmd1 = binding.CreateCommand(typeof(SourceImplementation), typeof(DestinationWithSpecialSauce)); var source1 = new SourceImplementation() { Name = "mikey" }; cmd1.Map(source1, dest); dest.Name.should_be_equal_to("mikey"); dest = new DestinationWithSpecialSauce(); var cmd2 = binding.CreateCommand(typeof(YetAnotherImplementation), typeof(DestinationWithSpecialSauce)); var source2 = new YetAnotherImplementation() { Name = "tasha", SpecialProperty = 3 }; cmd2.Map(source2, dest); dest.Name.should_be_equal_to("tasha"); dest.SpecialProperty.should_be_equal_to(3); }
public void it_should_map_from_interface_source() { var cfg = new DestinationConfigurationContainer(null, new TestConfigurationFactory()); cfg.Map<Destination>().From<IWorkOkay>(); var binding = cfg.ToBinding(); binding.Bind(); binding.Assert(); var cmd = binding.CreateCommand(typeof (SourceImplementation), typeof (Destination)); var src = new SourceImplementation() {Name = "mikey"}; var dest = new Destination(); cmd.Map(src, dest); dest.Name.should_be_equal_to("mikey"); }
public void validation_fails_when_custom_types_are_mapped_by_property_name_default_but_not_provided_mapping() { var cfg = new DestinationConfigurationContainer(null, configFactory); // cfg.Map(typeof(ViewModelComponent)).From(typeof(EventComponent)); cfg.Map(typeof(ComplexViewModel)).From(typeof(ComplexEvent));//both have property named 'Component', but this would require a custom mapping var binding = cfg.ToBinding(); binding.Bind(); Action propertyNameMappingOnCustomType = binding.Assert; propertyNameMappingOnCustomType.should_throw_because <DittoConfigurationException>("The following properties are not mapped for 'Ditto.Tests.ComplexViewModel':" + Environment.NewLine + "Component" + Environment.NewLine); }
public void it_should_cache_source_implementation_getter_invocations_after_first_call() { var cache = new Fasterflection(); var cfg = new DestinationConfigurationContainer(null, new TestConfigurationFactory()); cfg.Map<Destination>().From<IWorkOkay>(); var binding = cfg.ToBinding(); binding.Bind(); binding.Assert(); binding.Accept(new CacheInitializer(cache)); var src = new SourceImplementation() {Name = "mikey"}; cache.HasCachedGetterFor(typeof(SourceImplementation), "Name").should_be_false(); var value=cache.GetValue("Name", src); cache.HasCachedGetterFor(typeof (SourceImplementation), "Name").should_be_true(); value.should_be_equal_to("mikey"); }
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_from_interface_source() { var cfg = new DestinationConfigurationContainer(null, new TestConfigurationFactory()); cfg.Map <Destination>().From <IWorkOkay>(); var binding = cfg.ToBinding(); binding.Bind(); binding.Assert(); var cmd = binding.CreateCommand(typeof(SourceImplementation), typeof(Destination)); var src = new SourceImplementation() { Name = "mikey" }; var dest = new Destination(); cmd.Map(src, dest); dest.Name.should_be_equal_to("mikey"); }
public void it_should_cache_source_implementation_getter_invocations_after_first_call() { var cache = new Fasterflection(); var cfg = new DestinationConfigurationContainer(null, new TestConfigurationFactory()); cfg.Map <Destination>().From <IWorkOkay>(); var binding = cfg.ToBinding(); binding.Bind(); binding.Assert(); binding.Accept(new CacheInitializer(cache)); var src = new SourceImplementation() { Name = "mikey" }; cache.HasCachedGetterFor(typeof(SourceImplementation), "Name").should_be_false(); var value = cache.GetValue("Name", src); cache.HasCachedGetterFor(typeof(SourceImplementation), "Name").should_be_true(); value.should_be_equal_to("mikey"); }
public void multiple_source_implementations_work() { var cfg = new DestinationConfigurationContainer(null, new TestConfigurationFactory()); cfg.Map<DestinationWithSpecialSauce>().From<IWorkOkay,YetAnotherImplementation>(); var binding = cfg.ToBinding(); binding.Bind(); binding.Assert(); binding.Accept(new CacheInitializer(new Fasterflection())); var dest = new DestinationWithSpecialSauce(); var cmd1 = binding.CreateCommand(typeof(SourceImplementation), typeof(DestinationWithSpecialSauce)); var source1 = new SourceImplementation() { Name = "mikey" }; cmd1.Map(source1, dest); dest.Name.should_be_equal_to("mikey"); dest = new DestinationWithSpecialSauce(); var cmd2 = binding.CreateCommand(typeof(YetAnotherImplementation), typeof(DestinationWithSpecialSauce)); var source2 = new YetAnotherImplementation() { Name = "tasha" ,SpecialProperty = 3}; cmd2.Map(source2, dest); dest.Name.should_be_equal_to("tasha"); dest.SpecialProperty.should_be_equal_to(3); }
public void validation_fails_when_custom_types_are_mapped_by_property_name_default_but_not_provided_mapping() { var cfg = new DestinationConfigurationContainer(null, configFactory); // cfg.Map(typeof(ViewModelComponent)).From(typeof(EventComponent)); cfg.Map(typeof(ComplexViewModel)).From(typeof(ComplexEvent));//both have property named 'Component', but this would require a custom mapping var binding = cfg.ToBinding(); binding.Bind(); Action propertyNameMappingOnCustomType = binding.Assert; propertyNameMappingOnCustomType.should_throw_because<DittoConfigurationException>("The following properties are not mapped for 'Ditto.Tests.ComplexViewModel':"+Environment.NewLine+"Component"+Environment.NewLine); }
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"); }