public async Task <IActionResult> UpdateQuiz(int quizId, [FromBody] UpdateQuizCommand updateQuizCommand) { Expect(updateQuizCommand, c => c != null); Expect(updateQuizCommand, c => c.Id == quizId); await Mediator.Send(updateQuizCommand); return(NoContent()); }
public async Task IsFalse(string value) { var command = new UpdateQuizCommand(new Quiz { _id = value }); var handler = new UpdateQuizHandler(_mock.Object); var result = await handler.Handle(command, CancellationToken.None); Assert.IsFalse(result); }
public async Task IsTrue() { var command = new UpdateQuizCommand(new Quiz { _id = "1" }); var handler = new UpdateQuizHandler(_mock.Object); var result = await handler.Handle(command, CancellationToken.None); Assert.IsTrue(result); }
public async Task <HttpResponseMessage> UpdateQuizAsync(UpdateQuizCommand command) { try { return(await client.PutAsync($"{baseUrl}/api/quiz/", RequestHelper.GetStringContentFromObject(command))); } catch (Exception e) { var message = e.InnerException.Message; throw; } }
public async Task <IActionResult> Put([FromRoute] Guid quizId, [FromBody] UpdateQuizCommand updateQuizCommand) { using (var scope = _tracer.BuildSpan("UpdateQuiz").StartActive(finishSpanOnDispose: true)) { var userId = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)); updateQuizCommand.SetIdAndOwnerId(quizId, userId); var response = await _mediator.Send(updateQuizCommand); //catch if failure return(Ok(response)); } }
public async Task <IActionResult> UpdateQuiz(Quiz quiz) { if (quiz == null) { throw new NullReferenceException("QuizController.UpdateQuiz: NullReferenceException - quiz is null " + DateTime.Now); } var command = new UpdateQuizCommand(quiz); var result = await _mediator.Send(command); if (result) { return(Ok()); } return(NotFound()); }
public async Task <IActionResult> Put([FromBody] UpdateQuizCommand command) { var entity = await _context.Quiz.FirstOrDefaultAsync(e => e.Id == command.Id); if (entity == null) { throw new NotFoundException(nameof(Quiz), command.Id); } entity.Name = command.Name; entity.DateCreated = command.DateCreated; entity.TimesCompleted = command.TimesCompleted; entity.UserId = command.UserId; await _context.SaveChangesAsync(); return(NoContent()); }
public async Task Handle_ValidQuizData_ShouldSuccess() { //Arrange var quizId = Guid.NewGuid(); _chapterRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <ISpecification <Chapter> >())) .ReturnsAsync(true); _quizRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <ISpecification <Quiz> >())) .ReturnsAsync(true); _quizRepositoryMock.Setup(x => x.SaveAsync(It.IsAny <Quiz>())) .Callback <Quiz>(x => x.Id = quizId) .ReturnsAsync(true); _mediatorMock.Setup(x => x.Send(It.IsAny <UpdateQuizCommandHandler>(), It.IsAny <CancellationToken>())); var command = new UpdateQuizCommand { Title = "anonymousQuizTitle", Priority = (int)Priority.Low, ChapterId = Guid.NewGuid(), Questions = new List <Question>() { new Question() { Title = "anonymousQuestionTitle", CorrectAnswer = "anonymousCorrectAnswer", Options = new List <Option>() { new Option() { Value = "anonymousValue" } } } } }; command.SetIdAndOwnerId(quizId, Guid.NewGuid()); //Act var result = await _quizCommandHandler.Handle(command, CancellationToken.None); //Assert Assert.Equal(quizId, result); }
public async Task Handle_ValidQuizData_SaveShouldFailed() { //Arrange _chapterRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <ISpecification <Chapter> >())) .ReturnsAsync(true); _quizRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <ISpecification <Quiz> >())) .ReturnsAsync(true); _quizRepositoryMock.Setup(x => x.SaveAsync(It.IsAny <Quiz>())) .ReturnsAsync(false); var command = new UpdateQuizCommand { Title = "anonymousQuizTitle", Priority = (int)Priority.Low, Questions = new List <Question>() { new Question() { Title = "anonymousQuestionTitle", CorrectAnswer = "anonymousCorrectAnswer", Options = new List <Option>() { new Option() { Value = "anonymousValue" } } } } }; command.SetIdAndOwnerId(Guid.NewGuid(), Guid.NewGuid()); //Act //Assert await Assert.ThrowsAsync <InvalidOperationException>(() => _quizCommandHandler.Handle(command, CancellationToken.None)); _autoMocker.VerifyAll(); }