예제 #1
0
        static void Main(string[] args)
        {
            PrimitiveUnit.UnitTest();
            PrimitiveUnit.UnitTest2();
            PrimitiveUnit.UnitTestAsync().Wait();
            PrimitiveUnit.UnitTest2Async().Wait();

            Console.WriteLine($"{DateTime.Now} start generating serialization code for assembly");
            //This is not necessary but can accelerate following serializing
            Serializer.PrepareForAssembly(typeof(NestedUnit).Assembly);
            Serializer2.PrepareForAssembly(typeof(NestedUnit).Assembly);
            Console.WriteLine($"{DateTime.Now} end generating serialization code for assembly");

            OptionalFieldUnit.UnitTest();
            OptionalFieldUnit.UnitTest2();
            OptionalFieldUnit.UnitTestAsync().Wait();
            OptionalFieldUnit.UnitTest2Async().Wait();

            CollectionUnit.UnitTest();
            CollectionUnit.UnitTest2();
            CollectionUnit.UnitTestAsync().Wait();
            CollectionUnit.UnitTest2Async().Wait();

            RefUnit.UnitTest();

            PerformanceTest();

            Console.WriteLine($"{DateTime.Now} Unit test passed");
        }
예제 #2
0
        public static void UnitTest()
        {
            Console.WriteLine($"{DateTime.Now} Serializer2: start reference testing");
            using var mem = new MemoryStream();
            var serializer = new Serializer2(mem);

            var item1 = new RefUnit();

            item1.Dict1[1] = item1;
            item1.List1.Add(item1);
            item1.Array1[0] = item1;
            item1.Array2    = item1.Array1;
            item1.Dict2     = item1.Dict1;
            item1.List2     = item1.List1;
            item1.Str2      = item1.Str1;

            mem.Seek(0, SeekOrigin.Begin);
            serializer.Serialize(item1);
            mem.Seek(0, SeekOrigin.Begin);
            var item2 = serializer.Deserialize <RefUnit>();

            Debug.Assert(Object.ReferenceEquals(item2.Dict1[1], item2));
            Debug.Assert(Object.ReferenceEquals(item2.List1[0], item2));
            Debug.Assert(Object.ReferenceEquals(item2.Array1[0], item2));
            Debug.Assert(item2.Array1[1] == null);
            Debug.Assert(item2.Array1[2] == null);
            Debug.Assert(Object.ReferenceEquals(item2.Array1, item2.Array2));
            Debug.Assert(Object.ReferenceEquals(item2.Dict1, item2.Dict2));
            Debug.Assert(Object.ReferenceEquals(item2.List1, item2.List2));
            Debug.Assert(Object.ReferenceEquals(item2.Str1, item2.Str2));

            Console.WriteLine($"{DateTime.Now} Serializer2: end reference testing");
        }