Exemplo n.º 1
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");
        }
Exemplo n.º 2
0
        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");
        }
Exemplo n.º 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");
        }
Exemplo n.º 4
0
        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");
        }
Exemplo n.º 5
0
        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");
        }
Exemplo n.º 6
0
 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");
 }