Beispiel #1
0
        public void TestJsonLongListStr()
        {
            var list1 = new SampleList {
                E = new List <string>()
            };

            for (int i = 0; i < 100000; ++i)
            {
                list1.E.Add(i.ToString());
            }

            var js      = new JsonSerializer();
            var result1 = js.ToString(list1);

            Assert.IsTrue(result1 != "");

            var list2 = new SampleList();
            var jd    = new JsonDeserializer();

            jd.FromString(list2, result1);
            Assert.AreEqual(list1.E.Count, list2.E.Count);

            var jdg   = new SampleList_JsonDeserializer();
            var list3 = (SampleList)jdg.FromString(result1);

            Assert.AreEqual(list1.E.Count, list3.E.Count);
        }
Beispiel #2
0
        public void TestProtobufNetLongListStr()
        {
            var list1 = new SampleList {
                E = new List <string>()
            };

            for (int i = 0; i < 100000; ++i)
            {
                list1.E.Add(i.ToString());
            }

            var ms = new MemoryStream();

            ProtoBuf.Serializer.Serialize(ms, list1);
            Assert.IsTrue(ms.Length > 0);

            ms.Position = 0;
            var list2 = ProtoBuf.Serializer.Deserialize <SampleList>(ms);

            Assert.AreEqual(list1.E.Count, list2.E.Count);
        }
Beispiel #3
0
 public void TestCollection()
 {
     TestGen(cl => {
         var src = new List <string> {
             "s1", "s2"
         };
         var dst = cl.Deep(src);
         Assert.AreNotEqual(src, dst);
         CollectionAssert.AreEqual(src, dst);
     });
     TestGen(cl => {
         var src = new List <Sample1> {
             new Sample1 {
                 X = 34
             }
         };
         var dst = cl.Deep(src);
         Assert.AreNotEqual(src, dst);
         Assert.AreEqual(src.Count, dst.Count);
         Assert.AreNotEqual(src[0], dst[0]);
         Assert.AreEqual(src[0].X, dst[0].X);
     });
     TestGen(cl => {
         var src = new SampleList {
             E = new List <string> {
                 "sq"
             }
         };
         var dst = cl.Deep(src);
         Assert.AreNotEqual(src, dst);
         Assert.AreEqual(src.E.Count, dst.E.Count);
         Assert.AreNotEqual(src.E, dst.E);
         Assert.AreEqual(src.E[0], dst.E[0]);
     });
     TestGen(cl => {
         var src = new SampleMatrix {
             M = new List <List <int> > {
                 new List <int> {
                     1, 2, 3
                 },
                 new List <int> {
                     4
                 },
             }
         };
         var dst = cl.Deep(src);
         Assert.AreNotEqual(src, dst);
         Assert.AreNotEqual(src.M, dst.M);
         Assert.AreNotEqual(src.M[0], dst.M[0]);
         CollectionAssert.AreEqual(src.M[0], dst.M[0]);
         CollectionAssert.AreEqual(src.M[1], dst.M[1]);
     });
     TestGen(cl => {
         var src = new SampleCollection <int> {
             1, 5
         };
         var dst = cl.Deep(src);
         Assert.AreNotEqual(src, dst);
         int[] srcA = new int[2], dstA = new int[2];
         src.CopyTo(srcA, 0);
         dst.CopyTo(dstA, 0);
         CollectionAssert.AreEqual(srcA, dstA);
     });
     TestGen(cl => {
         var src = new SampleExplicitCollection <int>();
         ((ICollection <int>)src).Add(1);
         ((ICollection <int>)src).Add(5);
         var dst = cl.Deep(src);
         Assert.AreNotEqual(src, dst);
         CollectionAssert.AreEqual(src.ToList(), dst.ToList());
     });
 }