コード例 #1
0
        public void GetAnagramsFromCache_ShouldReturnEmptyIfNothingIsPassed()
        {
            RequestedWord = "";
            ExpectedList  = new List <string>()
            {
            };


            var firstSample = new CachedEntity()
            {
            };
            var secondSample = new CachedEntity()
            {
            };

            IList <CachedEntity> returnedFromCache = new List <CachedEntity>()
            {
                firstSample,
                secondSample
            };

            _cacheRepository.GetCacheListByRequestWord(RequestedWord).Returns(returnedFromCache);

            //////////////////////////////////
            //////////////////////////////////

            var result = _cacheService.GetAnagramsFromCache(RequestedWord);

            result.ShouldBeEmpty();

            _cacheRepository.DidNotReceive().GetCacheListByRequestWord(RequestedWord);
        }
コード例 #2
0
        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> >());
        }