示例#1
0
        public void Pay_UserCreditBalanceLessThanTotalCartPrice_BadRequestObjectResult()
        {
            // Arrange
            var userId         = "userId";
            var shoppingCartId = Guid.NewGuid();
            var sut            = new StoreController(_storeItemRepository, _warehouseService, _shoppingCardRepository,
                                                     _userCreditService, _paymentService);

            var shoppingCart = new ShoppingCart(userId);

            shoppingCart.AddOrder(new Order(Guid.NewGuid(), 10, 1));
            shoppingCart.AddOrder(new Order(Guid.NewGuid(), 20, 2));
            shoppingCart.AddOrder(new Order(Guid.NewGuid(), 30, 3));

            A.CallTo(() => _shoppingCardRepository.GetShoppingCartForUser(A <string> .Ignored))
            .Returns(shoppingCart);
            A.CallTo(() => _userCreditService.GetUserCurrentBalance(A <string> .Ignored))
            .Returns(0);

            // Act
            var result = sut.Pay(userId, shoppingCartId);

            // Assert
            result.Should()
            .BeOfType <BadRequestObjectResult>();
        }
示例#2
0
        public IActionResult AddToCart(string userId, Guid storeItemId, int quantity)
        {
            if (quantity <= 0)
            {
                return(BadRequest("Quantity must be greater than 0."));
            }

            var inventoryCount = _warehouseService.GetInventoryCount(storeItemId);

            if (quantity > inventoryCount)
            {
                return(BadRequest("Warehouse doesn't have enough items in inventory - order canceled."));
            }

            var storeItem = _storeItemRepository.GetOne(storeItemId);

            var shoppingCart = new ShoppingCart(userId);
            var order        = new Order(storeItemId, storeItem.Price, quantity);

            shoppingCart.AddOrder(order);

            _shoppingCardRepository.SaveShoppingCart(shoppingCart);

            return(Ok("Order added to shopping cart!"));
        }
示例#3
0
        static void Main(string[] args)
        {
            var userId      = args[0];
            var storeItemId = Guid.Parse(args[1]);
            var quantity    = int.Parse(args[2]);

            var inventoryCount = _warehouseService.GetInventoryCount(storeItemId);

            if (quantity > inventoryCount)
            {
                throw new Exception("Warehouse doesn't have enough items in inventory - order canceled.");
            }

            var shoppingCart = new ShoppingCart(userId);
            var order        = new Order(storeItemId, quantity);

            shoppingCart.AddOrder(order);
        }