Ejemplo n.º 1
0
 public async Task <ActionResult> AddItemToBasket(int id, int itemId, int count)
 {
     if (!await _storage.AddOrReplaceItemOnBasketAsync(id, itemId, count))
     {
         return(BadRequest("Item does not exist."));
     }
     return(NoContent());
 }
Ejemplo n.º 2
0
        public async Task AddItemToBasket()
        {
            var basketId = 1;
            var itemId   = 1;
            var item     = new Item {
                Id = itemId
            };
            await _storage.AddOrUpdateItemAsync(item);

            var basket = new Basket {
                Id = basketId
            };

            basket.Items.Add(itemId, new BasketItem {
                Item  = item,
                Count = 1
            });

            await _storage.AddOrReplaceBasketAsync(basket);

            basket = await _storage.GetBasketAsync(basketId);

            Assert.NotNull(basket);
            Assert.AreEqual(1, basket.Items.Count);
            Assert.AreEqual(1, basket.Items[itemId].Count);
            Assert.AreEqual(1, basket.Items[itemId].Item.Id);

            var result = await _storage.AddOrReplaceItemOnBasketAsync(basketId, itemId, 5);

            Assert.IsTrue(result);
            Assert.AreEqual(1, basket.Items.Count);
            Assert.AreEqual(5, basket.Items[itemId].Count);
            Assert.AreEqual(1, basket.Items[itemId].Item.Id);


            result = await _storage.AddOrReplaceItemOnBasketAsync(basketId, 2, 5);

            Assert.IsFalse(result);
        }