public async Task <T> PutAsync <T>(Uri uri, IncreaseDecreaseItemRequest increaseDecreaseItemRequest)
        {
            var content = new StringContent(JsonConvert.SerializeObject(increaseDecreaseItemRequest), Encoding.UTF8, "application/json");
            var result  = await Client.PutAsync(uri, content);

            result.EnsureSuccessStatusCode();
            return(JsonConvert.DeserializeObject <T>(await result.Content.ReadAsStringAsync()));
        }
        public IActionResult IncrementDecrement(Guid basketId, Guid itemId, IncreaseDecreaseItemRequest request)
        {
            var message = _mapper.Map <IncreaseDeacreaseItemMessage>(request);

            message.BasketId = basketId;
            message.ItemId   = itemId;
            var result = _mediator.Send <IncreaseDeacreaseItemMessage, IItem>(message);

            return(Ok(_mapper.Map <ItemResponseModel>(result)));
        }
Example #3
0
        public async Task Put_Should_Decrement_Quantity(string url)
        {
            // Arrange
            var client  = _factory.CreateClient();
            var request = new IncreaseDecreaseItemRequest {
                Quantity = -1
            };

            // Act
            var response = await client.PutAsync(url, new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"));

            // Assert
            response.StatusCode.ShouldBe(HttpStatusCode.OK);

            var responseContent = JsonConvert.DeserializeObject <ItemResponseModel>(await response.Content.ReadAsStringAsync());

            responseContent.Quantity.ShouldBe(0);
        }
Example #4
0
        public async Task Put_Should_Increment_Quantity(string url)
        {
            // Arrange
            var client  = _factory.CreateClient();
            var request = new IncreaseDecreaseItemRequest {
                Quantity = 3
            };

            // Act
            var response = await client.PutAsync(url, new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"));

            // Assert
            response.EnsureSuccessStatusCode(); // Status Code 200-299
            response.StatusCode.ShouldBe(HttpStatusCode.OK);

            var responseContent = await response.Content.ReadAsStringAsync();

            responseContent.ShouldContain("\"quantity\":4");
        }