public void GetWords_WithStringParameter_ReturnsWordsThatStartWithStringParameter() { _wordsRepository.GetWords().Returns(new List <Word> { new Word { Id = 1, Text = "Labas" }, new Word { Id = 2, Text = "Laibas" }, new Word { Id = 3, Text = "Lalala" }, new Word { Id = 4, Text = "Albas" }, }); var matchingWordsResult = _wordsService.GetWords("la"); _wordsRepository.Received().GetWords(); _wordsRepository.ReceivedCalls().ToList().Count.ShouldBe(1); matchingWordsResult.ShouldNotBeEmpty(); matchingWordsResult.First().Text.ShouldBe("Labas"); matchingWordsResult.Last().Text.ShouldBe("Lalala"); }
public void Should_Return_Two_Anagrams(string userInput) { AnagramSolver anagramSolver = new AnagramSolver(config); List <WordModel> anagrams = anagramSolver.GetAnagrams(userInput, wordsRepository.GetWords()); Assert.IsTrue(anagrams.Count() == 2); }
public IList <Word> GetWords(string word) { return(_wordsRepository .GetWords() .Where(w => w.Text.ToLower().StartsWith(word.ToLower())) .ToList()); }
public void Should_Use_Anagrams_Cache_Only(string word, string userIp) { _cacheRepository.GetCachedAnagrams(word).Returns(new List <WordModel>() { new WordModel(word) }); _wordsRepository.GetWords().Returns(_dummyWordsRepository.GetWords()); _anagramSolver.GetAnagrams(word, _dummyWordsRepository.GetWords()).Returns(new List <WordModel>() { new WordModel(word) }); _anagramsService.GetAnagrams(word, userIp); _cacheRepository.Received().GetCachedAnagrams(word); _wordsRepository.DidNotReceive().GetWords(); _anagramSolver.DidNotReceive().GetAnagrams(word, _wordsRepository.GetWords()); }
public void Should_Throw_Exception_Trying_To_Delete_Non_Existing_Word(int wordId, string userIp) { _wordsRepository.GetWords().Returns(_dummyWordsRepository.GetWords()); _wordsRepository .When(x => x.DeleteWord(wordId)) .Do(x => { if (!_wordsRepository.GetWords().Any(w => w.Id == wordId)) { throw new Exception(); } }); Assert.Throws <Exception>(() => _dictionaryService.DeleteWord(wordId, userIp)); }
public List <WordResponseModel> GetAnagrams(string word, string ip) { try { _usersRepository.DecreaseAvailabeUserSearches(ip); } catch (Exception ex) { throw; } List <WordModel> anagrams; if (IsCached(word)) { anagrams = _cachedAnagrams; } else { anagrams = _anagramSolver.GetAnagrams(word, _wordsRepository.GetWords()); UpdateAnagramsCache(word, anagrams); } return(anagrams.Select(w => new WordResponseModel(w.word, w.Id)).ToList()); }