public void WhenDoingIsAddedThenTemporaryDefinitionIsSetToBaseWord()
        {
            var word          = "slothning";
            var shortenedWord = "sloth";

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

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

            wordHelper.StrippedSuffixDictionaryCheck(_dictionary, word);

            _wordService.UpdateDictionaryFile();

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

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = "slothning",
                PermanentDefinition = null,
                TemporaryDefinition = TestFileHelper.SlothTemporaryDefinition,
                Status = WordStatus.Suffix
            });
        }
        public void WhenUpdateRequestedButBothWordAndDefinitionAreEmptyNothingShouldBeChanged()
        {
            var newDefinition = "";
            var word          = "";

            _wordService.UpdateExistingWord(Filename, word, newDefinition);
            _wordService.UpdateDictionaryFile();

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

            dictionary
            .Words
            .Count
            .Should()
            .Be(8);

            dictionary.Words.Should().Contain(x => x.Word == "sheep");
            dictionary.Words.Should().Contain(x => x.Word == "sloth");
            dictionary.Words.Should().Contain(x => x.Word == "pelican");
            dictionary.Words.Should().Contain(x => x.Word == "lion");
            dictionary.Words.Should().Contain(x => x.Word == "boxing");
            dictionary.Words.Should().Contain(x => x.Word == "dodo");
            dictionary.Words.Should().Contain(x => x.Word == "unicorn");
            dictionary.Words.Should().Contain(x => x.Word == "dinosaur");
        }
        public void WhenWordDoesNotExistButUpdateHappensNothingShouldBeChanged()
        {
            var newDefinition = "This is not a definition";
            var word          = "Not a word";

            _wordService.UpdateExistingWord(Filename, word, newDefinition);
            _wordService.UpdateDictionaryFile();

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

            dictionary
            .Words
            .Count
            .Should()
            .Be(8);

            dictionary.Words.Should().Contain(x => x.Word == "sheep");
            dictionary.Words.Should().Contain(x => x.Word == "sloth");
            dictionary.Words.Should().Contain(x => x.Word == "pelican");
            dictionary.Words.Should().Contain(x => x.Word == "lion");
            dictionary.Words.Should().Contain(x => x.Word == "boxing");
            dictionary.Words.Should().Contain(x => x.Word == "dodo");
            dictionary.Words.Should().Contain(x => x.Word == "unicorn");
            dictionary.Words.Should().Contain(x => x.Word == "dinosaur");
        }
Ejemplo n.º 4
0
        public void WhenDictionaryDoesNotContainWordThenTheNewWordShouldBeAdded()
        {
            var word       = "sheep";
            var definition = TestFileHelper.SheepPermanentDefinition;

            _wordService.AmendDictionary(Filename, word, definition);

            _wordService.UpdateDictionaryFile();

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

            response.Should().BeEquivalentTo(new Dictionary
            {
                Words = new List <WordData>
                {
                    new WordData
                    {
                        Word   = "pelican",
                        Status = WordStatus.Temporary,
                        PermanentDefinition = null,
                        TemporaryDefinition = null
                    },
                    new WordData
                    {
                        Word   = "sheep",
                        Status = WordStatus.Permanent,
                        PermanentDefinition = definition,
                        TemporaryDefinition = null
                    }
                }
            });
        }
        public void WhenWritingAnObjectToTheFileTheResponseShouldBeDeserializableToTheObjectWritten()
        {
            var data = new GuessedWords();

            data.AddWord("run", WordStatus.Permanent);
            data.AddWord("running", WordStatus.Suffix);

            FileHelper.WriteFile(Filename, data);

            var response = TestFileHelper.Read(Filename);

            var serializedObject = JsonConvert.SerializeObject(data);

            response.Should().BeEquivalentTo(serializedObject);
        }
Ejemplo n.º 6
0
        public void IfWordDoesNotExistInDictionaryThenTheWordShouldBeAddedToGuessedWordsAsNotExists()
        {
            _wordService.AddWordToGuessedWords(DictionaryFilename, GuessedWordsFilename, "telescope");
            _wordService.UpdateGuessedWordsFile();

            var json         = TestFileHelper.Read(GuessedWordsFilename);
            var guessedWords = JsonConvert.DeserializeObject <GuessedWords>(json);

            guessedWords
            .Words
            .Should()
            .BeEquivalentTo(new List <GuessedWord>
            {
                new GuessedWord("telescope", WordStatus.DoesNotExist)
            });
        }
        public AutomaticallySetTemporaryDefinitions()
        {
            TestFileHelper.Create(Filename);

            var json = TestFileHelper.Read(Filename);

            _webDictionaryRequestHelper = Substitute.For <IWebDictionaryRequestHelper>();
            _wordExistenceHelper        = Substitute.For <IWordExistenceHelper>();
            _wordDefinitionHelper       = Substitute.For <IWordDefinitionHelper>();
            _fileHelper = new FileHelper();

            _filenameHelper = Substitute.For <IFilenameHelper>();
            _filenameHelper.GetGuessedWordsFilename().Returns(Filename);
            _filenameHelper.GetDictionaryFilename().Returns(Filename);

            _wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
            _dictionary  = _wordService.GetDictionary();
        }
Ejemplo n.º 8
0
        public void WhenUserMarksNonExistingWordAsNonExistingThenStatusShouldBeNonExisting()
        {
            var word = "dinosaur";

            _wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
            _wordService.ToggleIsWordInDictionary(Filename, word, false);
            _wordService.UpdateDictionaryFile();

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

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = word,
                TemporaryDefinition = null,
                PermanentDefinition = null,
                Status = WordStatus.DoesNotExist
            });
        }
Ejemplo n.º 9
0
        public void WhenUserMarksPermanentWordWithNoDefinitionsAsExistingThenStatusShouldBePermanent()
        {
            var word = "sheep";

            _wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
            _wordService.ToggleIsWordInDictionary(Filename, word, true);
            _wordService.UpdateDictionaryFile();

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

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = word,
                TemporaryDefinition = TestFileHelper.SheepTemporaryDefinition,
                PermanentDefinition = TestFileHelper.SheepPermanentDefinition,
                Status = WordStatus.Permanent
            });
        }
Ejemplo n.º 10
0
        public void WhenUserMarksNonExistingWordWithATemporaryDefinitionButNoPermanentDefinitionAsExistingThenStatusShouldBeTemporary()
        {
            var word = "unicorn";

            _wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
            _wordService.ToggleIsWordInDictionary(Filename, word, true);
            _wordService.UpdateDictionaryFile();

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

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = word,
                TemporaryDefinition = TestFileHelper.UnicornTemporaryDefinition,
                PermanentDefinition = null,
                Status = WordStatus.Temporary
            });
        }
Ejemplo n.º 11
0
        public void WhenUserAddsNewWordToDictionary()
        {
            var word          = "hello";
            var newDefinition = "A friendly greeting";

            _wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
            _wordService.AddNewWordToDictionary(Filename, word, newDefinition);
            _wordService.UpdateDictionaryFile();

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

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = word,
                TemporaryDefinition = null,
                PermanentDefinition = newDefinition,
                Status = WordStatus.Permanent
            });
        }
Ejemplo n.º 12
0
        public void WhenUserUpdatesExistingDefinition()
        {
            var word          = "pelican";
            var newDefinition = TestFileHelper.PelicanPermanentDefinition;

            _wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
            _wordService.UpdateExistingWord(Filename, word, newDefinition);
            _wordService.UpdateDictionaryFile();

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

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = word,
                TemporaryDefinition = TestFileHelper.PelicanTemporaryDefinition,
                PermanentDefinition = newDefinition,
                Status = WordStatus.Permanent
            });
        }
Ejemplo n.º 13
0
        public void WhenDefinitionAutomaticallySourcedFromSuffixStatusShouldBeSuffix()
        {
            var word = "pelicans";
            var temporaryDefinition = TestFileHelper.PelicanTemporaryDefinition;

            _temporaryDefinitionHelper = new TemporaryDefinitionHelper(_fileHelper);
            _temporaryDefinitionHelper.AutomaticallySetTemporaryDefinitionForWord(_dictionary, word, temporaryDefinition);
            _wordService.UpdateDictionaryFile();

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

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = word,
                TemporaryDefinition = temporaryDefinition,
                PermanentDefinition = null,
                Status = WordStatus.Suffix
            });
        }
Ejemplo n.º 14
0
        public void WhenWordIsGuessedTwiceItShouldOnlyBeWrittenToTheFileOnce()
        {
            _wordService.AddWordToGuessedWords(DictionaryFilename, GuessedWordsFilename, _words[0]);
            _wordService.AddWordToGuessedWords(DictionaryFilename, GuessedWordsFilename, _words[0]);
            _wordService.AddWordToGuessedWords(DictionaryFilename, GuessedWordsFilename, _words[0]);
            _wordService.UpdateGuessedWordsFile();

            var json         = TestFileHelper.Read(GuessedWordsFilename);
            var guessedWords = JsonConvert.DeserializeObject <GuessedWords>(json);

            guessedWords
            .Words
            .Should()
            .BeEquivalentTo(new List <GuessedWord>
            {
                new GuessedWord(_words[0], WordStatus.Permanent)
            });

            guessedWords.Words.Should().HaveCount(1);
        }
Ejemplo n.º 15
0
        public void ReadingAFileShouldReturnTheFileContent()
        {
            var fileHelper = new Chat.WordGame.LocalDictionaryHelpers.FileHelper();

            var json = TestFileHelper.Read(_filename);

            JToken.Parse(json).Should().BeEquivalentTo($@"
            {{
                ""Words"": [
                    {{""Word"":""sheep"",""TemporaryDefinition"":""A fluffy animal that sits, eats grass, sits, eats grass and is commonly counted by children who can't sleep (they love the attention)."", ""PermanentDefinition"": ""An animal with a wool laden coat that lives on a farm"", ""Status"": {(int)WordStatus.Permanent}}},
                    {{""Word"":""sloth"",""TemporaryDefinition"":""A sleepy animal that sleeps, sleeps and sleeps some more and is a common role model for teenagers who spend all their days sleeping. No sheep are counted anymore because there wouldn't be enough for all the sleeping that is done and given the environmental crisis, sloths are a more environmental choice."", ""PermanentDefinition"": ""An animal that likes sleeping"",  ""Status"": {(int)WordStatus.Permanent}}},
                    {{""Word"":""pelican"",""TemporaryDefinition"":""A large bird with one heck of a bill, I wonder if such a big bill causes problems? Adults find this relatable because they have entered the real world and also have big bills."", ""PermanentDefinition"": ""A bird with a big beak"", ""Status"": {(int)WordStatus.Permanent}}},
                    {{""Word"":""lion"",""TemporaryDefinition"":""{TestFileHelper.LionTemporaryDefinition}"", ""PermanentDefinition"": ""{TestFileHelper.LionPermanentDefinition}"", ""Status"": {(int)WordStatus.Temporary}}},
                    {{""Word"":""boxing"",""TemporaryDefinition"":""{TestFileHelper.BoxingTemporaryDefinition}"", ""PermanentDefinition"": null, ""Status"": {(int)WordStatus.Suffix}}},
                    {{""Word"":""dodo"",""TemporaryDefinition"": null, ""PermanentDefinition"": ""{TestFileHelper.DodoPermanentDefinition}"", ""Status"": {(int)WordStatus.DoesNotExist}}},
                    {{""Word"":""unicorn"",""TemporaryDefinition"":""{TestFileHelper.UnicornTemporaryDefinition}"", ""PermanentDefinition"": null, ""Status"": {(int)WordStatus.DoesNotExist}}},
                    {{""Word"":""dinosaur"",""TemporaryDefinition"": null, ""PermanentDefinition"": null, ""Status"": {(int)WordStatus.DoesNotExist}}}
                ]
            }}");
        }
        public void WhenNoDefinitionIsEnteredTheWordShouldStillBeWritten()
        {
            var newWord             = "news";
            var temporaryDefinition = "";

            _temporaryDefinitionHelper = new TemporaryDefinitionHelper(_fileHelper);
            _temporaryDefinitionHelper.AutomaticallySetTemporaryDefinitionForWord(_dictionary, newWord, temporaryDefinition);
            _wordService.UpdateDictionaryFile();

            var response = TestFileHelper.Read(Filename);

            var dictionary = JsonConvert.DeserializeObject <Dictionary>(response);

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = newWord,
                PermanentDefinition = null,
                TemporaryDefinition = temporaryDefinition,
                Status = WordStatus.Suffix
            });
        }
Ejemplo n.º 17
0
        public void WhenNoDefinitionIsEnteredTheWordShouldStillBeWritten()
        {
            var newWord       = "new";
            var newDefinition = "";

            _wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
            _wordService.AddNewWordToDictionary(Filename, newWord, newDefinition);
            _wordService.UpdateDictionaryFile();

            var response = TestFileHelper.Read(Filename);

            var dictionary = JsonConvert.DeserializeObject <Dictionary>(response);

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = newWord,
                PermanentDefinition = newDefinition,
                TemporaryDefinition = null,
                Status = WordStatus.Permanent
            });
        }
        public void WhenAWordAndDefinitionAreSetTheWordShouldBeAddedToTheDictionary()
        {
            var newWord             = "news";
            var temporaryDefinition = "Something that has only just come into existence";

            _temporaryDefinitionHelper = new TemporaryDefinitionHelper(_fileHelper);
            _temporaryDefinitionHelper.AutomaticallySetTemporaryDefinitionForWord(_dictionary, newWord, temporaryDefinition);
            _wordService.UpdateDictionaryFile();

            var response = TestFileHelper.Read(Filename);

            var dictionary = JsonConvert.DeserializeObject <Dictionary>(response);

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = newWord,
                PermanentDefinition = null,
                TemporaryDefinition = temporaryDefinition,
                Status = WordStatus.Suffix
            });
        }
Ejemplo n.º 19
0
        public void WhenADefinitionIsSetThenItShouldBeWrittenToTheDictionary()
        {
            var newWord       = "new";
            var newDefinition = "Something that has only just come into existence";

            _wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
            _wordService.AddNewWordToDictionary(Filename, newWord, newDefinition);
            _wordService.UpdateDictionaryFile();

            var response = TestFileHelper.Read(Filename);

            var dictionary = JsonConvert.DeserializeObject <Dictionary>(response);

            dictionary.Words.Should().ContainEquivalentOf(new WordData
            {
                Word = newWord,
                PermanentDefinition = newDefinition,
                TemporaryDefinition = null,
                Status = WordStatus.Permanent
            });
        }
Ejemplo n.º 20
0
        public WordStatusTests()
        {
            _filenameHelper = Substitute.For <IFilenameHelper>();
            _filenameHelper
            .GetGuessedWordsFilename()
            .Returns(Filename);

            _filenameHelper
            .GetDictionaryFilename()
            .Returns(Filename);

            TestFileHelper.Create(Filename);
            var json = TestFileHelper.Read(Filename);

            _wordDefinitionHelper = Substitute.For <IWordDefinitionHelper>();
            _wordExistenceHelper  = Substitute.For <IWordExistenceHelper>();
            _wordHelper           = Substitute.For <IWordHelper>();
            _fileHelper           = new FileHelper();

            _wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
            _dictionary  = _wordService.GetDictionary();
        }
Ejemplo n.º 21
0
        public void WhenWordExistsInGuessedWordsButHasADifferentStatusThenTheStatusShouldBeUpdated()
        {
            var originalGuessedWords = new GuessedWords();

            originalGuessedWords.AddWord(_words[0], WordStatus.Temporary);

            TestFileHelper.CreateCustomFile(GuessedWordsFilename, originalGuessedWords);

            _wordService.AddWordToGuessedWords(DictionaryFilename, GuessedWordsFilename, _words[0]);
            _wordService.UpdateGuessedWordsFile();

            var json         = TestFileHelper.Read(GuessedWordsFilename);
            var guessedWords = JsonConvert.DeserializeObject <GuessedWords>(json);

            guessedWords
            .Words
            .Should()
            .BeEquivalentTo(new List <GuessedWord>
            {
                new GuessedWord(_words[0], WordStatus.Permanent)
            });
        }
        public void WhenWordExistsUpdateDefinitionThePermanentDefinitionShouldBeUpdated()
        {
            var newDefinition = "A cloud like fluffy animal";
            var word          = "sheep";

            _wordService.UpdateExistingWord(Filename, word, newDefinition);
            _wordService.UpdateDictionaryFile();

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

            dictionary
            .Words
            .Should()
            .ContainEquivalentOf(new WordData
            {
                Word = word,
                PermanentDefinition = newDefinition,
                TemporaryDefinition = TempDefinition,
                Status = WordStatus.Permanent
            });
        }
        public AutomaticallyAddNewWordToDictionaryTests()
        {
            _wordDefinitionHelper = Substitute.For <IWordDefinitionHelper>();
            _wordExistenceHelper  = Substitute.For <IWordExistenceHelper>();
            _wordHelper           = Substitute.For <IWordHelper>();
            _filenameHelper       = Substitute.For <IFilenameHelper>();
            _filenameHelper.GetDictionaryFilename().Returns(Filename);
            _filenameHelper.GetGuessedWordsFilename().Returns(Filename);
            _fileHelper = new FileHelper();


            if (File.Exists(Filename))
            {
                File.Delete(Filename);
            }

            TestFileHelper.Create(Filename);
            _wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
            var json = TestFileHelper.Read(Filename);

            _dictionary = _wordService.GetDictionary();
        }
        public void WhenUpdateHappensAndDefinitionIsEmptyDefinitionShouldNotBeChanged()
        {
            var newDefinition = "";
            var word          = "sheep";

            _wordService.UpdateExistingWord(Filename, word, newDefinition);
            _wordService.UpdateDictionaryFile();

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

            dictionary
            .Words
            .Should()
            .ContainEquivalentOf(new WordData
            {
                Word = word,
                PermanentDefinition = PermDefinition,
                TemporaryDefinition = TempDefinition,
                Status = WordStatus.Permanent
            });
        }
Ejemplo n.º 25
0
        public void AllWordsGuessedAndTheirStatusesShouldBeAddedToGuessedWordsList()
        {
            _wordService.AddWordToGuessedWords(DictionaryFilename, GuessedWordsFilename, _words[0]);
            _wordService.AddWordToGuessedWords(DictionaryFilename, GuessedWordsFilename, _words[1]);
            _wordService.AddWordToGuessedWords(DictionaryFilename, GuessedWordsFilename, _words[2]);
            _wordService.AddWordToGuessedWords(DictionaryFilename, GuessedWordsFilename, _words[3]);
            _wordService.UpdateGuessedWordsFile();

            var json         = TestFileHelper.Read(GuessedWordsFilename);
            var guessedWords = JsonConvert.DeserializeObject <GuessedWords>(json);



            guessedWords
            .Words
            .Should()
            .BeEquivalentTo(new List <GuessedWord>
            {
                new GuessedWord(_words[0], WordStatus.Permanent),
                new GuessedWord(_words[1], WordStatus.Temporary),
                new GuessedWord(_words[2], WordStatus.Suffix),
                new GuessedWord(_words[3], WordStatus.DoesNotExist)
            });
        }