public void WhenWritingToAFileIfItDoesNotExistItShouldBeCreated() { var fileHelper = new Chat.WordGame.LocalDictionaryHelpers.FileHelper(); File.Exists(_filenameToCreate).Should().BeFalse(); fileHelper.WriteDictionary(_filenameToCreate, new Dictionary()); File.Exists(_filenameToCreate).Should().BeTrue(); }
public void WhenWritingContentTheContentShouldActuallyBeDeserializableToDictionary() { var fileHelper = new Chat.WordGame.LocalDictionaryHelpers.FileHelper(); var dictionary = new Dictionary { Words = new List <WordData> { new WordData { Word = "sheep", PermanentDefinition = "An animal with a wool laden coat", TemporaryDefinition = "A fluffy animal that sits", Status = WordStatus.Permanent }, new WordData { Word = "sloth", PermanentDefinition = "An animal that likes sleeping", TemporaryDefinition = "A sleepy animal that sleeps", Status = WordStatus.DoesNotExist } } }; fileHelper.WriteDictionary(_filename, dictionary); using (StreamReader r = new StreamReader(_filename)) { string json = r.ReadToEnd(); var dictionaryContent = JsonConvert.DeserializeObject <Dictionary>(json); dictionaryContent.Should().BeOfType <Dictionary>(); JToken.Parse(JsonConvert.SerializeObject(dictionaryContent)).Should().BeEquivalentTo($@" {{ ""Words"": [ {{ ""Word"": ""sheep"", ""PermanentDefinition"": ""An animal with a wool laden coat"", ""TemporaryDefinition"": ""A fluffy animal that sits"", ""Status"": {(int)WordStatus.Permanent}, ""Category"" : 0 }}, {{ ""Word"": ""sloth"", ""PermanentDefinition"": ""An animal that likes sleeping"", ""TemporaryDefinition"": ""A sleepy animal that sleeps"", ""Status"": {(int)WordStatus.DoesNotExist}, ""Category"" : 0 }} ] }}" ); } }