Exemple #1
0
        public void ShouldMapOnToASetMethod()
        {
            var source = new PublicGetMethod <double>(5643723);
            var target = new PublicSetMethod <double>();

            Mapper.Map(source).OnTo(target);

            target.Value.ShouldBe(source.GetValue());
        }
Exemple #2
0
        public void ShouldCreateAMemberDerivedTargetFromADerivedSourceMember()
        {
            using (var mapper = Mapper.CreateNew())
            {
                var source = new PublicProperty <Person> {
                    Value = new Customer()
                };
                var target = new PublicSetMethod <PersonViewModel>();
                var result = mapper.Map(source).OnTo(target);

                result.Value.ShouldBeOfType <CustomerViewModel>();
            }
        }
Exemple #3
0
        public void ShouldUseAConfiguredFactoryWithAComplexTypeMemberBinding()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .InstancesOf <PublicCtor <Address> >()
                .CreateUsing(ctx => new PublicCtor <Address>(new Address())
                {
                    Value = { Line2 = "Some Street" }
                });

                var source = new PublicField <PersonViewModel> {
                    Value = new PersonViewModel()
                };
                var target = new PublicSetMethod <PublicCtor <Address> >();
                var result = mapper.Map(source).OnTo(target);

                result.Value.ShouldNotBeNull();
                result.Value.Value.ShouldNotBeNull();
                result.Value.Value.Line2.ShouldBe("Some Street");
            }
        }
Exemple #4
0
        public void ShouldCreateADerivedTypeInAMemberEnumerableUsingRuntimeTypes()
        {
            using (var mapper = Mapper.CreateNew())
            {
                var source = new PublicProperty <object>
                {
                    Value = new Collection <object>
                    {
                        new CustomerViewModel {
                            Name = "Fred"
                        },
                        new PersonViewModel {
                            Name = "Bob"
                        }
                    }
                };
                var target = new PublicSetMethod <IEnumerable <Person> >();
                var result = mapper.Map(source).OnTo(target);

                result.Value.First().ShouldBeOfType <Customer>();
                result.Value.Second().ShouldBeOfType <Person>();
            }
        }