Exemplo n.º 1
0
        public void Test_PocoComplexNotInitialized()
        {
            var val = new PocoComplex();

            var buf    = BinaryConvert.SerializeObject(val);
            var cloned = BinaryConvert.DeserializeObject <PocoComplex>(buf);

            Assert.AreEqual(val, cloned);
        }
Exemplo n.º 2
0
        public void Test_PocoComplex()
        {
            var val = new PocoComplex()
            {
                Id        = 7,
                Time1     = new DateTime((DateTime.UtcNow.Ticks / TimeSpan.TicksPerSecond) * TimeSpan.TicksPerSecond),
                Comment   = null,//"Bla!",
                SubRecord = new PocoWithAllPrimitives()
                {
                    Byte   = 1,
                    SByte  = -2,
                    Int16  = -3,
                    UInt16 = 4,
                    Int32  = 5,
                    UInt32 = 6,
                    Int64  = 7,
                    UInt64 = 8,
                    Char   = 'a',
                },
                Dec1     = 1234567890.954m,
                Real32   = 17890.9f,
                Real64   = 167890.1,
                TestEnum = TestEnum.Val1,
                IntList  = new List <int> {
                    1, 4, 9, 16
                },
                SubRecordList = new List <PocoWithAllPrimitives>
                {
                    new PocoWithAllPrimitives()
                    {
                        Byte   = 11,
                        SByte  = -12,
                        Int16  = -13,
                        UInt16 = 14,
                        Int32  = 15,
                        UInt32 = 16,
                        Int64  = 17,
                        UInt64 = 18,
                        Char   = 'b',
                    }
                },
                IntDict = new Dictionary <int, int>
                {
                    { 0, 0 },
                    { 1, 1 },
                    { 2, 4 },
                    { 3, 9 },
                    { 4, 16 },
                },
                SubRecordDict = new Dictionary <string, PocoSimple>
                {
                    { "key1", new PocoSimple {
                          Int = 1, Str = null
                      } },
                    { "key2", new PocoSimple {
                          Int = -1, Str = "str"
                      } },
                }
            };

            var buf    = BinaryConvert.SerializeObject(val);
            var cloned = BinaryConvert.DeserializeObject <PocoComplex>(buf);

            Assert.AreEqual(val, cloned);
        }
Exemplo n.º 3
0
        public void Test_PocoComplex()
        {
            var val = new PocoComplex()
            {
                Id        = 7,
                Time1     = new DateTime((DateTime.UtcNow.Ticks / TimeSpan.TicksPerSecond) * TimeSpan.TicksPerSecond),
                Comment   = null,//"Bla!",
                SubRecord = new PocoWithAllPrimitives()
                {
                    Byte   = 1,
                    SByte  = -2,
                    Int16  = -3,
                    UInt16 = 4,
                    Int32  = 5,
                    UInt32 = 6,
                    Int64  = 7,
                    UInt64 = 8,
                    Char   = 'a',
                },
                Dec1     = 1234567890.954m,
                Real32   = 17890.9f,
                Real64   = 167890.1,
                TestEnum = TestEnum.Val1,
                TupleN2  = new Tuple <int, string>(1, "1"),
                IntList  = new List <int> {
                    1, 4, 9, 16
                },
                SubRecordList = new List <PocoWithAllPrimitives>
                {
                    new PocoWithAllPrimitives()
                    {
                        Byte   = 11,
                        SByte  = -12,
                        Int16  = -13,
                        UInt16 = 14,
                        Int32  = 15,
                        UInt32 = 16,
                        Int64  = 17,
                        UInt64 = 18,
                        Char   = 'b',
                    }
                },
                IntDict = new Dictionary <int, int>
                {
                    { 0, 0 },
                    { 1, 1 },
                    { 2, 4 },
                    { 3, 9 },
                    { 4, 16 },
                },
                SubRecordDict = new Dictionary <string, PocoSimple>
                {
                    { "key1", new PocoSimple {
                          Int = 1, Str = null
                      } },
                    { "key2", new PocoSimple {
                          Int = -1, Str = "str"
                      } },
                },
                ByteArray2 = new byte[0],
                ByteArray3 = new byte[10] {
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10
                },
                StringArray = new string[3] {
                    "1", null, "3"
                },
                Guid = new Guid("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4"),
            };

            //for (int i = 0; i < 100_000; i++)
            {
                var jsonLen = JsonConvert.SerializeObject(val).Length;

                var buf    = BinaryConvert.SerializeObject(val);
                var cloned = BinaryConvert.DeserializeObject <PocoComplex>(buf);

                Assert.AreEqual(val, cloned);
                Assert.AreEqual(val.TupleN2, cloned.TupleN2);
            }
        }
        public void Test_ClassMapSerializerArgTime()
        {
            SerializerRegistry.RegisterClassMap(typeof(PocoComplex), new ClassMap <PocoComplex>(cm =>
            {
                cm.MapProperty(p => p.Time1).SerializerArg = new DateTimeSerializerArg()
                {
                    TickResolution = TimeSpan.TicksPerDay
                };
                cm.MapProperty(p => p.Time2).SerializerArg = new DateTimeSerializerArg()
                {
                    TickResolution = TimeSpan.TicksPerMinute
                };
            }));

            var val = new PocoComplex()
            {
                Id        = 7,
                Time1     = new DateTime(2010, 10, 10, 10, 10, 10),
                Time2     = new DateTime(2010, 10, 10, 10, 10, 10),
                Comment   = null,//"Bla!",
                SubRecord = new PocoWithAllPrimitives()
                {
                    Byte   = 1,
                    SByte  = -2,
                    Int16  = -3,
                    UInt16 = 4,
                    Int32  = 5,
                    UInt32 = 6,
                    Int64  = 7,
                    UInt64 = 8,
                    Char   = 'a',
                },
                Dec1     = 1234567890.954m,
                Real32   = 17890.9f,
                Real64   = 167890.1,
                TestEnum = TestEnum.Val1,
                IntList  = new List <int> {
                    1, 4, 9, 16
                },
                SubRecordList = new List <PocoWithAllPrimitives>
                {
                    new PocoWithAllPrimitives()
                    {
                        Byte   = 11,
                        SByte  = -12,
                        Int16  = -13,
                        UInt16 = 14,
                        Int32  = 15,
                        UInt32 = 16,
                        Int64  = 17,
                        UInt64 = 18,
                        Char   = 'b',
                    }
                },
                IntDict = new Dictionary <int, int>
                {
                    { 0, 0 },
                    { 1, 1 },
                    { 2, 4 },
                    { 3, 9 },
                    { 4, 16 },
                },
                SubRecordDict = new Dictionary <string, PocoSimple>
                {
                    { "key1", new PocoSimple {
                          Int = 1, Str = null
                      } },
                    { "key2", new PocoSimple {
                          Int = -1, Str = "str"
                      } },
                }
            };

            var buf    = BinaryConvert.SerializeObject(val);
            var cloned = BinaryConvert.DeserializeObject <PocoComplex>(buf);

            Assert.AreEqual(val, cloned); //Note: comparer use class map, so ite return equal even that they are not!

            Assert.AreEqual(cloned.Time1.Second, 0);
            Assert.AreEqual(cloned.Time1.Minute, 0);
            Assert.AreEqual(cloned.Time1.Hour, 0);

            Assert.AreEqual(cloned.Time2.Second, 0);
            Assert.AreEqual(cloned.Time2.Minute, 10);
            Assert.AreEqual(cloned.Time2.Hour, 10);
        }