public void Initialize() { MyStringICollectionWrapper = new StringICollectionWrapper() { "Hello" }; MyStringIListWrapper = new StringIListWrapper() { "Hello" }; MyStringISetWrapper = new StringISetWrapper() { "Hello" }; MyStringToStringIDictionaryWrapper = new StringToStringIDictionaryWrapper() { { "key", "value" } }; MyStringListWrapper = new StringListWrapper() { "Hello" }; MyStringStackWrapper = new StringStackWrapper(new List <string> { "Hello" }); MyStringQueueWrapper = new StringQueueWrapper(new List <string> { "Hello" }); MyStringHashSetWrapper = new StringHashSetWrapper() { "Hello" }; MyStringLinkedListWrapper = new StringLinkedListWrapper(new List <string> { "Hello" }); MyStringSortedSetWrapper = new StringSortedSetWrapper() { "Hello" }; MyStringToStringDictionaryWrapper = new StringToStringDictionaryWrapper() { { "key", "value" } }; MyStringToStringSortedDictionaryWrapper = new StringToStringSortedDictionaryWrapper() { { "key", "value" } }; MyStringToGenericDictionaryWrapper = new StringToGenericDictionaryWrapper <StringToGenericDictionaryWrapper <string> >() { { "key", new StringToGenericDictionaryWrapper <string>() { { "key", "value" } } } }; }
public static void ImplementsDictionary_DictionaryOfString() { const string JsonString = @"{""Hello"":""World"",""Hello2"":""World2""}"; const string ReorderedJsonString = @"{""Hello2"":""World2"",""Hello"":""World""}"; { WrapperForIDictionary obj = JsonSerializer.Deserialize <WrapperForIDictionary>(JsonString); Assert.Equal("World", ((JsonElement)obj["Hello"]).GetString()); Assert.Equal("World2", ((JsonElement)obj["Hello2"]).GetString()); string json = JsonSerializer.Serialize(obj); Assert.Equal(JsonString, json); json = JsonSerializer.Serialize <object>(obj); Assert.Equal(JsonString, json); } { StringToStringDictionaryWrapper obj = JsonSerializer.Deserialize <StringToStringDictionaryWrapper>(JsonString); Assert.Equal("World", obj["Hello"]); Assert.Equal("World2", obj["Hello2"]); string json = JsonSerializer.Serialize(obj); Assert.Equal(JsonString, json); json = JsonSerializer.Serialize <object>(obj); Assert.Equal(JsonString, json); } { StringToStringSortedDictionaryWrapper obj = JsonSerializer.Deserialize <StringToStringSortedDictionaryWrapper>(JsonString); Assert.Equal("World", obj["Hello"]); Assert.Equal("World2", obj["Hello2"]); string json = JsonSerializer.Serialize(obj); Assert.Equal(JsonString, json); json = JsonSerializer.Serialize <object>(obj); Assert.Equal(JsonString, json); } { StringToStringIDictionaryWrapper obj = JsonSerializer.Deserialize <StringToStringIDictionaryWrapper>(JsonString); Assert.Equal("World", obj["Hello"]); Assert.Equal("World2", obj["Hello2"]); string json = JsonSerializer.Serialize(obj); Assert.Equal(JsonString, json); json = JsonSerializer.Serialize <object>(obj); Assert.Equal(JsonString, json); } { Assert.Throws <JsonException>(() => JsonSerializer.Deserialize <StringToStringIReadOnlyDictionaryWrapper>(JsonString)); StringToStringIReadOnlyDictionaryWrapper obj = new StringToStringIReadOnlyDictionaryWrapper(new Dictionary <string, string>() { { "Hello", "World" }, { "Hello2", "World2" }, }); string json = JsonSerializer.Serialize(obj); Assert.Equal(JsonString, json); json = JsonSerializer.Serialize <object>(obj); Assert.Equal(JsonString, json); } { Assert.Throws <JsonException>(() => JsonSerializer.Deserialize <StringToStringIImmutableDictionaryWrapper>(JsonString)); StringToStringIImmutableDictionaryWrapper obj = new StringToStringIImmutableDictionaryWrapper(new Dictionary <string, string>() { { "Hello", "World" }, { "Hello2", "World2" }, }); string json = JsonSerializer.Serialize(obj); Assert.True(JsonString == json || ReorderedJsonString == json); json = JsonSerializer.Serialize <object>(obj); Assert.True(JsonString == json || ReorderedJsonString == json); } { HashtableWrapper obj = JsonSerializer.Deserialize <HashtableWrapper>(JsonString); Assert.Equal("World", ((JsonElement)obj["Hello"]).GetString()); Assert.Equal("World2", ((JsonElement)obj["Hello2"]).GetString()); string json = JsonSerializer.Serialize(obj); Assert.True(JsonString == json || ReorderedJsonString == json); json = JsonSerializer.Serialize <object>(obj); Assert.True(JsonString == json || ReorderedJsonString == json); } { SortedListWrapper obj = JsonSerializer.Deserialize <SortedListWrapper>(JsonString); Assert.Equal("World", ((JsonElement)obj["Hello"]).GetString()); Assert.Equal("World2", ((JsonElement)obj["Hello2"]).GetString()); string json = JsonSerializer.Serialize(obj); Assert.Equal(JsonString, json); json = JsonSerializer.Serialize <object>(obj); Assert.Equal(JsonString, json); } }