Exemplo n.º 1
0
        public void Test_Strongly_typed_Mapper_for_Poco_to_Dto()
        {
            const string cOrderDescription = "Hello";
            const int cOrderId = 88;

            DateTime cOrderDate = new DateTime(1976, 11, 05);

            // Arrange
            var mouse = new Product { ProductId = 1, ProductName = "Mouse" };
            var keyboard = new Product { ProductId = 2, ProductName = "Keyboard" };

            var country = new Country { CountryId = 1, CountryName = "Philippines" };
            var customer = new Customer { Country = country, CustomerName = "Michael" };

            Order oPoco = new Order { OrderId = 88, Customer = customer, OrderDescription = cOrderDescription, OrderDate = cOrderDate };
            oPoco.OrderLines = new List<OrderLine>
            {
                new OrderLine { Order = oPoco, Product = mouse, Quantity = 7, Price = 6, Amount = 42, Freebie = keyboard },
                new OrderLine { Order = oPoco, Product = keyboard, Quantity = 2, Price = 3, Amount = 6 },
                new OrderLine { Order = oPoco, Product = mouse, Quantity = 5, Price = 10, Amount = 50 },
            };

            oPoco.OrderLines[1].Comments = new List<Comment>
            {
                new Comment { OrderLine = oPoco.OrderLines[1], TheComment = "Nice" },
                new Comment { OrderLine = oPoco.OrderLines[1], TheComment = "Great" },
            };

            // Act

            /*
            var x = new OrderLineMapping();
            var odto = new OrderMapping().ToDto(o);
            */
            OrderDto oDto = Mapper.ToDto<Order,OrderDto>(oPoco);

            // Assert

            // Assert.AreEqual(cOrderDescription, odto.ZOrderDescription);
            Assert.AreEqual(cOrderDate, oDto.DummyDate);
            Assert.AreEqual(cOrderId, oDto.OrderId);

            // Assert.AreEqual(o.OrderDescription, odto.CustomerName);
            Assert.AreEqual(oPoco.Customer.CustomerName, oDto.CustomerName);

            Assert.AreEqual(oPoco.Customer.Address1, oDto.Address1);

            Assert.IsNotNull(oDto.OrderLines);

            Assert.AreNotSame(oPoco.OrderLines, oDto.OrderLines);
            Assert.AreEqual(oPoco.OrderLines.Count, oDto.OrderLines.Count);

            Assert.AreEqual(oPoco.OrderLines[0].Product.ProductId, oDto.OrderLines[0].ProductoId);
            Assert.AreEqual(oPoco.OrderLines[0].Product.ProductDescription, oDto.OrderLines[0].ProductDescription);
            Assert.AreEqual(oPoco.OrderLines[0].Freebie.ProductId, oDto.OrderLines[0].FreebieId);
            Assert.AreEqual(oPoco.OrderLines[0].Quantity, oDto.OrderLines[0].Quantity);
            Assert.AreEqual(oPoco.OrderLines[0].Amount, oDto.OrderLines[0].Amount);

            Assert.AreNotSame(oPoco.OrderLines[1].Comments, oDto.OrderLines[1].Koments);
            Assert.IsNotNull(oDto.OrderLines[1].Koments);
            Assert.AreEqual(oPoco.OrderLines[1].Comments.Count, oDto.OrderLines[1].Koments.Count);
            Assert.AreEqual(oPoco.OrderLines[1].Comments[0].TheComment, oDto.OrderLines[1].Koments[0].TheComment);
        }
Exemplo n.º 2
0
        public void Test_Poco_To_Dto()
        {
            const string cOrderDescription = "Hello";
            const int cOrderId = 88;

            DateTime cOrderDate = new DateTime(1976, 11, 05);

            // Arrange
            var mouse = new Product { ProductId = 1, ProductName = "Mouse" };
            var keyboard = new Product { ProductId = 2, ProductName = "Keyboard" };

            Order o = new Order { OrderId = 88, OrderDescription = cOrderDescription, OrderDate = cOrderDate };
            o.OrderLines = new List<OrderLine>
            {
                new OrderLine { Order = o, Product = mouse, Quantity = 7, Price = 6, Amount = 42, Freebie = keyboard },
                new OrderLine { Order = o, Product = keyboard, Quantity = 2, Price = 3, Amount = 6 },
                new OrderLine { Order = o, Product = mouse, Quantity = 5, Price = 10, Amount = 50 },
            };

            o.OrderLines[1].Comments = new List<Comment>
            {
                new Comment { OrderLine = o.OrderLines[1], TheComment = "Nice" },
                new Comment { OrderLine = o.OrderLines[1], TheComment = "Great" },
            };

            // Act
            OrderDto odto = Mapper.ToDto<Order, OrderDto>(o);

            // Assert

            Assert.AreEqual(cOrderDescription, odto.OrderDescription);
            Assert.AreEqual(cOrderDate, odto.DummyDate);
            Assert.AreEqual(cOrderId, odto.OrderId);

            Assert.IsNotNull(odto.OrderLines);
            Assert.AreEqual(o.OrderLines.Count, odto.OrderLines.Count);

            Assert.AreEqual(o.OrderLines[0].Product.ProductId, odto.OrderLines[0].ProductoId);
            Assert.AreEqual(o.OrderLines[0].Product.ProductDescription, odto.OrderLines[0].ProductDescription);
            Assert.AreEqual(o.OrderLines[0].Freebie.ProductId, odto.OrderLines[0].FreebieId);
            Assert.AreEqual(o.OrderLines[0].Quantity, odto.OrderLines[0].Quantity);
            Assert.AreEqual(o.OrderLines[0].Amount, odto.OrderLines[0].Amount);

            Assert.IsNotNull(odto.OrderLines[1].Koments);
            Assert.AreEqual(o.OrderLines[1].Comments.Count, odto.OrderLines[1].Koments.Count);
            Assert.AreEqual(o.OrderLines[1].Comments[0].TheComment, odto.OrderLines[1].Koments[0].TheComment);
        }