public void GetMetaTags_OnExecuteWithNoMetaTags_ThrowsException() { var doc = new HtmlDocument(); doc.LoadHtml("<html>Empty</html>"); var htmlTagHelper = new HtmlTagHelper(); htmlTagHelper.GetMetaTags(doc.DocumentNode); }
public override AnalyzeResult Analyse(IPageData pageData) { var result = new AnalyzeResult(); var metaTags = _htmlTagHelper.GetMetaTags(pageData.Document, result); if (metaTags.Any()) { AnalyzeMetaTags(metaTags, result); } return(result); }
public void GetMetaTags_OnExecuteWithMetaTags_ReturnsMetaTagsNodes() { var doc = new HtmlDocument(); doc.LoadHtml("<html><meta /><meta /></html>"); var htmlTagHelper = new HtmlTagHelper(); var metaTags = htmlTagHelper.GetMetaTags(doc.DocumentNode); Assert.IsNotNull(metaTags); Assert.AreEqual(2, metaTags.Count()); }
public override AnalyzeResult Analyse(IPageData pageData) { var result = new AnalyzeResult(); var metaTags = _htmlTagHelper.GetMetaTags(pageData.Document, result); if (metaTags.Any()) { var attributeValues = from metaTag in metaTags let attribute = metaTag.GetAttribute("name") where attribute != null where attribute.Value == "description" select metaTag.GetAttribute("content"); if (!attributeValues.Any()) { result.AddResultRule("no_meta_description_tag", ResultType.Warning); } else if (attributeValues.Count() > 1) { result.AddResultRule("multiple_meta_description_tags", ResultType.Warning); } else { var firstMetaDescriptionTag = attributeValues.FirstOrDefault(); if (firstMetaDescriptionTag != null) { var descriptionValue = firstMetaDescriptionTag.Value; if (descriptionValue.IndexOf(pageData.Focuskeyword, StringComparison.InvariantCultureIgnoreCase) >= 0) { result.AddResultRule("meta_description_contains_keyword", ResultType.Success); } else { result.AddResultRule("meta_description_doesnt_contain_keyword", ResultType.Hint); } } } } return(result); }
public void GetMetaTags_OnExecuteWithNullParameter_ThrowsException() { var htmlTagHelper = new HtmlTagHelper(); htmlTagHelper.GetMetaTags(null); }