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;
            }
        }
Example #2
0
        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);
        }
Example #3
0
        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");
        }
        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;
            }
        }
Example #5
0
        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");
        }
Example #6
0
 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");
 }
Example #7
0
        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);
        }
Example #8
0
 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 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");
        }
Example #11
0
        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");
        }
Example #12
0
        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);
        }
Example #13
0
        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");
        }
Example #14
0
 public static BindingDestinationConfigurationContainer ToBinding(this DestinationConfigurationContainer cfg)
 {
     return(new BindingDestinationConfigurationContainer(new BinderFactory(new Fasterflection()), new TestContextualizer(), cfg, new TestConfigurationFactory()));
 }
 public complex_model_mapping_tests()
 {
     contextualizer = new TestContextualizer();
     configFactory  = new TestConfigurationFactory();
     container      = new DestinationConfigurationContainer(null, configFactory);
 }
 public collection_mapping_tests()
 {
     container = new DestinationConfigurationContainer(null, new TestConfigurationFactory());
 }
 public complex_model_mapping_tests()
 {
     contextualizer = new TestContextualizer();
     configFactory=new TestConfigurationFactory();
     container = new DestinationConfigurationContainer(null, configFactory);
 }
        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 collection_mapping_tests()
 {
     container = new DestinationConfigurationContainer(null, new TestConfigurationFactory());
 }