public async Task AddItemToBasket()
        {
            var response = await _controller.AddItemToBasket(1, 1, 1);

            Assert.IsInstanceOf <BadRequestObjectResult>(response);

            await _storage.AddOrUpdateItemAsync(new Item { Id = 1 });

            var id = await _storage.InitBasketAsync();

            response = await _controller.AddItemToBasket(id, 1, 1);

            Assert.IsInstanceOf <NoContentResult>(response);
        }
        public async Task <ActionResult <ItemResponse> > Post([FromBody] ItemResponse item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (item == null)
            {
                return(BadRequest());
            }

            if (!await _storage.AddOrUpdateItemAsync(_mapper.Map <Item>(item)))
            {
                return(BadRequest());
            }

            return(Ok(item));
        }
Example #3
0
        public async Task AddItem()
        {
            var item = new Item {
                Id = 1
            };
            var result = await _storage.AddOrUpdateItemAsync(item);

            Assert.IsTrue(result);

            result = await _storage.AddOrUpdateItemAsync(null);

            Assert.IsFalse(result);

            var item2 = new Item {
                Id = 2
            };

            result = await _storage.AddOrUpdateItemAsync(item2);

            Assert.IsTrue(result);

            var items = await _storage.GetItemsAsync();

            Assert.AreEqual(2, items.Count());
        }