public void FilterOutNegativeWords_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>() { "bad", "horrible", "nasty" }); string filtered = wp.FilterOutNegativeWords(text, false, mock.Object); Assert.IsTrue(filtered == "b#d word 1, h######e n###y n###y n###y"); filtered = wp.FilterOutNegativeWords(text, true, mock.Object); Assert.IsTrue(filtered == text); mock.Setup(t => t.GetBannedWordsList()).Returns(new List<string>() { "unknown banned word" }); filtered = wp.FilterOutNegativeWords(text, false, mock.Object); Assert.IsTrue(filtered == text); filtered = wp.FilterOutNegativeWords("", false, mock.Object); Assert.IsTrue(filtered == ""); filtered = wp.FilterOutNegativeWords(null, false, mock.Object); Assert.IsTrue(filtered == null); }
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(); }