public void collections_of_components_are_mapped_with_list()
        {
            container.Map(typeof(IntegerDest)).From(typeof(IntegerSource));
            container.Map(typeof(DestWithCollections)).From(typeof(SourceWithCollections));
            var bindable = container.ToBinding();

            bindable.Bind();
            bindable.Assert();
            var source = new SourceWithCollections()
            {
                ArrayOfIntegerComponents = new IntegerSource[0],
                ListOfIntegerComponents  = new List <IntegerSource> {
                    new IntegerSource()
                    {
                        AnInt = 1
                    }, new IntegerSource()
                    {
                        AnInt = 3
                    },
                }
            };
            var dest = new DestWithCollections();

            var executable = bindable.CreateCommand(typeof(SourceWithCollections), typeof(DestWithCollections));

            executable.Map(source, dest);
            dest.ListOfIntegerComponents.Count.should_be_equal_to(2);
        }
        public void it_should_resolve_to_array_from_array()
        {
            var resolver = new ListResolver(MappableProperty.For<SourceWithCollections>(s => s.ArrayOfIntegerComponents),integerComponentElementConfig, new Fasterflection());
            var source = new SourceWithCollections()
                             {
                                 ArrayOfIntegerComponents =
                                     new[] {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.ArrayOfIntegerComponents));
            result.Value.should_be_a_type_of<IntegerDest[]>();
            ((IntegerDest[])result.Value)[0].AnInt.should_be_equal_to(1);
            ((IntegerDest[])result.Value)[1].AnInt.should_be_equal_to(4);
        }
        public void collections_of_components_are_mapped_with_list()
        {
            container.Map(typeof (IntegerDest)).From(typeof (IntegerSource));
            container.Map(typeof (DestWithCollections)).From(typeof (SourceWithCollections));
            var bindable = container.ToBinding();
            bindable.Bind();
            bindable.Assert();
            var source = new SourceWithCollections()
            {
                ArrayOfIntegerComponents = new IntegerSource[0],
                ListOfIntegerComponents = new List<IntegerSource>{new IntegerSource() { AnInt = 1 }, new IntegerSource() { AnInt = 3 }, }
            };
            var dest = new DestWithCollections();

            var executable = bindable.CreateCommand(typeof (SourceWithCollections), typeof (DestWithCollections));
            executable.Map(source, dest);
            dest.ListOfIntegerComponents.Count.should_be_equal_to(2);
        }
Example #4
0
        public void it_should_resolve_from_array_to_list()
        {
            var resolver = new ListResolver(MappableProperty.For <SourceWithCollections>(s => s.ArrayOfIntegerComponents), integerComponentElementConfig, new Fasterflection());
            var source   = new SourceWithCollections()
            {
                ArrayOfIntegerComponents =
                    new[] { 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);
        }