public async Task <IActionResult> UpdateIncremental(int id, [FromBody] CustomizationDto customizationDto)
        {
            var customizationObj = await _coditoRepository.GetCustomizationAsync(id);

            if (customizationObj == null)
            {
                return(NotFound(new ProblemDetailsError(StatusCodes.Status404NotFound)));
            }

            // User passes Id as a parameter. If an Id is passed in the body, it is ignored.
            customizationDto.Id = id;
            var customizationUpdated = Mapper.Map <Customization>(customizationDto);

            await _coditoRepository.ApplyPatchAsync(customizationUpdated);

            return(NoContent());
        }
예제 #2
0
        public async Task UpdateCustomizationIncremental_NotFound_TestAsync()
        {
            //Arrange
            int id            = -1;
            var customization = new CustomizationDto
            {
                InventoryLevel = 100
            };

            var request = TestExtensions.GetJsonRequest(customization, "PATCH", $"/codito/v1/customization/{id}");

            // Act
            var response = await fixture._httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }
예제 #3
0
        public async Task UpdateCustomizationIncremental_NoContent_TestAsync()
        {
            //Arrange
            int id            = 1;
            var customization = new CustomizationDto
            {
                InventoryLevel = 100
            };

            var request  = new HttpRequestMessage(HttpMethod.Get, $"/codito/v1/customization/{id}");
            var response = await fixture._httpClient.SendAsync(request);

            var actualDto = JsonConvert.DeserializeObject <CustomizationDto>(await response.Content.ReadAsStringAsync());

            request = TestExtensions.GetJsonRequest(customization, "PATCH", $"/codito/v1/customization/{id}");

            //actualDto.Should().BeNull();

            // Act
            response = await fixture._httpClient.SendAsync(request);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.NoContent);
            request  = new HttpRequestMessage(HttpMethod.Get, $"/codito/v1/customization/{id}");
            response = await fixture._httpClient.SendAsync(request);

            var updatedDto = JsonConvert.DeserializeObject <CustomizationDto>(await response.Content.ReadAsStringAsync());

            updatedDto.Id.Should().Be(actualDto.Id);

            //these should stay the same
            updatedDto.Name.Should().Be(actualDto.Name);
            updatedDto.NumberSold.Should().Be(actualDto.NumberSold);
            updatedDto.CarId.Should().Be(actualDto.CarId);

            // this one is updated
            updatedDto.InventoryLevel.Should().Be(customization.InventoryLevel);
            updatedDto.InventoryLevel.Should().NotBe(actualDto.InventoryLevel);
        }