Exemplo n.º 1
0
        public Analysis GetAnalysis()
        {
            var analysis = new Analysis();

            if (!string.IsNullOrEmpty(FocusKeyword) && FocusKeyword != "undefined")
            {
                FocusKeyword = FocusKeyword.ToLower();

                var wordOccurenceService = new WordOccurenceService();

                var topwords = wordOccurenceService.GetKeywords(_htmlResult);

                var information = new AnalysisInformation {
                    Alias = "keywordanalyzer_top_words"
                };
                information.Tokens.Add(FocusKeyword);
                foreach (var word in topwords)
                {
                    information.Tokens.Add(word.Key);
                    information.Tokens.Add(word.Value.ToString());
                }

                analysis.Information.Add(information);


                var keywordTitleAnalyzer = new KeywordTitleAnalyzer();
                analysis.Results.Add(keywordTitleAnalyzer.Analyse(_htmlResult.Document, FocusKeyword));

                var keywordMetaDescriptionAnalyzer = new KeywordMetaDescriptionAnalyzer();
                analysis.Results.Add(keywordMetaDescriptionAnalyzer.Analyse(_htmlResult.Document, FocusKeyword));

                var keywordUrlAnalyzer = new KeywordUrlAnalyzer();
                analysis.Results.Add(keywordUrlAnalyzer.Analyse(_htmlResult.Document, FocusKeyword, _htmlResult.Url));

                var keywordContentAnalyzer = new KeywordContentAnalyzer();
                analysis.Results.Add(keywordContentAnalyzer.Analyse(_htmlResult.Document, FocusKeyword));

                var keywordHeadingAnalyzer = new KeywordHeadingAnalyzer();
                analysis.Results.Add(keywordHeadingAnalyzer.Analyse(_htmlResult.Document, FocusKeyword));
            }
            else
            {
                var information = new AnalysisInformation {
                    Alias = "keywordanalyzer_focus_keyword_not_set"
                };
                analysis.Information.Add(information);
            }

            return(analysis);
        }
Exemplo n.º 2
0
        public void Analyse_OnExecuteWithMultipleBodyTags_SetsAnalyzeResult()
        {
            var doc = new HtmlDocument();

            doc.LoadHtml("<body><div><body>focus</body></div></body>");

            var pageData = new PageData()
            {
                Document     = doc.DocumentNode,
                Focuskeyword = "focus",
                Url          = "http://www.google.com"
            };

            var analyzer = new KeywordContentAnalyzer(new HtmlTagHelper());

            analyzer.Analyse(pageData);
            var result = analyzer.AnalyzeResult;

            Assert.IsNotNull(result);
            Assert.IsTrue(result.ResultRules.Count == 1);
            Assert.AreEqual(ResultType.Error, result.ResultRules.First().Type);
            Assert.AreEqual("multiple_body_tags", result.ResultRules.First().Alias);
        }
Exemplo n.º 3
0
        public void Analyse_OnExecuteWithKeywordNotPresent_SetsAnalyzeResult()
        {
            var doc = new HtmlDocument();

            doc.LoadHtml("<body><div></div></body>");

            var pageData = new PageData()
            {
                Document     = doc.DocumentNode,
                Focuskeyword = "focus",
                Url          = "http://www.google.com"
            };

            var analyzer = new KeywordContentAnalyzer(new HtmlTagHelper());

            analyzer.Analyse(pageData);
            var result = analyzer.AnalyzeResult;

            Assert.IsNotNull(result);
            Assert.IsTrue(result.ResultRules.Count == 1);
            Assert.AreEqual(ResultType.Warning, result.ResultRules.First().Type);
            Assert.IsTrue(!result.ResultRules.First().Tokens.Any());
            Assert.AreEqual("content_doesnt_contain_keyword", result.ResultRules.First().Alias);
        }
Exemplo n.º 4
0
        public void Analyse_OnExecuteWithNullParameter_ThrowArgumentNullException()
        {
            var analyzer = new KeywordContentAnalyzer(new HtmlTagHelper());

            analyzer.Analyse(null);
        }