public AnagramsSearchInfoModel GetAnagrams(string requestWord, string userIp) { var anagramsSearchInfoModel = new AnagramsSearchInfoModel(); if (!_userManagingService.CheckIfRegistered(userIp)) { _userContract.SetUser(userIp); } anagramsSearchInfoModel.isValidToSearch = _userManagingService.CheckIfValidToSearch(userIp); if (!anagramsSearchInfoModel.isValidToSearch) { return(anagramsSearchInfoModel); } if (_cachedWords.CheckIfCached(requestWord)) { _logger.Log(requestWord, userIp); anagramsSearchInfoModel.Anagrams = _cachedWords.GetCachedAnagrams(requestWord); return(anagramsSearchInfoModel); } anagramsSearchInfoModel.Anagrams = _anagramSolver.GetAnagrams(requestWord).ToList(); _requestWordContract.SetRequestWord(requestWord); _cachedWords.SetCachedAnagrams(anagramsSearchInfoModel.Anagrams, requestWord); _logger.Log(requestWord, userIp); return(anagramsSearchInfoModel); }
public void GetAnagrams_IfWordIsCached_ShouldSetModelAnagramsFromCache() { List <string> anagrams = new List <string> { "sula", "alus" }; _cachedWords.CheckIfCached("test").Returns(true); _cachedWords.GetCachedAnagrams("test").Returns(anagrams); _userManagingService.CheckIfValidToSearch(ip).Returns(true); var result = _anagramsSearchService.GetAnagrams("test", ip); _logger.Received().Log("test", ip); result.Anagrams.ShouldBe(anagrams); _anagramSolver.DidNotReceive().GetAnagrams("test"); }