public void PlaceOrderDoesNotReturnNull()
        {
            // Arrange

            var order = GetOrderFrom("1234", "4321");

            AllProductsAreInStock();
            _orderFulfillmentService.Fulfill(order).Returns(_orderConfirmation);

            // Act
            var result = _subject.PlaceOrder(order);

            // Assert
            Assert.That(result, Is.Not.Null);
        }
        public OrderSummary PlaceOrder(Order order)
        {
            ValidateOrder(order);

            var confirmation = _orderFulfillmentService.Fulfill(order);

            var customer = _customerRepository.Get(confirmation.CustomerId);

            var taxes = _taxRateService.GetTaxEntries(customer.PostalCode, customer.Country);

            var netTotal = order.OrderItems.Sum(c => c.Quantity * c.Product.Price);

            var orderSummary = new OrderSummary
            {
                CustomerId  = confirmation.CustomerId,
                OrderNumber = confirmation.OrderNumber,
                OrderId     = confirmation.OrderId,
                NetTotal    = netTotal,
                Taxes       = taxes,
            };

            _emailService.SendOrderConfirmationEmail(orderSummary.CustomerId, orderSummary.OrderId);

            return(orderSummary);
        }
        public OrderSummary PlaceOrder(Order order)
        {
            ValidateOrder(order);

            var orderConfirmation = _orderFulfillmentService.Fulfill(order);

            var customer = _customerRepository.Get(order.CustomerId.Value);

            var netTotal = CalculateNetTotal(order);

            var taxRate = _taxRateService.GetTaxEntries(customer.PostalCode, customer.Country)
                          .FirstOrDefault(rate => rate.Description == "Default");

            _emailService.SendOrderConfirmationEmail(orderConfirmation.CustomerId, orderConfirmation.OrderId);

            var orderSummary = new OrderSummary
            {
                OrderNumber = orderConfirmation.OrderNumber,
                OrderId     = orderConfirmation.OrderId,
                CustomerId  = orderConfirmation.CustomerId,
                Taxes       = _taxRateService.GetTaxEntries(customer.PostalCode, customer.Country),
                NetTotal    = netTotal,
                Total       = netTotal * (1 + taxRate.Rate)
            };

            return(orderSummary);
        }
        public OrderSummary PlaceOrder(Order order)
        {
            CheckIfOrderIsValid(order);

            var confirmation = _orderFulfillmentService.Fulfill(order);

            var customer = _customerRepository.Get(_customerId);

            var taxList = _taxRateService.GetTaxEntries(customer.PostalCode, customer.Country);

            var netTotal = order.OrderItems.Sum(orderItem => orderItem.Quantity * orderItem.Product.Price);

            var taxEntries = taxList as IList <TaxEntry> ?? taxList.ToList();

            var total = taxEntries.Sum(taxEntry => netTotal * taxEntry.Rate);

            _emailService.SendOrderConfirmationEmail(_customerId, confirmation.OrderId);

            return(new OrderSummary()
            {
                CustomerId = _customerId,
                OrderNumber = confirmation.OrderNumber,
                OrderId = confirmation.OrderId,
                OrderItems = order.OrderItems,
                NetTotal = netTotal,
                Taxes = taxEntries,
                Total = total,
                EstimatedDeliveryDate = DateTime.Now.AddDays(7).Date
            });
        }
Пример #5
0
        public OrderSummary PlaceOrder(Order order)
        {
            if (order.OrderItemsAreUnique() == false)
            {
                throw new OrderItemsAreNotUniqueException();
            }

            if (ProductsAreInStock(order, _productRepository) == false)
            {
                throw new OrderItemsAreNotInStockException();
            }

            OrderConfirmation      orderConfirmation = _orderFulfillmentService.Fulfill(order);
            IEnumerable <TaxEntry> taxEntries        = _taxRateService.GetTaxEntries(_postalCode, _country);

            decimal netTotal   = order.GetOrderTotal();
            decimal orderTotal = netTotal + GetTotalTax(taxEntries);

            OrderSummary orderSummary = new OrderSummary
            {
                OrderId     = orderConfirmation.OrderId,
                OrderNumber = orderConfirmation.OrderNumber,
                CustomerId  = orderConfirmation.CustomerId,
                OrderItems  = order.OrderItems,
                NetTotal    = netTotal,
                Taxes       = taxEntries,
                Total       = orderTotal
            };

            _emailService.SendOrderConfirmationEmail(orderConfirmation.CustomerId, orderConfirmation.OrderId);

            return(orderSummary);
        }
Пример #6
0
        public OrderSummary PlaceOrder(Order order)
        {
            ValidateOrder(order);

            var fulfillment = _orderFulfillmentService.Fulfill(order);

            var customer = _customerRepository.Get(order.CustomerId);

            var netTotal = CalculateNetTotal(order);

            var listOfTaxEntries = CreateListOfTaxEntries(customer);

            var orderTotal = CalculateOrderTotal(listOfTaxEntries, netTotal);

            var orderSummary = new OrderSummary()
            {
                OrderNumber = fulfillment.OrderNumber,
                OrderId     = fulfillment.OrderId,
                Taxes       = listOfTaxEntries,
                NetTotal    = netTotal,
                Total       = orderTotal
            };

            SendConfirmationEmail(order, orderSummary);

            return(orderSummary);
        }
Пример #7
0
        // probably dont want to use something like this
        private Order ValidOrderSetup()
        {
            _customerRepository.Get(Arg.Any <int>())
            .Returns(CreateCustomer(PostalCode, Country));

            _productRepository.IsInStock(Arg.Any <string>()).Returns(true);

            _orderFulfillmentService.Fulfill(Arg.Any <Order>())
            .Returns(new OrderConfirmation()
            {
                OrderNumber = "orderNum1", OrderId = 123, CustomerId = 30
            });

            _taxRateService.GetTaxEntries(Arg.Any <string>(), Arg.Any <string>()).Returns(CreateTaxEntryList());
            return(CreateValidOrder());
        }
        public OrderSummary PlaceOrder(Order order)
        {
            // Check duplicate SKU
            if (order.HasNoDuplicateSku() == false)
            {
                throw new ArgumentException(DuplicateSkuError);
            }

            // Get customer information
            int customerId = order.CustomerId ?? -1;

            if (customerId == -1)
            {
                throw new ArgumentException(NoCustomerIdError);
            }
            Customer customer = _customerService.Get(customerId);

            // Get tax rate
            IEnumerable <TaxEntry> tax = _taxService.GetTaxEntries(customer.PostalCode, customer.Country);
            decimal totalTax           = 0;

            foreach (TaxEntry entry in tax)
            {
                totalTax += entry.Rate;
            }

            // Check product stock and calculate totals
            decimal netTotal = 0;
            decimal total    = 0;

            foreach (OrderItem items in order.OrderItems)
            {
                if (_productRepo.IsInStock(items.Product.Sku) == false)
                {
                    throw new ArgumentException(NoStockError);
                }

                netTotal += items.Product.Price * items.Quantity;
            }
            total = totalTax / 100 * netTotal;

            // All checks pass, get confirmation properties
            OrderConfirmation confirmation = _fulfillmentService.Fulfill(order);

            // Create new summary with required information filled in
            OrderSummary summary = new OrderSummary
            {
                OrderId     = confirmation.OrderId,
                OrderNumber = confirmation.OrderNumber,
                NetTotal    = netTotal,
                Total       = total
            };

            _emailService.SendOrderConfirmationEmail(customerId, summary.OrderId);

            return(summary);
        }
 public static void SetOrderFullfillmentReturn(this IOrderFulfillmentService orderFulfillment,
                                               Order order)
 {
     orderFulfillment.Fulfill(order).Returns(new OrderConfirmation
     {
         CustomerId  = 1,
         OrderId     = 2,
         OrderNumber = "1337"
     });
 }
Пример #10
0
        public OrderSummary PlaceOrder(Order order)
        {
            var orderItems   = order.OrderItems;
            var orderSummary = new OrderSummary();

            if (AreOrderItemsUnique(orderItems) && AllOrderItemsInStock(orderItems))
            {
                var confirmation = _orderFulfillmentService.Fulfill(order);

                var customer = _customerRepository.Get((int)order.CustomerId);
                if (customer == null)
                {
                    throw new Exception("customer does not exist");
                }

                var taxEntries = _taxRateService.GetTaxEntries(customer.PostalCode, customer.Country);
                var taxrate    = TotalTaxRate(taxEntries);
                var netTotal   = NetTotal(orderItems);
                var ordertotal = OrderTotal(netTotal, taxrate);


                orderSummary = new OrderSummary
                {
                    OrderId     = confirmation.OrderId,
                    CustomerId  = (int)customer.CustomerId,
                    OrderNumber = confirmation.OrderNumber,
                    OrderItems  = orderItems,
                    NetTotal    = netTotal,
                    Total       = ordertotal,
                    Taxes       = taxEntries
                };

                _emailService.SendOrderConfirmationEmail((int)customer.CustomerId, confirmation.OrderId);
            }
            else if (AllOrderItemsInStock(orderItems))
            {
                throw new SKUsNotUniqueException();
            }
            else if (AreOrderItemsUnique(orderItems))
            {
                throw new ProductsNotInStockException();
            }
            else
            {
                throw new SKUsNotUniqueAndProductNotInStockException();
            }


            return(orderSummary);
        }
Пример #11
0
        public OrderSummary PlaceOrder(Order order)
        {
            decimal orderNetTotal = 0.0M;

            foreach (var orderItem in order.OrderItems)
            {
                bool check = _productRepository.IsInStock("laptop");
                if (!_productRepository.IsInStock("laptop"))
                {
                    ExceptionReasons.Add("There is not enough stock available for the product " + orderItem.Product.Sku + " to complete the order");
                }
                orderNetTotal += orderItem.Product.Price * orderItem.Quantity;
            }

            var customer = _customerRepository.Get((int)order.CustomerId);

            if (customer == null)
            {
                ExceptionReasons.Add("Customer not found");
                throw new OrderPlacementValidationException(ExceptionReasons);
            }

            var taxEntryList = _taxRateService.GetTaxEntries(customer.PostalCode, customer.Country);

            if (taxEntryList == null)
            {
                ExceptionReasons.Add("Tax Entry for the specified Postal Code: " + customer.PostalCode + " and Country: " + customer.Country + " was invalid");
                throw new OrderPlacementValidationException(ExceptionReasons);
            }

            var total = taxEntryList.Sum(t => t.Rate * orderNetTotal);

            var orderConf = _orderFulfillmentService.Fulfill(order);

            var orderSummary = new OrderSummary
            {
                CustomerId            = orderConf.CustomerId,
                EstimatedDeliveryDate = DateTime.Now,
                NetTotal    = orderNetTotal,
                OrderId     = orderConf.OrderId,
                OrderItems  = order.OrderItems,
                OrderNumber = orderConf.OrderNumber,
                Total       = total,
                Taxes       = taxEntryList
            };

            _emailService.SendOrderConfirmationEmail(orderSummary.CustomerId, orderSummary.OrderId);

            return(orderSummary);
        }
        private Order GenerateValidOneProductOrder()
        {
            var product = new Product()
            {
                Name        = "Test Product",
                Description = "A test Product",
                Price       = 10,
                ProductId   = 1,
                Sku         = "TestSKU"
            };
            var order = GenerateOrderFromProducts(new[] { product });

            _productRepository.IsInStock(product.Sku).Returns(true);
            _orderFulfillmentService.Fulfill(order).Returns(_orderConfirmation);

            return(order);
        }
Пример #13
0
        private OrderSummary GetOrderSummary(Order order)
        {
            var customer = GetCustomerFromId(_customerRepository, order.CustomerId);
            var taxes    = GetTaxes(_taxRateService, customer);

            var netTotal = GetNetTotal(order.OrderItems);
            var total    = GetTotal(taxes, netTotal);

            var orderConfirmation = _orderFulfillment.Fulfill(order);

            SendConfirmationEmail(_emailService, orderConfirmation);

            return(new OrderSummary()
            {
                OrderId = orderConfirmation.OrderId,
                OrderNumber = orderConfirmation.OrderNumber,
                CustomerId = orderConfirmation.CustomerId,
                Taxes = taxes,
                NetTotal = netTotal,
                Total = total,
                OrderItems = order.OrderItems,
                EstimatedDeliveryDate = DateTime.Today.AddDays(7)
            });
        }