Пример #1
0
 public bool Update(Guid orderId, [FromBody] OrderInputData inputData)
 {
     if (inputData.Quantity > 0)
     {
         return(order.UpdateOrderQuantity(orderId, inputData));
     }
     throw new Exception("Please enter the Quantity which should be greater than 0");
 }
Пример #2
0
 public bool Create([FromBody] OrderInputData inputData)
 {
     if (inputData.Quantity > 0)
     {
         return(order.AddOrder(inputData));
     }
     throw new Exception("Please enter the Quantity which should be greater than 0");
 }
Пример #3
0
        public void TestCancelExpectException()
        {
            var order = new OrderInputData()
            {
                ProductId  = Guid.Parse("4A3AF1AA-B6BC-4F2E-85F1-7620672DB1E2"),
                OrderId    = Guid.NewGuid(),
                CustomerId = Guid.Parse("fe7d6a2e-cd78-44db-8225-ebd1c1bc592f"),
                Quantity   = 10
            };

            Assert.Throws <Exception>(() => objOrderService.CancelOrder(order.OrderId));
        }
Пример #4
0
        public void TestUpdateQuantityExpectTrue()
        {
            var order = new OrderInputData()
            {
                ProductId  = Guid.Parse("4A3AF1AA-B6BC-4F2E-85F1-7620672DB1E2"),
                OrderId    = Guid.Parse("4A32FC4C-93F1-4E95-838B-16D0900339B8"),
                CustomerId = Guid.Parse("fe7d6a2e-cd78-44db-8225-ebd1c1bc592f"),
                Quantity   = 10
            };

            Assert.True(objOrderService.UpdateOrderQuantity(order.OrderId, order));
        }
Пример #5
0
        public void TestAddOrderExpectTrue()
        {
            var order = new OrderInputData()
            {
                ProductId  = Guid.Parse("4A3AF1AA-B6BC-4F2E-85F1-7620672DB1E2"),
                OrderId    = Guid.NewGuid(),
                CustomerId = Guid.Parse("fe7d6a2e-cd78-44db-8225-ebd1c1bc592f"),
                Quantity   = 10
            };

            Assert.True(objOrderService.AddOrder(order));
        }
Пример #6
0
        public void TestAddOrderExpectException()
        {
            var order = new OrderInputData()
            {
                ProductId  = Guid.Parse("95FEB320-49F1-4343-9DD3-0DB1521A4832"),
                OrderId    = Guid.NewGuid(),
                CustomerId = Guid.Parse("fe7d6a2e-cd78-44db-8225-ebd1c1bc592f"),
                Quantity   = 11
            };

            Assert.Throws <Exception>(() => objOrderService.AddOrder(order));
        }
Пример #7
0
        public bool AddOrder(OrderInputData orderInputData)
        {
            var order = new Order()
            {
                OrderId    = Guid.NewGuid(),
                ProductId  = orderInputData.ProductId,
                Quantity   = orderInputData.Quantity,
                CustomerId = _customerId
            };

            dbContext.Orders.Add(order);

            var product = dbContext.Products.Find(order.ProductId);

            if (product == null || order.Quantity > product.Quantity)
            {
                throw new Exception("Product unavailable");
            }
            product.Quantity -= order.Quantity;
            dbContext.SaveChanges();
            return(true);
        }
Пример #8
0
        public bool UpdateOrderQuantity(Guid orderId, OrderInputData orderInputData)
        {
            var isCancelled = CancelOrder(orderId);

            return(isCancelled && AddOrder(orderInputData));
        }