public void ComplexTestTransformation()
        {
            Mapper.CreateMap <CustomComplexType, CustomComplexTypeDto>();
            Mapper.CreateMap <User, UserDto>();

            CustomComplexType instance = new CustomComplexType
            {
                MyKeyService  = KeyService.Type2,
                ComplexNaming = "complex_naming",
                Owner         = new User
                {
                    Name    = "name1",
                    Surname = "surname1",
                    Parent  = new User
                    {
                        Name    = "parteName1",
                        Surname = "parentSurname1",
                        Parent  = new User
                        {
                            Name    = "parentParentName1",
                            Surname = "parentParentSurname1",
                            Parent  = new User()
                        }
                    }
                }
            };

            var result = Mapper.Map <CustomComplexType, CustomComplexTypeDto>(instance);

            Assert.IsNotNull(result);
        }
Exemple #2
0
        public void BuildAutoResolverMapperTest3()
        {
            TransformerObserver observer = new TransformerObserver();

            Assert.IsTrue(observer.BuildAutoResolverMapper(typeof(CustomComplexType), typeof(CustomComplexTypeDto)));
            Assert.IsTrue(observer.BuildAutoResolverMapper <User, UserDto>(null, null));
            Assert.IsTrue(observer.RegisterMapper(new SimpleMapper <KeyService, KeyServiceOther>(service => (KeyServiceOther)Enum.ToObject(typeof(KeyServiceOther), service))));

            CustomComplexType instance = new CustomComplexType
            {
                MyKeyService  = KeyService.Type2,
                ComplexNaming = "complex_naming",
                Owner         = new User
                {
                    Name    = "name1",
                    Surname = "surname1",
                    Parent  = new User
                    {
                        Name    = "parteName1",
                        Surname = "parentSurname1",
                        Parent  = new User
                        {
                            Name    = "parentParentName1",
                            Surname = "parentParentSurname1",
                            Parent  = new User()
                        }
                    }
                }
            };

            var res = observer.TryToMap <CustomComplexType, CustomComplexTypeDto>(instance);

            Assert.IsNotNull(res);
            Assert.AreEqual(res.MyKeyService, KeyServiceOther.Type2);
            Assert.AreEqual(res.ComplexNaming, instance.ComplexNaming);
            Assert.IsNotNull(res.Owner);

            var res1 = observer.TryToMap(instance, typeof(CustomComplexTypeDto)) as CustomComplexTypeDto;

            Assert.IsNotNull(res1);
            Assert.AreEqual(res1.MyKeyService, KeyServiceOther.Type2);
            Assert.AreEqual(res1.ComplexNaming, instance.ComplexNaming);
            Assert.IsNotNull(res1.Owner);

            var res2 = observer.TryToMap(KeyService.Type1, null);

            Assert.IsNull(res2);
        }