コード例 #1
0
        public bool AddWord(string word)
        {
            WordEntity wordEntity = _wordRepository.GetByWord(word);

            if (wordEntity != null)
            {
                return(false);
            }

            wordEntity = new WordEntity()
            {
                Word       = word,
                SortedWord = string.Concat(word.ToLower().OrderBy(x => x))
            };
            _wordRepository.Add(wordEntity);

            return(true);
        }
コード例 #2
0
        public async Task GetValueAsync(string word)
        {
            var res = await _repository.GetByWord(word.ToLower());

            if (res != null)
            {
                await ReplyAsync(res.Value.ToString());
            }

            else
            {
                await ReplyAsync("That word doesn't exist!");
            }
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
0
        public void AddWord_ShouldAddWordToDictionaryAndReturnTrue()
        {
            RequestedWord = "labas";

            _wordRepository.GetByWord(RequestedWord).ReturnsNull();

            _wordRepository.Add(Arg.Is <WordEntity>(q => q.Word.Equals(RequestedWord))).Returns(1);

            var result = _modificationService.AddWord(RequestedWord);

            result.ShouldBeTrue();

            _wordRepository.Received().Add(Arg.Is <WordEntity>(q => q.Word.Equals(RequestedWord)));
            _wordRepository.Received().GetByWord(RequestedWord);
        }