public void CountBannedWords_Test()
        {
            string text = "bad word 1, horrible nasty nasty nasty";
            BannedWordsProcessor wp = new BannedWordsProcessor();
            Mock<IBannedWordsRepo> mock = new Mock<IBannedWordsRepo>();
            mock.Setup(t=>t.GetBannedWordsList()).Returns(new List<string>());
            Assert.IsTrue(wp.CountBannedWords(text, mock.Object) == 0);

            mock.Setup(t => t.GetBannedWordsList()).Returns(new List<string>() { "bad", "horrible" });
            Assert.IsTrue(wp.CountBannedWords(text, mock.Object) == 2);

            Assert.IsTrue(wp.CountBannedWords("", mock.Object) == 0);
            Assert.IsTrue(wp.CountBannedWords(null, mock.Object) == 0);

            mock.Setup(t => t.GetBannedWordsList()).Returns(new List<string>() { "nasty" });
            Assert.IsTrue(wp.CountBannedWords(text, mock.Object) == 3);
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            string content = "The weather, in Manchester in winter is bad bad. It rains all the time - it must be horrible for people visiting.";
            bool skipFiltering = false;
            if (args.Length == 1)
                content = args[0];
            if (args.Length == 2)
            {
                content = args[0];
                if (args[0] == "-skipFilter")
                    skipFiltering = true;
            }

            BannedWordsProcessor wordProcessor = new BannedWordsProcessor();

            Console.WriteLine("Scanned the text:");
            Console.WriteLine(content);
            Console.WriteLine("Total Number of negative words: " + wordProcessor.CountBannedWords(content));
            wordProcessor.FilterOutNegativeWords(content, skipFiltering);

            Console.WriteLine("Press ANY key to exit.");
            Console.ReadKey();
        }