Ejemplo n.º 1
0
        public void GetAnagramsFromCache_ShouldReturnListOfCachedWords()
        {
            RequestedWord = "labas";
            ExpectedList  = new List <string>()
            {
                "labas", "balas"
            };

            var firstSample = new CachedEntity()
            {
                Id      = 1,
                Anagram = new WordEntity()
                {
                    Id = 1, Word = "labas", SortedWord = "aabls"
                },
                Request = new RequestEntity()
                {
                    Id = 1, Word = "labas"
                }
            };
            var secondSample = new CachedEntity()
            {
                Id      = 1,
                Anagram = new WordEntity()
                {
                    Id = 2, Word = "balas", SortedWord = "aabls"
                },
                Request = new RequestEntity()
                {
                    Id = 1, Word = "labas"
                }
            };

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

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

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

            var result = _cacheService.GetAnagramsFromCache(RequestedWord);

            result.ShouldNotBeNull();

            firstSample.Anagram.Word.ShouldBe(ExpectedList[0]);
            secondSample.Anagram.Word.ShouldBe(ExpectedList[1]);

            _cacheRepository.Received().GetCacheListByRequestWord(RequestedWord);
        }
Ejemplo n.º 2
0
        public void InsertWordToCache(string requestWord, IList <string> anagrams)
        {
            InsertWordToRequestedWords(requestWord);

            bool wordIsCached = _cacheRepository.GetCacheListByRequestWord(requestWord).Any();

            if (!wordIsCached)
            {
                foreach (var item in anagrams)
                {
                    CachedEntity cachedEntity = new CachedEntity()
                    {
                        RequestId = _requestRepository.GetByWord(requestWord).Id,
                        AnagramId = _wordRepository.GetByWord(item).Id
                    };
                    _cacheRepository.Add(cachedEntity);
                }
            }
        }