Example #1
0
      /// <summary>
      ///    Create a new order
      /// </summary>
      /// <param name="customer">Associated customer</param>
      /// <param name="shippingName">The order shipping name</param>
      /// <param name="shippingCity">The order shipping city</param>
      /// <param name="shippingAddress">The order shipping address</param>
      /// <param name="shippingZipCode">The order shipping zip cocde</param>
      /// <returns>Associated order</returns>
      public static Order CreateOrder(
         Customer customer,
         string shippingName,
         string shippingCity,
         string shippingAddress,
         string shippingZipCode)
      {
         //create the order
         var order = new Order();

         //create shipping
         var shipping = new ShippingInfo(shippingName, shippingAddress, shippingCity, shippingZipCode);

         //set default values
         order.OrderDate = DateTime.UtcNow;

         order.DeliveryDate = null;

         order.ShippingInformation = shipping;

         //set customer information
         order.SetTheCustomerForThisOrder(customer);

         //set identity
         order.GenerateNewIdentity();

         return order;
      }
Example #2
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);

      }
Example #3
0
      public void OrderCannotSetNullCustomer()
      {
         //Arrange 
         var customer = new Customer();

         var order = new Order();

         //Act
         order.SetTheCustomerForThisOrder(customer);
      }
        public void OrderCannotSetTransientCustomer()
        {
            //Arrange 
            Customer customer = new Customer();

            Order order = new Order();

            //Act
            order.SetTheCustomerForThisOrder(customer);
        }
Example #5
0
      public void OrderSetDeliveredSetDateAndState()
      {
         //Arrange 
         var order = new Order();

         //Act
         order.SetOrderAsDelivered();

         //Assert
         Assert.IsTrue(order.IsDelivered);
         Assert.IsNotNull(order.DeliveryDate);
         Assert.IsTrue(order.DeliveryDate != default(DateTime));
      }
        /// <summary>
        /// Create a new order
        /// </summary>
        /// <param name="customerId">Associated customer identifier</param>
        /// <param name="shippingName">The order shipping name</param>
        /// <param name="shippingCity">The order shipping city</param>
        /// <param name="shippingAddress">The order shipping address</param>
        /// <param name="shippingZipCode">The order shipping zip cocde</param>
        /// <returns>Associated order</returns>
        public static Order CreateOrder(Guid customerId, string shippingName, string shippingCity, string shippingAddress, string shippingZipCode)
        {
            //create the order
            var order = new Order();

            //create shipping
            var shipping = new ShippingInfo(shippingName, shippingAddress, shippingCity, shippingZipCode);

            //set default values
            order.OrderDate = DateTime.UtcNow;
            order.DeliveryDate = null;
            order.ShippingInformation = shipping;
            order.CustomerId = customerId;

            return order;
        }
        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);
        }
        void SaveOrder(Order order)
        {
            var entityValidator = EntityValidatorFactory.CreateValidator();

            if (entityValidator.IsValid(order))//if entity is valid save. 
            {
                //add order and commit changes
                _orderRepository.Add(order);
                _orderRepository.UnitOfWork.Commit();
            }
            else // if not valid throw validation errors
                throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(order));
        }
Example #9
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 OrderCannotSetNullCustomer()
        {
            //Arrange
            Customer customer = new Customer();

            Order order = new Order();

            //Act
            order.SetCustomer(customer);
        }
      public void FindOrdersInDateRangeMaterializeResults()
      {
         //Arrange

         var customerRepository = new StubICustomerRepository();
         var productRepository = new StubIProductRepository();
         var orderRepository = new StubIOrderRepository();

         orderRepository.AllMatchingISpecificationOfOrder = (spec) =>
         {
            var order = new Order();
            order.GenerateNewIdentity();
            order.SetTheCustomerReferenceForThisOrder(Guid.NewGuid());

            return new List<Order>()
            {
               order
            };
         };

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

         //act
         var result = salesManagement.FindOrders(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(-1));

         //Assert

         Assert.IsNotNull(result);
         Assert.IsTrue(result.Any());

      }
      private IEnumerable<Order> FindOrdersInPageMaterializeResults(
         int index,
         int count,
         Expression<Func<Order, DateTime>> order,
         bool ascending)
      {
         var item = new Order();
         item.GenerateNewIdentity();
         item.SetTheCustomerReferenceForThisOrder(Guid.NewGuid());

         return new List<Order>()
         {
            item
         };
      }
        public void FindOrdersInPageMaterializeResults()
        {
            //Arrange
            
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            orderRepository.GetPagedInt32Int32ExpressionOfFuncOfOrderKPropertyBoolean<DateTime>((index, count, order, ascending) =>
            {
                var item = new Order();
                item.GenerateNewIdentity();
                item.SetTheCustomerReferenceForThisOrder(Guid.NewGuid());

                return new List<Order>()
                {
                    item
                };
            });
            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(0, 1);

            //Assert

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());

        }
        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);
        }