예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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());
        }