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");
        }
Example #2
0
        public void it_can_map_string_to_datetime()
        {
            var context    = Contextualize(new StringToDateTimeConverter());
            var assignment = context.BuildValueAssignment(MappableProperty.For <Destination>(d => d.AnDateTime));

            assignment.SetValue(new Result(true, new DateTime(2009, 8, 1, 0, 0, 0).ToString()));
            dest.AnDateTime.should_be_equal_to(new DateTime(2009, 8, 1, 0, 0, 0));
        }
Example #3
0
        public void it_can_map_numeric_to_string()
        {
            var context    = Contextualize(new SimpleIntToStringConverter());
            var assignment = context.BuildValueAssignment(MappableProperty.For <Destination>(d => d.AnInt));

            assignment.SetValue(new Result(true, 3));
            dest.AnInt.should_be_equal_to("3");
        }
Example #4
0
        public void it_can_map_unsigned_values_to_their_signed_equivalent()
        {
            var  context    = Contextualize(new SystemConverter());
            var  assignment = context.BuildValueAssignment(MappableProperty.For <Destination>(d => d.Int));
            uint unsigned   = 42;

            assignment.SetValue(new Result(true, unsigned));
            dest.Int.should_be_equal_to(42);
        }
Example #5
0
        public void it_can_map_nonnullable_to_nullable_types()
        {
            var context    = Contextualize(new NonNullableToNullableConverter());
            var assignment = context.BuildValueAssignment(MappableProperty.For <Destination>(d => d.NInt));
            int iint       = 4;

            assignment.SetValue(new Result(true, iint));
            dest.NInt.should_be_equal_to(4);
        }
Example #6
0
        public void it_can_map_nullable_double_to_nonnullable_types_with_default_value()
        {
            var    context    = Contextualize(new NullableToNonNullableConverter());
            var    assignment = context.BuildValueAssignment(MappableProperty.For <Destination>(d => d.Double));
            double?ndouble    = null;

            assignment.SetValue(new Result(true, ndouble));
            dest.Double.should_be_equal_to(0);
        }
Example #7
0
        public void it_should_get_destination_property_for_underlying_element()
        {
            var dest = MappableProperty.For <DestinationWithComponentArray>(d => d.IntegerComponents);

            dest.PropertyType.should_be_equal_to(typeof(IntegerDest[]));
            var el = dest.ElementAt(2);

            el.PropertyType.should_be_equal_to(typeof(IntegerDest));
            el.Index.should_be_equal_to(2);
        }
Example #8
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);
        }