public async Task UpdateAsyncFailureTest() { // Arrange SaveQbQuestionResource resource = new SaveQbQuestionResource(); QbQuestion question = new QbQuestion(); mapper.Map <SaveQbQuestionResource, QbQuestion>(Arg.Any <SaveQbQuestionResource>()).Returns(question); IQbQuestionService qbQuestionService = Substitute.For <IQbQuestionService>(); QbQuestionResponse response = new QbQuestionResponse(string.Empty); qbQuestionService.UpdateAsync(Arg.Any <int>(), Arg.Any <QbQuestion>()).Returns(response); QbQuestionsController controller = new QbQuestionsController(qbQuestionService, mapper); // Act IActionResult result = await controller.PutAsync(1, resource); // Assert result.Should().BeOfType <BadRequestObjectResult>(); }
public async Task <IActionResult> PutAsync(int id, [FromBody] SaveQbQuestionResource resource) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } QbQuestion question = _mapper.Map <SaveQbQuestionResource, QbQuestion>(resource); QbQuestionResponse result = await _qbQuestionService.UpdateAsync(id, question); if (!result.Success) { return(BadRequest(result.Message)); } QbQuestionResource questionResource = _mapper.Map <QbQuestion, QbQuestionResource>(result.QbQuestion); return(Ok(questionResource)); }