コード例 #1
0
        public void GetOccuranceWordTableTest_input_is_empty()
        {
            string input = "    ";

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

            Assert.AreEqual(0, result.Count());
        }
コード例 #2
0
        public void GetOccuranceWordTableTest_upperCharacter()
        {
            string input = "Apple apple APPLE";

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

            Assert.IsTrue(result.Any(x => x.Key == "apple" && x.Value == 3));
        }
コード例 #3
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));
        }
コード例 #4
0
        public void GetOccuranceWordTableTest_two_differenct_words()
        {
            string input = "Apple banana apple Banana APPLE";

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

            Assert.IsTrue(result.Any(x => x.Key == "apple" && x.Value == 3));
            Assert.IsTrue(result.Any(x => x.Key == "banana" && x.Value == 2));
        }
コード例 #5
0
        public void GetOccuranceWordTableTest()
        {
            string input = "apple apple apple";

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

            Assert.IsTrue(result.Any(x => x.Key == "apple" && x.Value == 3));
            Assert.IsFalse(result.Any(x => x.Key == "apple" && x.Value == 1));
        }