public void WhenPluralIsAddedThenTemporaryDefinitionIsSetToSingular()
        {
            var word          = "sloths";
            var shortenedWord = "sloth";

            _wordDefinitionHelper.GetDefinitionForWord(shortenedWord).Returns(TestFileHelper.SlothTemporaryDefinition);
            _webDictionaryRequestHelper.MakeContentRequest(shortenedWord).Returns("sloth word forms plural sloths");
            _wordExistenceHelper.DoesWordExist(shortenedWord).Returns(true);

            _temporaryDefinitionHelper = new TemporaryDefinitionHelper(_fileHelper);
            var wordHelper = new WordHelper(_webDictionaryRequestHelper, _wordExistenceHelper, _wordDefinitionHelper, _fileHelper, _temporaryDefinitionHelper);

            wordHelper.StrippedSuffixDictionaryCheck(_dictionary, word);

            _wordService.UpdateDictionaryFile();

            _wordService.UpdateDictionaryFile();

            var json       = TestFileHelper.Read(Filename);
            var dictionary = JsonConvert.DeserializeObject <Dictionary>(json);

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = "sloths",
                PermanentDefinition = null,
                TemporaryDefinition = TestFileHelper.SlothTemporaryDefinition,
                Status = WordStatus.Suffix
            });
        }
Ejemplo n.º 2
0
        public string GetDefinition(string filename, string word)
        {
            if (GetWordStatus(filename, word))
            {
                return(_wordDefinitionHelper.GetDefinitionForWord(word));
            }

            return(null);
        }
Ejemplo n.º 3
0
        public void WhenWordIsInTheDictionaryThenACallShouldBeMadeToGetTheDefinition()
        {
            var word = "sheep";

            _wordDefinitionHelper.ClearReceivedCalls();

            _wordExistenceHelper
            .DoesWordExist(word)
            .Returns(true);

            _wordDefinitionHelper.GetDefinitionForWord(word).Returns("An absolutely baaing animal");

            var wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
            var response    = wordService.GetDefinition(Filename, word);

            _wordDefinitionHelper.Received().GetDefinitionForWord(word);
            response.Should().Be("An absolutely baaing animal");
        }
Ejemplo n.º 4
0
        public bool StrippedSuffixDictionaryCheck(Dictionary dictionary, string word)
        {
            word = word.ToLower();
            var endings = new List <string> {
                "ning", "ing", "ed", "er", "es", "s", "d"
            };

            endings = endings
                      .Where(x => x.Length < word.Length)
                      .OrderByDescending(s => s.Length)
                      .ToList();


            foreach (var ending in endings)
            {
                var shortenedWord = word.Remove(word.Length - ending.Length);

                if (word.Substring(word.Length - ending.Length) != ending)
                {
                    continue;
                }

                if (!_wordExistenceHelper.DoesWordExist(shortenedWord))
                {
                    continue;
                }

                if (CheckWordWithEndingExists(word, shortenedWord))
                {
                    var temporaryDefinition = _wordDefinitionHelper.GetDefinitionForWord(shortenedWord);
                    _temporaryDefinitionHelper.AutomaticallySetTemporaryDefinitionForWord(dictionary, word, temporaryDefinition);
                    return(true);
                }
            }

            return(false);
        }