public void Serializer_roundtrips_type_with_dictionary_properties_whose_keys_are_strings_or_enums_without_manipulating_case_of_first_letter_in_string_key() { var expected = new DictionaryPropertiesTest { Names = new Dictionary <string, string> { { "Joe", "Locks" }, { "sally", "fields" } }, ReadOnlyNames = new ReadOnlyDictionary <string, string>( new Dictionary <string, string> { { "billy", "Bob" }, { "Harry", "wright" } }), NamesByColor = new Dictionary <Color, string> { { Color.Green, "Billy" }, { Color.White, "jean" } } }; var json = JsonConvert.SerializeObject(expected, JsonConfiguration.DefaultSerializerSettings); var actual = JsonConvert.DeserializeObject <DictionaryPropertiesTest>(json, JsonConfiguration.DefaultSerializerSettings); Assert.That(actual, Is.Not.Null); CollectionAssert.AreEquivalent(expected.Names, actual.Names); CollectionAssert.AreEquivalent(expected.ReadOnlyNames, actual.ReadOnlyNames); CollectionAssert.AreEquivalent(expected.NamesByColor, actual.NamesByColor); }
public static void Serializer_roundtrips_type_with_dictionary_properties_whose_keys_are_strings_or_enums_without_manipulating_case_of_first_letter_in_string_key() { var expected = new DictionaryPropertiesTest { Names = new Dictionary <string, string> { { "Joe", "Locks" }, { "sally", "fields" }, }, ReadOnlyNames = new ReadOnlyDictionary <string, string>( new Dictionary <string, string> { { "billy", "Bob" }, { "Harry", "wright" }, }), ColorsByNames = new Dictionary <string, Color> { { "billy", Color.Green }, { "Jean", Color.White }, }, NamesByColor = new Dictionary <Color, string> { { Color.Green, "Billy" }, { Color.White, "jean" }, }, }; var json = new ObcJsonSerializer().SerializeToString(expected); var actual = new ObcJsonSerializer().Deserialize <DictionaryPropertiesTest>(json); actual.Should().NotBeNull(); expected.Names.Should().BeEquivalentTo(actual.Names); expected.ReadOnlyNames.Should().BeEquivalentTo(actual.ReadOnlyNames); expected.ColorsByNames.Should().BeEquivalentTo(actual.ColorsByNames); expected.NamesByColor.Should().BeEquivalentTo(actual.NamesByColor); }