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");
        }
示例#2
0
        public void it_should_resolve_to_list_from_list()
        {
            var resolver = new ListResolver(MappableProperty.For <SourceWithCollections>(s => s.ListOfIntegerComponents), integerComponentElementConfig, new Fasterflection());
            var source   = new SourceWithCollections()
            {
                ListOfIntegerComponents =
                    new List <IntegerSource> {
                    new IntegerSource {
                        AnInt = 1
                    }, new IntegerSource()
                    {
                        AnInt = 4
                    }
                }
            };


            var destination = new DestWithCollections();
            var result      = resolver.TryResolve(contextualizer.CreateContext(source, destination), MappableProperty.For <DestWithCollections>(its => its.ListOfIntegerComponents));

            result.Value.should_be_a_type_of <List <IntegerDest> >();
            ((List <IntegerDest>)result.Value)[0].AnInt.should_be_equal_to(1);
            ((List <IntegerDest>)result.Value)[1].AnInt.should_be_equal_to(4);
        }