private static void ShowStory3(Content content) { var detectWords = new NegativeWordsDetector(new NegativeWordRepository(), new SearchAndFilterText()); detectWords.Detect(content); Console.WriteLine("\r\n"); Console.WriteLine("Filtered text:\r\n"); Console.WriteLine(content.Text); }
private void Validate(Content content) { if (content == null) throw new ArgumentNullException(paramName: "content"); if (!_searchNegativeWords.Any()) { throw new NotSupportedException(); } }
private static void ShowStory2(Content content) { var detectWords = new NegativeWordsDetector(new NegativeWordRepository(),new SearchText()); detectWords.Detect(content); Console.WriteLine("Total Number of negative words: " + content.NegativeWordCount); Console.WriteLine("\r\n"); Console.WriteLine("Scanned the text:\r\n"); Console.WriteLine(content.Text); }
private static void ShowStory1( Content content) { var bannedWords = new[] { "swine", "bad", "nasty", "horrible" }; var wordDetector = new NegativeWordsDetector(bannedWords,new SearchText()); wordDetector.Detect(content); Console.WriteLine("Total Number of negative words: " + content.NegativeWordCount); Console.WriteLine("\r\n"); Console.WriteLine("Scanned the text:\r\n"); Console.WriteLine(content.Text); }
public void Detect(Content content) { Validate(content); var counter = 0; foreach (var word in _searchNegativeWords) { content.Text = _wordFinder.Search(content.Text, word, ref counter); } content.NegativeWordCount = counter; }
public void ShouldDetectNegativeWordFromArray(string contentText,string negativeWordsStr,string expectedCount) { var content = new Content { Text = contentText }; var negativeWords = negativeWordsStr.Split(','); var sut= new NegativeWordsDetector(negativeWords, new SearchText()); sut.Detect(content); var expectedResult = int.Parse(expectedCount); Assert.That(content.NegativeWordCount, Is.EqualTo(expectedResult)); }
public void ShouldDetectNegativeWordsFromRepository(string contentText, string negativeWordsStr, string expectedCount) { var negativeWords = negativeWordsStr.Split(','); var content = new Content { Text = contentText }; _fakeNegativeWordRepository.Setup(x => x.GetAll()).Returns(negativeWords); var sut = new NegativeWordsDetector(_fakeNegativeWordRepository.Object, new SearchText()); sut.Detect(content); var expectedResult = int.Parse(expectedCount); Assert.That(content.NegativeWordCount, Is.EqualTo(expectedResult)); }
public static void Main(string[] args) { var choice = "0"; do { Console.WriteLine("Enter 0 to exit."); Console.WriteLine("Enter 1 to get count of negative words."); Console.WriteLine("Enter 2 to get count of negative words, using negative words from data store."); Console.WriteLine("Enter 3 to get count of negative words, and filtered content."); Console.WriteLine("Enter 4 to get count of negative words, and original content."); choice = Console.ReadLine(); var content = new Content { Text = "The weather in Manchester in winter is bad. It rains all the time -"+ "it must be horrible for people visiting.Horrible to go out.Bad fun.UNPLEASANT." }; switch (choice) { case "1": ShowStory1(content); break; case "2": ShowStory2(content); break; case "3": ShowStory3(content); break; case "4": ShowStory4(content); break; default: break; } Console.WriteLine("\r\n"); } while (choice != "0"); }
public void ShouldFilterContent(string contentText, string negativeWordsStr, string expectedContent) { var negativeWords = negativeWordsStr.Split(','); var content = new Content { Text = contentText }; var sut = new NegativeWordsDetector(negativeWords,new SearchAndFilterText()); sut.Detect(content); Assert.That(content.Text, Is.EqualTo(expectedContent)); }