public async Task Handle(ChallengeStarting @event)
        {
            var delay = @event.StartDate - DateTimeOffset.UtcNow;

            if (delay.TotalMilliseconds > 0)
            {
                _logger.LogInformation("Waiting {WaitSeconds} seconds before starting the quiz {QuizId}",
                                       delay.TotalSeconds, @event.QuizId);
                await Task.Delay(delay);
            }

            var newChallenge = _mathChallengeService.CreateChallenge();

            _logger.LogInformation("New challenge {Challenge} with answer {Answer} created for quiz {QuizId}",
                                   newChallenge.Question, newChallenge.IsCorrect, @event.QuizId);

            await _quizService.SetChallengeToQuiz(
                @event.QuizId,
                newChallenge.Question,
                newChallenge.IsCorrect
                );

            _eventBus.Publish(new ChallengeUpdated
            {
                Question = newChallenge.Question,
                QuizId   = @event.QuizId
            });
        }
Ejemplo n.º 2
0
        public void CreateChallenge_JustCalled_NotNullChallenge()
        {
            // Act
            var challenge = _service.CreateChallenge();

            // Assert
            Assert.NotNull(challenge);
            Assert.NotEmpty(challenge.Question);
            Assert.False(challenge.IsCompleted);
        }