예제 #1
0
        public async Task ArrayDictionaryLoop()
        {
            ListWithGenericCycleWithinDictionary root = new ListWithGenericCycleWithinDictionary();

            root.Add(new Dictionary <string, ListWithGenericCycleWithinDictionary> {
                { "Root", root }
            });

            string expected = JsonConvert.SerializeObject(root, s_newtonsoftSerializerSettingsPreserve);
            string actual   = await JsonSerializerWrapperForString.SerializeWrapper(root, s_serializerOptionsPreserve);

            Assert.Equal(expected, actual);

            ListWithGenericCycleWithinDictionary rootCopy = await JsonSerializerWrapperForString.DeserializeWrapper <ListWithGenericCycleWithinDictionary>(actual, s_serializerOptionsPreserve);

            Assert.Same(rootCopy, rootCopy[0]["Root"]);
        }
예제 #2
0
        public static void ArrayDictionaryLoop()
        {
            ListWithGenericCycleWithinDictionary root = new ListWithGenericCycleWithinDictionary();

            root.Add(new Dictionary <string, ListWithGenericCycleWithinDictionary> {
                { "Root", root }
            });

            string expected = JsonConvert.SerializeObject(root, s_newtonsoftSerializerSettingsPreserve);
            string actual   = JsonSerializer.Serialize(root, s_serializerOptionsPreserve);

            Assert.Equal(expected, actual);

            ListWithGenericCycleWithinDictionary rootCopy = JsonSerializer.Deserialize <ListWithGenericCycleWithinDictionary>(actual, s_serializerOptionsPreserve);

            Assert.Same(rootCopy, rootCopy[0]["Root"]);
        }
예제 #3
0
        public async Task ArrayPreserveDuplicateDictionaries()
        {
            ListWithGenericCycleWithinDictionary root = new ListWithGenericCycleWithinDictionary
            {
                new Dictionary <string, ListWithGenericCycleWithinDictionary>()
            };

            root.Add(root[0]);

            string expected = JsonConvert.SerializeObject(root, s_newtonsoftSerializerSettingsPreserve);
            string actual   = await JsonSerializerWrapperForString.SerializeWrapper(root, s_serializerOptionsPreserve);

            Assert.Equal(expected, actual);

            ListWithGenericCycleWithinDictionary rootCopy = await JsonSerializerWrapperForString.DeserializeWrapper <ListWithGenericCycleWithinDictionary>(actual, s_serializerOptionsPreserve);

            Assert.Same(rootCopy[0], rootCopy[1]);
        }
예제 #4
0
        public static void ArrayPreserveDuplicateDictionaries()
        {
            ListWithGenericCycleWithinDictionary root = new ListWithGenericCycleWithinDictionary
            {
                new Dictionary <string, ListWithGenericCycleWithinDictionary>()
            };

            root.Add(root[0]);

            string expected = JsonConvert.SerializeObject(root, s_newtonsoftSerializerSettingsPreserve);
            string actual   = JsonSerializer.Serialize(root, s_serializerOptionsPreserve);

            Assert.Equal(expected, actual);

            ListWithGenericCycleWithinDictionary rootCopy = JsonSerializer.Deserialize <ListWithGenericCycleWithinDictionary>(actual, s_serializerOptionsPreserve);

            Assert.Same(rootCopy[0], rootCopy[1]);
        }