public void S1()
        {
            string skuId = "A,B,C";

            long activePromotionDiscount = _calculator.CalculateDiscountPercentage(skuId);

            Assert.AreEqual(100, activePromotionDiscount);
        }
        public void Return07ForFirsTimeCustomer()
        {
            var customerOrder = new Order();

            _customer = new Customer();
            _product  = new Product();

            customerOrder.Customer = _customer;
            customerOrder.Product  = _product;

            decimal discount = _calculator.CalculateDiscountPercentage(customerOrder);

            Assert.AreEqual(0.07m, discount);
        }
Exemplo n.º 3
0
        public IActionResult CalculateRebate([FromBody] OrderDto newOrder)
        {
            if (newOrder == null)
            {
                return(BadRequest());
            }

            Customer selectedCustomer = _customerRepository.GetEntity(newOrder.CustomerId);
            Product  selectedProduct  = _productRepository.GetEntity(newOrder.ProductId);

            if (selectedCustomer == null)
            {
                return(BadRequest(ModelState));
            }

            if (selectedProduct == null)
            {
                return(BadRequest(ModelState));
            }

            // Here we should use a Mapper between two similar or almost similar models. For the moment it's done by hand.
            Domain.Products.Product mappedProduct = new Domain.Products.Product()
            {
                Id     = selectedProduct.Id,
                Name   = selectedProduct.Name,
                Price  = selectedProduct.Price,
                OnSale = selectedProduct.OnSale
            };

            Domain.Customers.Customer mappedCustomer = new Domain.Customers.Customer()
            {
                Id                  = selectedProduct.Id,
                Name                = selectedProduct.Name,
                IsPremium           = selectedCustomer.IsPremium,
                DateOfFirstPurchase = selectedCustomer.DateOfFirstPurchase
            };

            Order order = new Order()
            {
                Product   = mappedProduct,
                Customer  = mappedCustomer,
                Quantity  = newOrder.Quantity,
                UnitPrice = mappedProduct.Price
            };

            var resultDiscount = _discountCalculator.CalculateDiscountPercentage(order);
            var returnedValue  = new JsonResult(resultDiscount);

            // return new JsonResult(resultDiscount)

            return(Ok(resultDiscount));
        }
        public void Return15PctForNewCustomer()
        {
            var customer = new Customer();

            decimal discount = _calculator.CalculateDiscountPercentage(customer);

            Assert.AreEqual(0.15m, discount);
        }
Exemplo n.º 5
0
        public IActionResult Discount(Customer customer)
        {
            ViewBag.DiscountPercentage = _discountCalculator.CalculateDiscountPercentage(customer);

            return(View(customer));
        }