コード例 #1
0
      public void OrderToOrderDtoAdapter()
      {
         //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 orderLine = order.AddNewOrderLine(product.Id, 10, 10, 0.5M);
         orderLine.SetProduct(product);

         //Act
         var adapter = TypeAdapterFactory.CreateAdapter();
         var orderDto = adapter.Adapt<Order, OrderDto>(order);

         //Assert
         Assert.AreEqual(orderDto.Id, order.Id);
         Assert.AreEqual(orderDto.OrderDate, order.OrderDate);
         Assert.AreEqual(orderDto.DeliveryDate, order.DeliveryDate);

         Assert.AreEqual(orderDto.ShippingAddress, order.ShippingInformation.ShippingAddress);
         Assert.AreEqual(orderDto.ShippingCity, order.ShippingInformation.ShippingCity);
         Assert.AreEqual(orderDto.ShippingName, order.ShippingInformation.ShippingName);
         Assert.AreEqual(orderDto.ShippingZipCode, order.ShippingInformation.ShippingZipCode);

         Assert.AreEqual(orderDto.CustomerFullName, order.Customer.FullName);
         Assert.AreEqual(orderDto.CustomerId, order.Customer.Id);

         Assert.AreEqual(
            orderDto.OrderNumber,
            string.Format("{0}/{1}-{2}", order.OrderDate.Year, order.OrderDate.Month, order.SequenceNumberOrder));

         Assert.IsNotNull(orderDto.OrderLines);
         Assert.IsTrue(orderDto.OrderLines.Any());

         Assert.AreEqual(orderDto.OrderLines[0].Id, orderLine.Id);
         Assert.AreEqual(orderDto.OrderLines[0].Amount, orderLine.Amount);
         Assert.AreEqual(orderDto.OrderLines[0].Discount, orderLine.Discount * 100);
         Assert.AreEqual(orderDto.OrderLines[0].UnitPrice, orderLine.UnitPrice);
         Assert.AreEqual(orderDto.OrderLines[0].TotalLine, orderLine.TotalLine);
         Assert.AreEqual(orderDto.OrderLines[0].ProductId, product.Id);
         Assert.AreEqual(orderDto.OrderLines[0].ProductTitle, product.Title);

      }
コード例 #2
0
        public void ProductToProductDTOAdapter()
        {
            //Arrange
            var product = new Software("the title", "The description","AB001");
            product.ChangeUnitPrice(10);
            product.IncrementStock(10);
            product.GenerateNewIdentity();

            //Act
            ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter();
            var productDTO = adapter.Adapt<Product, ProductDTO>(product);

            //Assert
            Assert.AreEqual(product.Id, productDTO.Id);
            Assert.AreEqual(product.Title, productDTO.Title);
            Assert.AreEqual(product.Description, productDTO.Description);
            Assert.AreEqual(product.AmountInStock, productDTO.AmountInStock);
            Assert.AreEqual(product.UnitPrice, productDTO.UnitPrice);
        }
コード例 #3
0
        public void SoftwareToSoftwareDTOAdapter()
        {
            //Arrange
            var software = new Software("the title", "The description","AB001");
            software.ChangeUnitPrice(10);
            software.IncrementStock(10);
            software.GenerateNewIdentity();
            //Act
            ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter();
            var softwareDTO = adapter.Adapt<Software, SoftwareDTO>(software);

            //Assert
            Assert.AreEqual(software.Id, softwareDTO.Id);
            Assert.AreEqual(software.Title, softwareDTO.Title);
            Assert.AreEqual(software.Description, softwareDTO.Description);
            Assert.AreEqual(software.AmountInStock, softwareDTO.AmountInStock);
            Assert.AreEqual(software.UnitPrice, softwareDTO.UnitPrice);
            Assert.AreEqual(software.LicenseCode, softwareDTO.LicenseCode);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        public void EnumerableProductToListProductDTOAdapter()
        {
            //Arrange
            var software = new Software("the title", "The description","AB001");
            software.ChangeUnitPrice(10);
            software.IncrementStock(10);
            software.GenerateNewIdentity();

            var products = new List<Software>() { software };

            //Act
            ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter();
            var productsDTO = adapter.Adapt<IEnumerable<Product>, List<ProductDTO>>(products);

            //Assert
            Assert.AreEqual(products[0].Id, productsDTO[0].Id);
            Assert.AreEqual(products[0].Title, productsDTO[0].Title);
            Assert.AreEqual(products[0].Description, productsDTO[0].Description);
            Assert.AreEqual(products[0].AmountInStock, productsDTO[0].AmountInStock);
            Assert.AreEqual(products[0].UnitPrice, productsDTO[0].UnitPrice);
        }
コード例 #6
0
        public void EnumerableOrderLineToListOrderLineDTOAdapter()
        {
            //Arrange
            Product product = new Software();
            product.Id = IdentityGenerator.NewSequentialGuid();
            product.Title = "The product title";
            product.Description = "The product description";

            OrderLine orderLine = new OrderLine()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                Amount = 1,
                Discount = 0,
                UnitPrice = 10,
                ProductId = product.Id,
            };
            orderLine.SetProduct(product);

            IEnumerable<OrderLine> lines = new List<OrderLine>(){orderLine};

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            var orderLinesDTO = adapter.Adapt<IEnumerable<OrderLine>, List<OrderLineDTO>>(lines);

            //Assert
            Assert.IsNotNull(orderLinesDTO);
            Assert.IsTrue(orderLinesDTO.Any());

            Assert.AreEqual(orderLinesDTO[0].Amount, orderLine.Amount);
            Assert.AreEqual(orderLinesDTO[0].Id, orderLine.Id);
            Assert.AreEqual(orderLinesDTO[0].Discount, orderLine.Discount);
            Assert.AreEqual(orderLinesDTO[0].ProductId, orderLine.ProductId);
            Assert.AreEqual(orderLinesDTO[0].ProductTitle, orderLine.Product.Title);
            Assert.AreEqual(orderLinesDTO[0].UnitPrice, orderLine.UnitPrice);
            Assert.AreEqual(orderLinesDTO[0].TotalLine, orderLine.TotalLine);
        }
コード例 #7
0
        /// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/>
        /// </summary>
        /// <param name="softwareDTO"><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/></param>
        public SoftwareDTO AddNewSoftware(SoftwareDTO softwareDTO)
        {
            if (softwareDTO == null)
                throw new ArgumentException(Messages.warning_CannotAddSoftwareWithNullInformation);

            //Create the softare entity
            var newSoftware = new Software(softwareDTO.Title, softwareDTO.Description,softwareDTO.LicenseCode);

            //set unit price and stock
            newSoftware.ChangeUnitPrice(softwareDTO.UnitPrice);
            newSoftware.IncrementStock(softwareDTO.AmountInStock);

            //Assign the poid
            newSoftware.GenerateNewIdentity();

            //save software
            SaveProduct(newSoftware);

            //return software dto
            return newSoftware.ProjectedAs<SoftwareDTO>();
        }
コード例 #8
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);
      }
コード例 #9
0
        public void SoftwareToSoftwareDTOAdapter()
        {
            //Arrange
            Software software = new Software()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                Title = "the title",
                UnitPrice = 10,
                Description = "The description",
                AmountInStock = 10,
                LicenseCode = "AB001"
            };

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            var softwareDTO = adapter.Adapt<Software, SoftwareDTO>(software);

            //Assert
            Assert.AreEqual(software.Id, softwareDTO.Id);
            Assert.AreEqual(software.Title, softwareDTO.Title);
            Assert.AreEqual(software.Description, softwareDTO.Description);
            Assert.AreEqual(software.AmountInStock, softwareDTO.AmountInStock);
            Assert.AreEqual(software.UnitPrice, softwareDTO.UnitPrice);
            Assert.AreEqual(software.LicenseCode, softwareDTO.LicenseCode);
        }
コード例 #10
0
        public void ProductToProductDTOAdapter()
        {
            //Arrange
            Product product = new Software()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                Title ="the title",
                UnitPrice = 10,
                Description = "The description",
                AmountInStock = 10
            };

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            var productDTO = adapter.Adapt<Product, ProductDTO>(product);

            //Assert
            Assert.AreEqual(product.Id, productDTO.Id);
            Assert.AreEqual(product.Title, productDTO.Title);
            Assert.AreEqual(product.Description, productDTO.Description);
            Assert.AreEqual(product.AmountInStock, productDTO.AmountInStock);
            Assert.AreEqual(product.UnitPrice, productDTO.UnitPrice);
        }
コード例 #11
0
      public void FindProductsByFilterMaterializeResults()
      {
         //Arrange
         var customerRepository = new StubICustomerRepository();
         var productRepository = new StubIProductRepository();
         var orderRepository = new StubIOrderRepository();
         productRepository.AllMatchingISpecificationOfProduct = (spec) =>
         {
            var book = new Book("title", "description", "publisher", "isbn");
            book.ChangeUnitPrice(10);
            book.GenerateNewIdentity();

            var software = new Software("title", "description", "license code");
            software.ChangeUnitPrice(10);
            software.GenerateNewIdentity();

            return new List<Product>()
            {
               book,
               software
            };
         };

         var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

         //act
         var result = salesManagement.FindProducts("filter text");

         //Assert
         Assert.IsNotNull(result);
         Assert.IsTrue(result.Count == 2);
      }
コード例 #12
0
      public void FindProductsInPageMaterializeResults()
      {
         //Arrange
         var customerRepository = new StubICustomerRepository();
         var productRepository = new StubIProductRepository();
         var orderRepository = new StubIOrderRepository();
         //productRepository.GetPagedInt32Int32ExpressionOfFuncOfProductKPropertyBoolean<string>(
         //   (index, count, order, ascending) =>
         //   {
         //      var book = new Book("title", "description", "publisher", "isbn");
         //      book.ChangeUnitPrice(10M);
         //      book.GenerateNewIdentity();

         //      var software = new Software("title", "description", "license code");
         //      software.ChangeUnitPrice(10);
         //      software.GenerateNewIdentity();

         //      return new List<Product>()
         //      {
         //         book,
         //         software
         //      };
         //   });

         productRepository.GetPagedOf1Int32Int32ExpressionOfFuncOfProductM0Boolean<string>(
            (index, count, order, ascending) =>
            {
               var book = new Book("title", "description", "publisher", "isbn");
               book.ChangeUnitPrice(10M);
               book.GenerateNewIdentity();

               var software = new Software("title", "description", "license code");
               software.ChangeUnitPrice(10);
               software.GenerateNewIdentity();

               return new List<Product>
               {
                  book,
                  software
               };

            });

         var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

         //act
         var result = salesManagement.FindProducts(0, 2);

         //Assert
         Assert.IsNotNull(result);
         Assert.IsTrue(result.Count == 2);
      }
コード例 #13
0
        public void OrderToOrderDTOAdapter()
        {
            //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 orderLine = order.CreateOrderLine(product, 10, 10, 10);
            order.AddOrderLine(orderLine);

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            var orderDTO = adapter.Adapt<Order, OrderDTO>(order);

            //Assert
            Assert.AreEqual(orderDTO.Id, order.Id);
            Assert.AreEqual(orderDTO.OrderDate, order.OrderDate);
            Assert.AreEqual(orderDTO.DeliveryDate, order.DeliveryDate);

            Assert.AreEqual(orderDTO.ShippingAddress, order.ShippingInformation.ShippingAddress);
            Assert.AreEqual(orderDTO.ShippingCity, order.ShippingInformation.ShippingCity);
            Assert.AreEqual(orderDTO.ShippingName, order.ShippingInformation.ShippingName);
            Assert.AreEqual(orderDTO.ShippingZipCode, order.ShippingInformation.ShippingZipCode);

            Assert.AreEqual(orderDTO.CustomerFullName, order.Customer.FullName);
            Assert.AreEqual(orderDTO.CustomerId, order.Customer.Id);

            Assert.IsNotNull(orderDTO.OrderLines);
            Assert.IsTrue(orderDTO.OrderLines.Any());

            Assert.AreEqual(orderDTO.OrderLines[0].Id, orderLine.Id);
            Assert.AreEqual(orderDTO.OrderLines[0].Amount, orderLine.Amount);
            Assert.AreEqual(orderDTO.OrderLines[0].Discount, orderLine.Discount);
            Assert.AreEqual(orderDTO.OrderLines[0].UnitPrice, orderLine.UnitPrice);
            Assert.AreEqual(orderDTO.OrderLines[0].TotalLine, orderLine.TotalLine);
            Assert.AreEqual(orderDTO.OrderLines[0].ProductId, product.Id);
            Assert.AreEqual(orderDTO.OrderLines[0].ProductTitle, product.Title);
        }
コード例 #14
0
        public void OrderLineToOrderLineDTOAdapter()
        {
            //Arrange
            Product product = new Software();
            product.Id = IdentityGenerator.NewSequentialGuid();
            product.Title = "The product title";
            product.Description = "The product description";

            OrderLine orderLine = new OrderLine()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                Amount = 1,
                Discount = 0,
                UnitPrice = 10,
                ProductId = product.Id,
            };
            orderLine.SetProduct(product);

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            var orderLineDTO = adapter.Adapt<OrderLine, OrderLineDTO>(orderLine);

            //Assert
            Assert.AreEqual(orderLineDTO.Amount, orderLine.Amount);
            Assert.AreEqual(orderLineDTO.Id, orderLine.Id);
            Assert.AreEqual(orderLineDTO.Discount, orderLine.Discount);
            Assert.AreEqual(orderLineDTO.ProductId, orderLine.ProductId);
            Assert.AreEqual(orderLineDTO.ProductTitle, orderLine.Product.Title);
            Assert.AreEqual(orderLineDTO.UnitPrice, orderLine.UnitPrice);
            Assert.AreEqual(orderLineDTO.TotalLine, orderLine.TotalLine);
        }