public async Task PutAsyncTest_ReturnsBadRequest() { var putCategory = new PutCategory(); controller.ModelState.AddModelError("MockError", "Model is invalid"); var result = await controller.PutAsync(putCategory); var assert = Assert.IsType <BadRequestObjectResult>(result); }
public async Task PutAsyncTest_ReturnsNotFound() { var category = new CategoryDTO(); var putCategory = new PutCategory(); _mapperMock.Setup(m => m.Map <PutCategory, CategoryDTO>(putCategory)) .Returns(category); _serviceMock.Setup(s => s.UpdateAsync(category)) .Returns(Task.FromResult((CategoryDTO)null)); var result = await controller.PutAsync(putCategory); var assert = Assert.IsType <NotFoundResult>(result); }
public async Task <IActionResult> PutAsync([FromBody] PutCategory request) { var prefix = "[PutAsync]"; _logger.LogInformation($"{prefix} Executing action"); if (!ModelState.IsValid) { _logger.LogWarning($"{prefix} Invalid model"); return(BadRequest(ModelState)); } var entity = _mapper.Map <PutCategory, CategoryDTO>(request); var response = await _service.UpdateAsync(entity); if (response == null) { _logger.LogWarning($"{prefix} Category with id {request.ID} not found"); return(NotFound()); } _logger.LogInformation($"{prefix} Updated category with id {request.ID}"); return(NoContent()); }