Esempio n. 1
0
      public void EnumerableOrderToOrderListDtoAdapter()
      {
         //Arrange

         var customer = new Customer();
         customer.GenerateNewIdentity();
         customer.FirstName = "Unai";
         customer.LastName = "Zorrilla";

         Product product = new Software("the product title", "the product description", "license code");
         product.GenerateNewIdentity();

         var order = new Order();
         order.GenerateNewIdentity();
         order.OrderDate = DateTime.Now;
         order.ShippingInformation = new ShippingInfo(
            "shippingName",
            "shippingAddress",
            "shippingCity",
            "shippingZipCode");
         order.SetTheCustomerForThisOrder(customer);

         var line = order.AddNewOrderLine(product.Id, 1, 200, 0);

         var orders = new List<Order>()
         {
            order
         };

         //Act
         var adapter = TypeAdapterFactory.CreateAdapter();
         var orderListDto = adapter.Adapt<IEnumerable<Order>, List<OrderListDto>>(orders);

         //Assert
         Assert.AreEqual(orderListDto[0].Id, order.Id);
         Assert.AreEqual(orderListDto[0].OrderDate, order.OrderDate);
         Assert.AreEqual(orderListDto[0].DeliveryDate, order.DeliveryDate);
         Assert.AreEqual(orderListDto[0].TotalOrder, order.GetOrderTotal());

         Assert.AreEqual(orderListDto[0].ShippingAddress, order.ShippingInformation.ShippingAddress);
         Assert.AreEqual(orderListDto[0].ShippingCity, order.ShippingInformation.ShippingCity);
         Assert.AreEqual(orderListDto[0].ShippingName, order.ShippingInformation.ShippingName);
         Assert.AreEqual(orderListDto[0].ShippingZipCode, order.ShippingInformation.ShippingZipCode);

         Assert.AreEqual(orderListDto[0].CustomerFullName, order.Customer.FullName);
         Assert.AreEqual(orderListDto[0].CustomerId, order.Customer.Id);
      }
        public void EnumerableOrderToOrderListDTOAdapter()
        {
            //Arrange

            Customer customer = new Customer();
            customer.Id = IdentityGenerator.NewSequentialGuid();
            customer.FirstName = "Unai";
            customer.LastName = "Zorrilla";

            Product product = new Software();
            product.Id = IdentityGenerator.NewSequentialGuid();
            product.Title = "the product title";
            product.Description = "the product description";

            Order order = new Order();
            order.Id = IdentityGenerator.NewSequentialGuid();
            order.OrderDate = DateTime.Now;
            order.ShippingInformation = new ShippingInfo("shippingName", "shippingAddress", "shippingCity", "shippingZipCode");
            order.SetCustomer(customer);

            var line = order.CreateOrderLine(product.Id, 1, 200, 0);
            order.AddOrderLine(line);

            var orders = new List<Order>() { order };

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            var orderListDTO = adapter.Adapt<IEnumerable<Order>, List<OrderListDTO>>(orders);

            //Assert
            Assert.AreEqual(orderListDTO[0].Id, order.Id);
            Assert.AreEqual(orderListDTO[0].OrderDate, order.OrderDate);
            Assert.AreEqual(orderListDTO[0].DeliveryDate, order.DeliveryDate);
            Assert.AreEqual(orderListDTO[0].TotalOrder, order.GetOrderTotal());

            Assert.AreEqual(orderListDTO[0].ShippingAddress, order.ShippingInformation.ShippingAddress);
            Assert.AreEqual(orderListDTO[0].ShippingCity, order.ShippingInformation.ShippingCity);
            Assert.AreEqual(orderListDTO[0].ShippingName, order.ShippingInformation.ShippingName);
            Assert.AreEqual(orderListDTO[0].ShippingZipCode, order.ShippingInformation.ShippingZipCode);

            Assert.AreEqual(orderListDTO[0].CustomerFullName, order.Customer.FullName);
            Assert.AreEqual(orderListDTO[0].CustomerId, order.Customer.Id);
        }