public async Task CanUpdateQuestion()
        {
            var authorizedClient = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory);

            var updateQuestionCommand = new UpdateQuestionCommand
            {
                Id       = 1,
                Text     = "Yukaridakilerden hangisi aslinda asagidadir?",
                Duration = 321
            };

            var serializedUpdateCommand = JsonConvert.SerializeObject(updateQuestionCommand);

            // The endpoint or route of the controller action.
            var httpResponse = await authorizedClient.PutAsync(requestUri : "/Question",
                                                               content : new StringContent(content: serializedUpdateCommand,
                                                                                           encoding: Encoding.UTF8,
                                                                                           mediaType: StringConstants.ApplicationJson));

            //Must be successful
            httpResponse.EnsureSuccessStatusCode();

            Assert.True(httpResponse.IsSuccessStatusCode);
            Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);
        }
        public async Task Handle_GivenInvalidId_ShouldThrowEntityNotFoundException()
        {
            // Arrange
            var command = new UpdateQuestionCommand {
                Id = 100
            };

            // Act, Assert
            await Assert.ThrowsAsync <EntityNotFoundException>(() => _sut.Handle(command, CancellationToken.None));
        }
예제 #3
0
        public async Task <IActionResult> UpdateQuestion(int quizId, int questionId, [FromBody] UpdateQuestionCommand updateQuestionCommand)
        {
            Expect(updateQuestionCommand, c => c != null);
            Expect(updateQuestionCommand, c => c.QuizId == quizId);
            Expect(updateQuestionCommand, c => c.QuestionId == questionId);

            await Mediator.Send(updateQuestionCommand);

            return(NoContent());
        }
예제 #4
0
        public async Task <ActionResult> Update(int QuestionsId, UpdateQuestionCommand command)
        {
            if (QuestionsId != command.QuestionsId)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }
예제 #5
0
        public async Task <IActionResult> Put([FromRoute] Guid questionId, [FromBody] UpdateQuestionCommand updateQuestionCommand)
        {
            using (var scope = _tracer.BuildSpan("UpdateQuestion").StartActive(finishSpanOnDispose: true))
            {
                updateQuestionCommand.SetQuestionId(questionId);
                var response = await _mediator.Send(updateQuestionCommand);

                //catch if failure
                return(Ok(response));
            }
        }
예제 #6
0
 public async Task <HttpResponseMessage> UpdateQuestionAsync(UpdateQuestionCommand command)
 {
     try
     {
         return(await client.PutAsync($"{baseUrl}/api/question/", RequestHelper.GetStringContentFromObject(command)));
     }
     catch (Exception e)
     {
         var message = e.InnerException.Message;
         throw;
     }
 }
        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 Question Update(UpdateQuestionCommand command)
        {
            var Question = _repository.GetOne(command.Id);

            if (!string.IsNullOrEmpty(command.Enunciation))
            {
                Question.ChangeEnunciation(command.Enunciation);
            }
            if (!string.IsNullOrEmpty(command.Education))
            {
                Question.ChangeEducation(command.Education);
            }
            if (command.PhaseQuestion != null)
            {
                Question.ChangePhaseQuestion(command.PhaseQuestion);
            }
            if (command.StepQuestion != null)
            {
                Question.ChangeStepQuestion(command.StepQuestion);
            }
            if (command.TypeQuestion != 0)
            {
                Question.ChangeTypeQuestion(command.TypeQuestion);
            }
            if (command.TypeReply != 0)
            {
                Question.ChangeTypeReply(command.TypeReply);
            }

            if (command.Reply.Count > 0)
            {
                foreach (var reply in command.Reply)
                {
                    Question.AddReply(reply);
                }
            }

            _repository.Update(Question);

            if (Commit())
            {
                return(Question);
            }

            return(null);
        }
예제 #9
0
        public async Task <IActionResult> Put([FromBody] UpdateQuestionCommand command)
        {
            var entity = await _context.Question.FirstOrDefaultAsync(e => e.Id == command.Id);

            if (entity == null)
            {
                throw new NotFoundException(nameof(Question), command.Id);
            }

            entity.Content     = command.Content;
            entity.Question_No = command.Question_No;
            entity.Row_No      = command.Row_No;
            entity.QuizId      = command.QuizId;

            await _context.SaveChangesAsync();

            return(NoContent());
        }
예제 #10
0
        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);
        }
예제 #11
0
        public async Task <Result <QuestionResponse> > Update(UpdateQuestionCommand command)
        {
            var validationResult = Validate(await _updateQuestionCommandValidator.Validate(command));

            if (!validationResult.Success)
            {
                return(validationResult);
            }

            var question = await _repository.Get(command.Id);

            question
            .SetName(command.Name);

            var toAdd = command.Answers
                        .Where(commandAnswer => !question.Answers.Any(answer => answer.AnswerId == commandAnswer.Id))
                        .Select(answer => new QuestionAnswer(answer.Id, answer.Correct))
                        .ToList();
            var toRemove = question.Answers
                           .Where(answer => !command.Answers.Any(commandAnswer => commandAnswer.Id == answer.AnswerId))
                           .ToList();
            var toUpdate = question.Answers
                           .Where(answer => command.Answers.Any(commandAnswer => commandAnswer.Id == answer.AnswerId && commandAnswer.Correct != answer.Correct))
                           .ToList();

            foreach (var item in toRemove)
            {
                question.RemoveAnswer(item);
            }

            foreach (var item in toAdd)
            {
                question.AddAnswer(item);
            }

            foreach (var item in toUpdate)
            {
                item.SetCorrect(!item.Correct);
            }

            await _repository.Update(question);

            return(new Result <QuestionResponse>(new QuestionResponse()));
        }
        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);
        }
예제 #13
0
        public async Task Should_Update_Question()
        {
            var command = new UpdateQuestionCommand()
            {
                Id      = _question.Id,
                Name    = "TESTE",
                Answers = new List <QuestionAnswerDto>()
                {
                    new QuestionAnswerDto()
                    {
                        Id = Guid.NewGuid(), Name = "TESTE", Correct = true
                    }
                }
            };

            var result = await _service.Update(command);

            result.Success.Should().BeTrue();
        }
        public async Task Handle_ValidQuestionData_SaveShouldFailed()
        {
            //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>()))
            .ReturnsAsync(false);

            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
            //Assert
            await Assert.ThrowsAsync <InvalidOperationException>(() => _questionCommandHandler.Handle(createQuestionCommand, CancellationToken.None));

            _autoMocker.VerifyAll();
        }
예제 #15
0
        public async Task Should_Not_Update_Question()
        {
            var command = new UpdateQuestionCommand()
            {
                Id      = _question.Id,
                Name    = "TESTE",
                Answers = new List <QuestionAnswerDto>()
                {
                    new QuestionAnswerDto()
                    {
                        Id = Guid.NewGuid(), Name = "BMW", Correct = false
                    }
                }
            };

            var result = await _service.Update(command);

            result.Success.Should().BeFalse();
            result.Message.Should().Be(QuestionValidationMessages.NO_CORRECT_ANSWER);
        }
예제 #16
0
        public async Task <ValidationResult> Validate(UpdateQuestionCommand command)
        {
            var result = new ValidationResult();

            if (string.IsNullOrEmpty(command.Name))
            {
                result.AddMessage(QuestionValidationMessages.NAME);
            }
            else if (await _repository.VerifyExistence(command.Name, command.Id))
            {
                result.AddMessage(QuestionValidationMessages.NAME_EXISTS);
            }

            if (!command.Answers.Any())
            {
                result.AddMessage(QuestionValidationMessages.NO_ANSWERS);
            }
            if (!command.Answers.Any(answer => answer.Correct))
            {
                result.AddMessage(QuestionValidationMessages.NO_CORRECT_ANSWER);
            }

            return(result);
        }
예제 #17
0
        public async Task <ActionResult <ResponseModel <UpdateQuestionModel> > > Put([FromBody] UpdateQuestionCommand command)
        {
            try
            {
                command.UpdatedBy = Claims[ClaimTypes.Sid].ToInt();
                command.TenantId  = Guid.Parse(Claims[ClaimTypes.UserData]);

                var updateQuestionModel = await Mediator.Send(command);

                return(Ok(updateQuestionModel));
            }
            catch (NotFoundException)
            {
                return(NotFound());
            }
            catch (ObjectAlreadyExistsException ex)
            {
                return(Conflict(new ResponseModel <UpdateQuestionModel>(new Error(HttpStatusCode.Conflict, ex))));
            }
            catch
            {
                return(StatusCode(HttpStatusCode.InternalServerError.ToInt()));
            }
        }
예제 #18
0
        public async Task <IActionResult> Update(UpdateQuestionCommand command)
        {
            var result = await Mediator.Send(command);

            return(GetResponse(result));
        }
예제 #19
0
 public async Task <IActionResult> UpdatePollQuestion(UpdateQuestionCommand request)
 {
     return(Ok(await _mediator.Send(request)));
 }
예제 #20
0
        public async Task <IActionResult> Update([FromBody] UpdateQuestionCommand command)
        {
            await _mediator.Send(command);

            return(NoContent());
        }
예제 #21
0
 public async Task <Result <QuestionResponse> > Put([FromBody] UpdateQuestionCommand command) => await _service.Update(command);