public async Task Handle_GivenValidRequest_ShouldUpdateQuestion() { // Arrange var command = new UpdateQuestionCommand { Id = 1, Text = "Question Text Updated" }; // Act await _sut.Handle(command, CancellationToken.None); var result = await _context.Questions.FindAsync(command.Id); // Assert Assert.Equal(command.Text, result.Text); Assert.True(DateTime.Compare(new DateTime(2020, 1, 1), result.UpdatedAt.Value) < 0); }
public async Task Handler_ValidQuestionData_ShouldSuccess() { //Arrange _quizRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <ISpecification <Quiz> >())) .ReturnsAsync(true); _questionRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <ISpecification <Question> >())) .ReturnsAsync(true); _questionRepositoryMock.Setup(x => x.SaveAsync(It.IsAny <Question>())) .Callback <Question>(x => x.Id = Guid.NewGuid()) .ReturnsAsync(true); var createQuestionCommand = new UpdateQuestionCommand() { QuizId = Guid.NewGuid(), Title = "anonymousText", CorrectAnswer = "anonymousText", Options = new List <Option>() { new Option() { Value = "anonymousOption1" }, new Option() { Value = "anonymousOption2" }, new Option() { Value = "anonymousOption3" }, new Option() { Value = "anonymousOption4" }, } }; //Act var result = await _questionCommandHandler.Handle(createQuestionCommand, CancellationToken.None); //Assert Assert.NotEqual(Guid.Empty, result); }
public async Task ShouldGetModelForValidInformation() { var updateQuestion = new UpdateQuestionCommand { Id = _questionId, TenantId = _tenantId, UpdatedBy = _adminUserId, Text = "Asagidakilerden hangisi asagidadir?", Duration = 3, TagsIdList = new List <int> { 1 } }; var questionModel = await _updateQuestionCommandHandler.Handle(updateQuestion, CancellationToken.None); Assert.Null(questionModel.Errors); }