public void GetAnagrams_ShouldReturnExistingAnagrams() { string word = "dangus"; string ip = "107.0.0.1"; allowedSearchesRepository.CheckIfExists(ip).Returns(true); allowedSearchesRepository.GetAmountOfSearches(ip).Returns(10); userLogRepository.CountUserSearchesByIp(ip).Returns(1); cacheRepository.GetCachedAnagrams(word).Returns(new List <string> { "dugnas", "gandus" }); var result = anagramService.GetAnagrams(word, ip); Assert.IsNotNull(result); Assert.AreEqual("dugnas", result.First()); allowedSearchesRepository.Received().CheckIfExists(ip); allowedSearchesRepository.Received().GetAmountOfSearches(ip); userLogRepository.Received().CountUserSearchesByIp(ip); cacheRepository.Received().GetCachedAnagrams(word); allowedSearchesRepository.DidNotReceive().SaveNewUser(Arg.Any <string>(), Arg.Any <int>()); wordRepository.DidNotReceive().FindAnagrams(Arg.Any <string>()); cacheRepository.DidNotReceive().Save(Arg.Any <string>(), Arg.Any <IEnumerable <string> >()); }
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()); }
private bool IsCached(string word) { _cachedAnagrams = _cacheRepository.GetCachedAnagrams(word); return(_cachedAnagrams.Count > 0); }