Exemplo n.º 1
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.º 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));
        }
Exemplo n.º 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");
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 8
0
        private void UseImmutableResolver(string name,LotsOTypes destination,ImmutableDestinationResolver resolver,Action<Result> assert)
        {
            var source = new LotsOTypes()
            {
                AGuid = Guid.NewGuid(),
                AInt = 5,
                ANguid = Guid.NewGuid(),
                ANint = 9,
                AReferenceType = new TestClass(){Name = "monster"},
                AString = "x3"
            };

            var context = contextualizer.CreateContext(source, destination);
            var destProp= new MappableProperty(typeof (LotsOTypes).GetProperty(name));
            var result = resolver.TryResolve(context,destProp);
            assert(result);
        }
Exemplo n.º 9
0
        private void UseImmutableResolver(string name, LotsOTypes destination, ImmutableDestinationResolver resolver, Action <Result> assert)
        {
            var source = new LotsOTypes()
            {
                AGuid          = Guid.NewGuid(),
                AInt           = 5,
                ANguid         = Guid.NewGuid(),
                ANint          = 9,
                AReferenceType = new TestClass()
                {
                    Name = "monster"
                },
                AString = "x3"
            };

            var context  = contextualizer.CreateContext(source, destination);
            var destProp = new MappableProperty(typeof(LotsOTypes).GetProperty(name));
            var result   = resolver.TryResolve(context, destProp);

            assert(result);
        }
Exemplo n.º 10
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);
        }