Ejemplo n.º 1
0
        public void Doit()
        {
            var c = new Customer
                        {
                            CustomerId = 3,
                            FirstName = "fn",
                            SecondName = "sn",
                            CustomerCountries =
                                new[] { new CustomerCountry { CountryId = 1 }, new CustomerCountry { CountryId = 2 } }
                        };

            var countries = new[]
                                {
                                    new Country {CountryId = 1, Name = "Moldova"},
                                    new Country {CountryId = 2, Name = "Japan"}
                                };

            var d = new CustomerDto();
            d.InjectFrom(c);
            Assert.AreEqual(c.CustomerId, d.CustomerId);
            Assert.AreEqual(c.FirstName, d.FirstName);
            Assert.AreEqual(c.SecondName, d.SecondName);

            d.InjectFrom(new My(countries), c);

            Assert.AreEqual(c.CustomerCountries.Count(), d.Countries.Count());
            Assert.AreEqual(countries.First().Name, d.Countries.First().Name);
        }
Ejemplo n.º 2
0
        public void Doit()
        {
            var c = new Customer
            {
                CustomerId        = 3,
                FirstName         = "fn",
                SecondName        = "sn",
                CustomerCountries =
                    new[] { new CustomerCountry {
                                CountryId = 1
                            }, new CustomerCountry {
                                CountryId = 2
                            } }
            };

            var countries = new[]
            {
                new Country {
                    CountryId = 1, Name = "Moldova"
                },
                new Country {
                    CountryId = 2, Name = "Japan"
                }
            };

            var d = new CustomerDto();

            d.InjectFrom(c);
            Assert.AreEqual(c.CustomerId, d.CustomerId);
            Assert.AreEqual(c.FirstName, d.FirstName);
            Assert.AreEqual(c.SecondName, d.SecondName);

            d.InjectFrom(new My(countries), c);

            Assert.AreEqual(c.CustomerCountries.Count(), d.Countries.Count());
            Assert.AreEqual(countries.First().Name, d.Countries.First().Name);
        }
Ejemplo n.º 3
0
        public static void AddCustomMappings()
        {
            Mapper.AddMap <Customer, CustomerDto>((from) =>
            {
                var target = new CustomerDto();
                target.InjectFrom(from);

                target.Name        = $"{from.FullName.Name} {from.FullName.Surname}";
                target.Email       = from.Email.Address;
                target.PhoneNumber = $"({from.PhoneNumber.AreaCode}) {from.PhoneNumber.Number}";
                target.Complement  = from.Address.Complement;
                target.Country     = from.Address.Country;
                target.District    = from.Address.District;
                target.City        = from.Address.City;
                target.Number      = from.Address.Number;
                target.State       = from.Address.State;
                target.Street      = from.Address.Street;
                target.ZipCode     = from.Address.ZipCode;

                return(target);
            });
        }