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); }
public void Analyse_OnExecuteWithKeywordPresentButNotInFront_SetsAnalyzeResult() { var doc = new HtmlDocument(); doc.LoadHtml("<head><title>test test test focus</title></head>"); var pageData = new PageData() { Document = doc.DocumentNode, Focuskeyword = "focus", Url = "http://www.google.com" }; var analyzer = new KeywordTitleAnalyzer(new HtmlTagHelper(), new OptionHelper()); analyzer.Analyse(pageData); var result = analyzer.AnalyzeResult; Assert.IsNotNull(result); Assert.IsTrue(result.ResultRules.Count == 1); Assert.AreEqual(ResultType.Hint, result.ResultRules.First().Type); Assert.AreEqual("title_not_in_front", result.ResultRules.First().Alias); }
public void Analyse_OnExecuteWithMultipleTitleTags_SetsAnalyzeResult() { var doc = new HtmlDocument(); doc.LoadHtml("<title><div><title>focus</title></div></title>"); var pageData = new PageData() { Document = doc.DocumentNode, Focuskeyword = "focus", Url = "http://www.google.com" }; var analyzer = new KeywordTitleAnalyzer(new HtmlTagHelper(), new OptionHelper()); 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_title_tags", result.ResultRules.First().Alias); }
public void Analyse_OnExecuteWithKeywordNotPresent_SetsAnalyzeResult() { var doc = new HtmlDocument(); doc.LoadHtml("<head><title>empty</title></head>"); var pageData = new PageData() { Document = doc.DocumentNode, Focuskeyword = "focus", Url = "http://www.google.com" }; var analyzer = new KeywordTitleAnalyzer(new HtmlTagHelper(), new OptionHelper()); 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("title_doesnt_contain_keyword", result.ResultRules.First().Alias); }
public void Analyse_OnExecuteWithNullParameter_ThrowArgumentNullException() { var analyzer = new KeywordTitleAnalyzer(new HtmlTagHelper(), new OptionHelper()); analyzer.Analyse(null); }