public AmendDictionaryTests()
        {
            var data = new Dictionary
            {
                Words = new List <WordData>
                {
                    new WordData
                    {
                        Word   = "pelican",
                        Status = WordStatus.Temporary,
                        PermanentDefinition = null,
                        TemporaryDefinition = null
                    }
                }
            };

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

            TestFileHelper.CreateCustomFile(Filename, data);
            _fileHelper  = new FileHelper();
            _wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
        }
        public void WhenReadingAnObjectFromTheFileResponseShouldBeDeserializableToTheObjectWritten()
        {
            var data = new GuessedWords();

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

            TestFileHelper.CreateCustomFile(Filename, data);

            var response = FileHelper.ReadFile(Filename);

            var serializedObject = JsonConvert.SerializeObject(data);

            response.Should().BeEquivalentTo(serializedObject);
        }
Example #3
0
        public AddWordToGuessedWordsTest()
        {
            _dictionary = new Dictionary
            {
                Words = new List <WordData>
                {
                    new WordData
                    {
                        Word = _words[0],
                        PermanentDefinition = null,
                        TemporaryDefinition = null,
                        Status = WordStatus.Permanent
                    },
                    new WordData
                    {
                        Word = _words[1],
                        PermanentDefinition = null,
                        TemporaryDefinition = null,
                        Status = WordStatus.Temporary
                    },
                    new WordData()
                    {
                        Word = _words[2],
                        PermanentDefinition = null,
                        TemporaryDefinition = null,
                        Status = WordStatus.Suffix
                    },
                    new WordData()
                    {
                        Word = _words[3],
                        PermanentDefinition = null,
                        TemporaryDefinition = null,
                        Status = WordStatus.DoesNotExist
                    }
                }
            };

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

            TestFileHelper.CreateCustomFile(GuessedWordsFilename, null);
            TestFileHelper.CreateCustomFile(DictionaryFilename, _dictionary);

            _wordService = new WordService(_wordExistenceHelper, _wordHelper, _wordDefinitionHelper, _fileHelper, _filenameHelper);
        }
Example #4
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)
            });
        }