Exemple #1
0
        public void GenerateReport_GivenValidWebsiteUrl_ExpectValidGenetaredReport()
        {
            var images = new List <ImageModel>
            {
                new ImageModel("imageA"),
                new ImageModel("imageB")
            };

            var wordsSummary = new WordsSummaryModel
            {
                DifferentWordsCount      = 2,
                WordsCount               = 5,
                OccurringWordsDictionary = new Dictionary <string, int>
                {
                    { "a", 3 },
                    { "b", 2 }
                }
            };

            m_ImagesFetcherServiceMock.Setup(imageFetcher => imageFetcher.FetchImages(WEBSITE))
            .Returns(images);

            m_WordsHandlerMock.Setup(wordsHandler => wordsHandler.GetWordsSummary(WEBSITE))
            .Returns(wordsSummary);

            var fullReport = m_ReportGeneratorService.GenerateReport(WEBSITE);

            Assert.That(fullReport.ImagesCarousel.Images.Count, Is.EqualTo(images.Count));
            Assert.That(fullReport.ImagesCarousel.Images[0], Is.EqualTo(images[0]));
            Assert.That(fullReport.ImagesCarousel.Images[1], Is.EqualTo(images[1]));

            Assert.That(fullReport.WordsSummary.DifferentWordsCount, Is.EqualTo(wordsSummary.DifferentWordsCount));
            Assert.That(fullReport.WordsSummary.WordsCount, Is.EqualTo(wordsSummary.WordsCount));
            Assert.That(fullReport.WordsSummary.OccurringWordsDictionary.Count, Is.EqualTo(wordsSummary.OccurringWordsDictionary.Count));
        }
        /// <summary>
        /// Gets the summary about the words for the provided website.
        /// </summary>
        /// <param name="p_WebsiteUrl">The provided website URL.</param>
        /// <returns>An instance of <see cref="WordsSummaryModel"/>.</returns>
        public WordsSummaryModel GetWordsSummary(string p_WebsiteUrl)
        {
            var wordsSummary = new WordsSummaryModel();

            var allWords = GetAllWords(p_WebsiteUrl);

            if (allWords != null && allWords.Any())
            {
                var wordsDictionary = new Dictionary <string, int>(StringComparer.InvariantCultureIgnoreCase);

                foreach (string word in allWords)
                {
                    if (wordsDictionary.ContainsKey(word))
                    {
                        wordsDictionary[word]++;
                    }
                    else
                    {
                        wordsDictionary.Add(word, 1);
                    }
                }

                wordsSummary = new WordsSummaryModel
                {
                    OccurringWordsDictionary = wordsDictionary,
                    DifferentWordsCount      = wordsDictionary.Keys.Count,
                    WordsCount = allWords.Count
                };
            }

            return(wordsSummary);
        }