public void Remove(NegativeWord word) { if (Exists(word)) { NegativeWords.Remove(word); } }
public void Equals_WhenTwoWordsAreEqual_ShouldReturnTrue(string a, string b, bool expect) { // Arrange var word1 = new NegativeWord(a); var word2 = new NegativeWord(b); // Act var result = word1.Equals(word2); //Assert Assert.AreEqual(expect, result); }
public void RemoveNegativeWord_WithValidInput_ShouldCallTheRepo() { // Arrange var negativeWord = new NegativeWord("badword"); _negativeWordsRepo.Setup(e => e.Remove(negativeWord)); // Act _negativeWordService.Remove(negativeWord.Value); //Assert _negativeWordsRepo.Verify(e => e.Remove(negativeWord), Times.Once()); }
public void AddNegativeWord_WithValidInput_ShouldIncreaseTheNumberOfWords() { // Arrange var negativeWord = new NegativeWord("badword"); _negativeWordsRepo.Setup(e => e.Add(negativeWord)); // Act _negativeWordService.Add(negativeWord.Value); //Assert _negativeWordsRepo.Verify(e => e.Add(negativeWord), Times.Once()); }
public void Add_WithValidInput_ShouldStoreInMemory() { // Arrange var repo = new NegativeWordsRepository(); var negativeWord = new NegativeWord("shouldStoreInMemory"); var countPreSave = repo.NegativeWords.Count; // Act var persisted = repo.Add(negativeWord); //Assert Assert.AreEqual(negativeWord, persisted); Assert.AreEqual(repo.NegativeWords.Count, countPreSave + 1); }
public void Remove_WithValidInput_ShouldRemoveFromMemory() { // Arrange var repo = new NegativeWordsRepository(); var negativeWord = new NegativeWord("shouldRemoveFromMemory"); repo.NegativeWords.Add(negativeWord); var countPreSave = repo.NegativeWords.Count; // Act repo.Remove(negativeWord); //Assert Assert.AreEqual(repo.NegativeWords.Count, countPreSave - 1); Assert.IsNull(repo.NegativeWords.SingleOrDefault(w => w.Equals(negativeWord))); }
public void Add(string input) { if (string.IsNullOrEmpty(input)) { throw new ArgumentException(); } var word = new NegativeWord(input.ToLowerInvariant()); //no duplicates var exists = _negativeWordsRepository.Exists(word); if (!exists) { _negativeWordsRepository.Add(word); } }
public bool Exists(NegativeWord word) { var found = NegativeWords.SingleOrDefault(w => w.Equals(word)); return(found != null); }
public NegativeWord Add(NegativeWord word) { NegativeWords.Add(word); return(word); }