public async Task GivenScraperServiceReturnsContent_WhenGetQuizAsyncByMetadata_ThenExpectedQuizReturned()
        {
            // Given
            _mockScraperHttpService.GetQuizPageContentAsync(TestQuizId).Returns(TestHtmlContent);
            _mockHtmlService.FindQuestions(TestHtmlContent).Returns(_questions);
            // When
            var quiz = await _quizService.GetQuizAsync(_quizMetadata);

            // Then
            Assert.AreEqual(TestQuizId, quiz.Id);
            Assert.AreEqual(TestQuizDate, quiz.Date);
            Assert.AreEqual(TestQuizTitle, quiz.Title);
            Assert.AreEqual(_questions, quiz.Questions);
        }
Esempio n. 2
0
        public async Task <Quiz> GetQuizAsync(QuizMetadata quizMetadata)
        {
            var quizHtml = await _scraperHttpService.GetQuizPageContentAsync(quizMetadata.Id);

            var questions = _htmlService.FindQuestions(quizHtml);

            return(new Quiz
            {
                Id = quizMetadata.Id,
                Date = quizMetadata.Date,
                Title = quizMetadata.Title,
                Questions = questions
            });
        }
        public void GivenHtml_WhenFindQuestions_ThenExpectedQuestionsAreReturned()
        {
            // Given
            const string html = "html";
            const string expectedQuestionsHtml         = "questionsHtml";
            const string expectedAnswersHtml           = "answersHtml";
            const string expectedQuestionsHtmlStripped = "questionsHtmlStripped";
            const string expectedAnswersHtmlStripped   = "answersHtmlStripped";
            var          expectedSections = new Sections
            {
                QuestionsSectionHtml = expectedQuestionsHtml,
                AnswersSectionHtml   = expectedAnswersHtml
            };
            var expectedQuestionsList = new List <string> {
                "questions"
            };
            var expectedAnswersList = new List <string> {
                "answers"
            };
            var expectedQuestions = new List <Question>
            {
                new Question
                {
                    Number       = 1,
                    Type         = QuestionType.Normal,
                    QuestionHtml = "questionHtml",
                    QuestionText = "questionText",
                    AnswerHtml   = "answerHtml",
                    AnswerText   = "answerText"
                }
            };

            _mockSectionExtractor.ExtractSections(html).Returns(expectedSections);
            _mockHtmlStripper.StripHtml(expectedQuestionsHtml).Returns(expectedQuestionsHtmlStripped);
            _mockHtmlStripper.StripHtml(expectedAnswersHtml).Returns(expectedAnswersHtmlStripped);
            _mockSectionSplitter.SplitSection(expectedQuestionsHtmlStripped).Returns(expectedQuestionsList);
            _mockSectionSplitter.SplitSection(expectedAnswersHtmlStripped).Returns(expectedAnswersList);
            _mockQuestionAssembler.AssembleQuestions(expectedQuestionsList, expectedAnswersList).Returns(expectedQuestions);

            // When
            var actualQuestions = _htmlService.FindQuestions(html);

            // Then
            Assert.That(actualQuestions, Is.EqualTo(expectedQuestions));
        }