public async Task Should_Start_Quiz() { var command = new StartQuizCommand() { UserName = "******" }; var result = await _service.StartQuiz(command); result.Success.Should().BeTrue(); }
public ValidationResult Validate(StartQuizCommand command) { var result = new ValidationResult(); if (string.IsNullOrEmpty(command.UserName)) { result.AddMessage(QuizValidationMessages.NAME); } return(result); }
public async Task <Result <QuizResponse> > StartQuiz(StartQuizCommand command) { var validationResult = Validate(_startQuizCommandValidator.Validate(command)); if (!validationResult.Success) { return(validationResult); } var query = await _repository.GetAll(); var questions = query .Select(QuestionResponse.ToQuizResponse) .OrderBy(question => Guid.NewGuid()) .AsEnumerable(); var response = new QuizResponse() { Questions = questions }; return(new Result <QuizResponse>(response)); }
public async Task <Result <QuizResponse> > Start([FromBody] StartQuizCommand command) => await _quizService.StartQuiz(command);