Пример #1
0
        public void Analyser_SubmitsTextWithoutCheckBoxes_ReturnsListOfWordsAndOccurences()
        {
            //arrange
            seoAnalyser = new Analyser("Kuala Lumpur is a big city.");

            //act
            results = seoAnalyser.Analyse();

            //assert
            List <Result> expectedText = new List <Result>()
            {
                new Result()
                {
                    Word = "Kuala", Occurrences = 0
                },
                new Result()
                {
                    Word = "Lumpur", Occurrences = 0
                },
                new Result()
                {
                    Word = "big", Occurrences = 0
                },
                new Result()
                {
                    Word = "city", Occurrences = 0
                }
            };

            Assert.AreEqual(4, results.Except(expectedText).Count());
            foreach (Result text in results)
            {
                Assert.IsTrue(text.Occurrences == 0);
            }
        }
Пример #2
0
        public void Analyser_SubmitHtmlOnly_ReturnsListOfWordsAndOccurencesInMetatag()
        {
            //arrange
            seoAnalyser = new Analyser(@"<!DOCTYPE html>
					< html lang = 'en' xmlns = 'http://www.w3.org/1999/xhtml' >
					< head >
					< meta charset = 'utf-8' />
					< meta content = 'Test' />
					< meta content = 'Test' />
					</ head >
					< body >
					This is just a test on meta tags.
					</ body >
					</ html >"                    )
            {
                OccurencesInMetaTag = true,
                OccurencesInPage    = true
            };

            //act
            results = seoAnalyser.Analyse();

            //assert
            Assert.AreEqual(3, results.Single(result => result.Word.ToLower() == "test").Occurrences);
        }
Пример #3
0
        public void Analyser_SubmitsEmptyText_ReturnsError()
        {
            //arrange
            seoAnalyser = new Analyser(" ");

            //act
            results = seoAnalyser.Analyse();
        }
Пример #4
0
        public void Analyser_SubmitInvalidUrlOnly_ReturnsInvalidUrlError()
        {
            //arrange
            seoAnalyser = new Analyser("http://www.google1.com")
            {
                IsUrl = true
            };

            //act
            results = seoAnalyser.Analyse();

            //assert
        }
Пример #5
0
        public void Analyser_SubmitsTextWithExternalLinks_ReturnsListOfWordsAndOccurences()
        {
            //arrange
            seoAnalyser = new Analyser("http://www.google.com http://www.google.com")
            {
                ExternalLinks    = true,
                OccurencesInPage = true
            };

            //act
            results = seoAnalyser.Analyse();

            //assert
            Assert.AreEqual("ExternalLink", results[0].Word);
            Assert.AreEqual(2, results[0].Occurrences);
        }
Пример #6
0
        /// <summary>
        /// Analyses input from user.
        /// </summary>
        /// <param name="request">Analyse request.</param>
        /// <returns>Analysis results.</returns>
        public async Task <ActionResult> Analyse(AnalyseRequest request)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Error = "Text or URL is required!";
                return(View("Index", request));
            }

            var isInputUrl = Uri.IsWellFormedUriString(request.Input, UriKind.Absolute);
            var result     = new AnalysisResult(request);

            if (!new bool[]
            {
                request.IsCalculateKeywordsInMetaTags,
                request.IsCalculateNumberOfExternalLinks,
                request.IsCalculateOccurrencesOfEachWords
            }.Any(x => x))
            {
                ViewBag.Warning = "No Analysis Result Type selected!";
                return(View(result));
            }

            if (!isInputUrl && !request.IsCalculateOccurrencesOfEachWords)
            {
                ViewBag.Warning = "'Calculate Occurrences of Each Words?' must be checked when analysing words.";
                return(View(result));
            }

            try
            {
                ISeoAnalyser analyser = isInputUrl ? new HtmlAnalyser(new LinkAnalyser(), new MetaAnalyser(), new WordAnalyser()) as ISeoAnalyser : new WordAnalyser() as ISeoAnalyser;
                result = await analyser.Analyse(request);
            }
            catch (HttpRequestException)
            {
                ViewBag.Error = $"{request.Input} is invalid!";
            }
            catch (Exception)
            {
                ViewBag.Error = $"Unknown error.";
            }

            return(View(result));
        }
Пример #7
0
        public void Analyser_SubmitsTextWithSpecialCharacters_ReturnsListOfWordsAndOccurences()
        {
            //arrange
            seoAnalyser = new Analyser("Kuala Lumpur / is a *& big city.")
            {
                OccurencesInPage = true
            };

            //act
            results = seoAnalyser.Analyse();

            //assert
            List <Result> expectedText = new List <Result>()
            {
                new Result()
                {
                    Word = "Kuala", Occurrences = 1
                },
                new Result()
                {
                    Word = "Lumpur", Occurrences = 1
                },
                new Result()
                {
                    Word = "big", Occurrences = 1
                },
                new Result()
                {
                    Word = "city", Occurrences = 1
                }
            };

            Assert.AreEqual(4, results.Except(expectedText).Count());
            foreach (Result text in results)
            {
                Assert.IsTrue(text.Occurrences == 1);
            }
        }