Exemplo n.º 1
0
        public async Task Start(int id)
        {
            var quizModel = QuizModelFactory.Create(id);
            var quiz      = new QuizAggregate();

            quiz.Start(quizModel);
            await _quizRepository.Save(quiz);
        }
Exemplo n.º 2
0
        public async Task <object> Start()
        {
            var quizModel = QuizModelFactory.Create();
            var quiz      = new QuizAggregate();

            quiz.Start(quizModel);
            await _quizRepository.Save(quiz);

            return(new
            {
                QuizId = quiz.Id,
                Questions = quiz.QuizModel.Questions
            });
        }
Exemplo n.º 3
0
        public void Given_A_Quiz_When_Starting_Then_QuizStartedEvent_Raised()
        {
            // Arrange
            var quiz      = new QuizAggregate();
            var quizModel = QuizModelFactory.Create(1);

            // Act
            quiz.Start(quizModel);

            // Assert
            var startEvent = quiz.GetPendingEvents().FirstOrDefault();

            Assert.NotNull(startEvent);
            Assert.IsAssignableFrom(typeof(QuizStartedEvent), startEvent);
        }
Exemplo n.º 4
0
        public void Given_An_Started_Quiz_When_Voting_For_WrongAnswer_Then_QuestionWrongAnsweredEvent_Raised()
        {
            // Arrange
            var quiz             = new QuizAggregate();
            var quizModel        = QuizModelFactory.Create(1);
            var selectedQuestion = quizModel.Questions.FirstOrDefault();
            var selectedOption   = selectedQuestion.Options.FirstOrDefault(x => !x.IsCorrect);

            // Act
            quiz.Start(quizModel);
            quiz.Vote(selectedQuestion.Id, selectedOption.Id);

            // Assert
            var startedEvent  = quiz.GetPendingEvents().FirstOrDefault();
            var answeredEvent = quiz.GetPendingEvents().LastOrDefault();

            Assert.NotNull(startedEvent);
            Assert.IsAssignableFrom(typeof(QuizStartedEvent), startedEvent);
            Assert.NotNull(answeredEvent);
            Assert.IsAssignableFrom(typeof(QuestionWrongAnsweredEvent), answeredEvent);
        }
Exemplo n.º 5
0
 public QuizModel Get(int id) => QuizModelFactory.Create(id);