Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        public void GetOccuranceExternalLinkTableTest_two_same_link()
        {
            string input = string.Empty;
            string link1 = @"https://visualstudio.microsoft.com/vso/";

            input += (link1 + " " + link1);

            AnalyseModel model  = new AnalyseModel();
            var          result = model.GetOccuranceExternalLinkTable(input);

            Assert.IsTrue(result.Any(x => x.Key == link1 && x.Value == 2));
        }