Пример #1
0
        public void DeepCircularReferenceError()
        {
            Serializer s = new Serializer();

            s.Settings.ReferenceWritingType = ReferenceOption.ErrorCircularReferences;
            string result = s.Serialize(deep);
            MockReferenceObject actual = s.Deserialize <MockReferenceObject>(result);
        }
Пример #2
0
        public void CircularReferenceWrite()
        {
            Serializer s = new Serializer();

            s.Settings.ReferenceWritingType = ReferenceOption.WriteIdentifier;
            string result = s.Serialize(simple);
            MockReferenceObject actual = s.Deserialize <MockReferenceObject>(result);

            Assert.AreSame(simple, simple.Reference.Reference, "References not equal");
        }
Пример #3
0
        public void DeepCircularReferenceIgnore()
        {
            Serializer s = new Serializer();

            s.Settings.ReferenceWritingType = ReferenceOption.IgnoreCircularReferences;
            string result = s.Serialize(deep);
            MockReferenceObject actual = s.Deserialize <MockReferenceObject>(result);

            Assert.IsNull(actual.Reference.Reference.Reference.Reference);
        }
Пример #4
0
        private void CreateSimpleReference()
        {
            simple = new MockReferenceObject();
            MockReferenceObject m2 = new MockReferenceObject();

            simple.Name      = "m1";
            m2.Name          = "m2";
            simple.Reference = m2;
            m2.Reference     = simple;
        }
Пример #5
0
        public void TestCollectionIndexReference()
        {
            MockReferenceObject[] mockArray = new MockReferenceObject[] { simple };
            Serializer            s         = new Serializer();

            s.Settings.ReferenceWritingType = ReferenceOption.WriteIdentifier;
            string result = s.Serialize(mockArray);

            MockReferenceObject[] actual = s.Deserialize <MockReferenceObject[]>(result);
            Assert.AreSame(actual[0], actual[0].Reference.Reference, "reference inside collection not equal");
        }
Пример #6
0
        public void BackwardsCompatibleDeepWrite()
        {
            Serializer s = new Serializer();

            s.Settings.ReferenceWritingType = ReferenceOption.WriteIdentifier;
            s.Settings.IsCompact            = true;
            string result = s.Serialize(deep);

            result = result.Replace("$['Reference']", "this.Reference");
            MockReferenceObject actual = s.Deserialize <MockReferenceObject>(result);

            Assert.AreSame(deep.Reference, deep.Reference.Reference.Reference.Reference, "References not equal");
        }
Пример #7
0
        public void TestBackwardsCompatibleReference()
        {
            Serializer s = new Serializer();

            s.Settings.ReferenceWritingType = ReferenceOption.WriteIdentifier;
            s.Settings.IsCompact            = true;
            string result = s.Serialize(simple);

            result = result.Replace("$", "this");
            MockReferenceObject actual = s.Deserialize <MockReferenceObject>(result);

            Assert.AreSame(simple, simple.Reference.Reference, "References not equal");
        }
Пример #8
0
        private void CreateDeepReference()
        {
            deep = new MockReferenceObject();
            MockReferenceObject m2 = new MockReferenceObject();
            MockReferenceObject m3 = new MockReferenceObject();
            MockReferenceObject m4 = new MockReferenceObject();

            deep.Name      = "m1";
            m2.Name        = "m2";
            m3.Name        = "m3";
            m4.Name        = "m4";
            deep.Reference = m2;
            m2.Reference   = m3;
            m3.Reference   = m4;
            m4.Reference   = m2;
        }