public void AddWord_IfWordRepositoryDoesNotContainSpecifiedWord_ShouldNotCallAddWordAndGiveUserAdditionalSearch() { _wordRepository.GetWordsDictionary().Returns(new List <string> { "test", "vienas" }); _userContract.GetUser("127.0.0.1").Returns(new User { Id = 1, UserIp = "127.0.0.1", SearchesLeft = 10 }); _dictionaryManagingService.AddWord("test", "127.0.0.1"); _wordRepository.DidNotReceive().AddWord("test"); _userManagingService.DidNotReceive().GiveUserAdditionalSearch("127.0.0.1"); }
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 UsesDeterministicAlgorithmForShortWords(string word) { IWordRepository repository = Substitute.For <IWordRepository>(); AnagramProvider provider = new AnagramProvider(repository); provider.FindAnagrams(word); repository.DidNotReceive().GetWordsWithLength(word.Length); }
public void AddWord_ShouldNotAddExistingDictionaryWord() { RequestedWord = "labas"; WordEntity wordEntity = new WordEntity() { Id = 1, Word = "labas", SortedWord = "aabls" }; _wordRepository.GetByWord(RequestedWord).Returns(wordEntity); var result = _modificationService.AddWord(RequestedWord); _wordRepository.Received().GetByWord(RequestedWord); _wordRepository.DidNotReceive().Add(wordEntity); result.ShouldBeFalse(); }