public ActionResult Index(AnalyseModel model) { string content = string.Empty; model.InvalidMessage = string.Empty; #region Validate input if (model.IsAnyOptionSelected == false) { model.InvalidMessage = "Please check at least one of the checkbox"; } else if (string.IsNullOrWhiteSpace(model.Input)) { model.InvalidMessage = "Please enter text or url"; } else if (Uri.TryCreate(model.Input, UriKind.Absolute, out Uri uri)) { content = GetHtmlText(uri); if (string.IsNullOrEmpty(content)) { model.InvalidMessage = "The URL you enter could not be access"; } } else { content = model.Input; } #endregion if (string.IsNullOrEmpty(model.InvalidMessage)) { model.IsValid = true; if (model.FilterStopsWordsFlag) { content = model.RemoveStopWords(content); } if (model.CalNumOfOccuranceOfWordsFlag) { model.OccuranceOfWordsTable = model.GetOccuranceWordTable(HttpUtility.HtmlEncode(content)); } if (model.CalNumOfOccuranceOfWordsListedInMetaTagsFlag) { model.OccuranceOfWordsInMetaTagsTable = model.GetOccuranceWordInMetaTagTable(content); } if (model.CalNumOfOccuranceOfExternalLinksFlag) { model.OccuranceOfExternalLinksTable = model.GetOccuranceExternalLinkTable(content); } } return(View(model)); }
public void GetOccuranceWordInMetaTagTableTest() { string input = @"<meta charset= ""UTF - 8\""> <meta name = ""keywords"" content = ""HTML,CSS,XML,JavaScript"" > <meta name = ""keywords"" content = ""HTML,CSS,XML,JavaScript"" > <meta name = ""keywords"" content = ""HTML,CSS,XML,JavaScript"" >"; AnalyseModel model = new AnalyseModel(); var result = model.GetOccuranceWordInMetaTagTable(input); Assert.IsTrue(result.Any(x => x.Key == "content" && x.Value == 3)); Assert.IsTrue(result.Any(x => x.Key == "name" && x.Value == 3)); Assert.IsTrue(result.Any(x => x.Key == "\"keywords\"" && x.Value == 3)); }