Example #1
0
        public void BasicTest()
        {
            var customer = GetCustomer();
            var res = new CustomerInput();

            res.InjectFrom<FlatLoopInjection>(customer);
            res.InjectFrom<UnflatLoopInjection>(customer);
        }
Example #2
0
        public void ShouldMapWithNewAddedMap()
        {
            var customer = GetCustomer();
            Mapper.AddMap<Customer, CustomerInput>((src, tag) =>
            {
                var res = new CustomerInput();
                return res;
            });

            Mapper.AddMap<Customer, CustomerInput>(src =>
            {
                var res = new CustomerInput();
                res.Id = src.Id;
                res.FirstName = src.FirstName;
                res.LastName = src.LastName;
                return res;
            });

            var c1 = Mapper.Map<Customer, CustomerInput>(customer);
            var c2 = Mapper.Map<CustomerInput>(customer);

            c1.InjectFrom<AreEqual>(c2);

            Assert.AreEqual(customer.Id, c1.Id);
            Assert.AreEqual(customer.FirstName, c1.FirstName);
            Assert.AreEqual(customer.LastName, c1.LastName);
        }
Example #3
0
        public void PerformanceCheck()
        {
            const int Iterations = 10000;
            var customer = GetCustomer();

            Mapper.AddMap<Customer, CustomerInput>(src =>
                {
                    var res = new CustomerInput();
                    res.InjectFrom(src);

                    //res.RegDate = src.RegDate.ToShortDateString();
                    //res.RegDate = src.RegDate.tos;
                    //res.FirstName = src.FirstName;
                    //res.LastName = src.LastName;
                    //res.Id = src.Id;
                    return res;
                });

            var w = new Stopwatch();

            w.Start();
            var customerInput = Mapper.Map<CustomerInput>(customer);
            w.Stop();

            Console.WriteLine("{0} one", w.Elapsed);

            w.Reset();
            w.Start();
            for (var i = 0; i < Iterations; i++)
            {
                Mapper.Map<Customer, CustomerInput>(customer);
            }
            w.Stop();
            Console.WriteLine("{0} <T,T>", w.Elapsed);

            w.Reset();
            w.Start();
            for (var i = 0; i < Iterations; i++)
            {
                Mapper.Map<CustomerInput>(customer);
            }
            w.Stop();
            Console.WriteLine("{0} loop", w.Elapsed);

            w.Reset();
            w.Start();
            Mapper.Map<CustomerInput>(customer);
            w.Stop();

            Console.WriteLine("{0} one", w.Elapsed);

            w.Reset();
            w.Start();
            for (int i = 0; i < Iterations; i++)
            {
                var cc = new Customer();
                cc.RegDate = customer.RegDate;
                cc.FirstName = customer.FirstName;
                cc.LastName = customer.LastName;
                cc.Id = customer.Id;
            }
            w.Stop();
            Console.WriteLine("{0} manual", w.Elapsed);
        }
Example #4
0
        public void ShouldMapProxy()
        {
            var customerProxy = new CustomerProxy { FirstName = "c1", ProxyName = "proxy1", RegDate = DateTime.Now };

            Mapper.AddMap<Customer, CustomerInput>(src =>
                {
                    var res = new CustomerInput();
                    res.InjectFrom(src);
                    res.RegDate = src.RegDate.ToShortDateString();
                    return res;
                });

            var input = Mapper.Map<Customer, CustomerInput>(customerProxy);

            Assert.AreEqual(customerProxy.RegDate.ToShortDateString(), input.RegDate);
            Assert.AreEqual(customerProxy.FirstName, input.FirstName);
        }