Пример #1
0
        static void TestDate(DateTime when)
        {
            long ticks = (when - origin).Ticks;

            byte[] bits = BitConverter.GetBytes(ticks);
            if (!BitConverter.IsLittleEndian)
            {
                Array.Reverse(bits);
            }
            Array.Resize(ref bits, bits.Length + 1);
            Buffer.BlockCopy(bits, 0, bits, 1, bits.Length - 1);
            bits[0] = 9;

            Int64Fixed i64 = new Int64Fixed {
                Value = ticks
            };

            Assert.IsTrue(Program.CheckBytes(i64, bits));

            Int64Fixed i64Clone = Serializer.DeepClone(i64);

            Assert.AreEqual(ticks, i64Clone.Value, "Int64 roundtrip:" + ticks.ToString() + " (" + when.ToString() + ")");

            DateTimeFixed val = new DateTimeFixed {
                When = when
            },
                          clone = ProtoBuf.Serializer.DeepClone(val);

            Assert.AreEqual(val.When, clone.When, "DateTime roundtrip:" + when.ToString());

            i64 = Serializer.ChangeType <DateTimeFixed, Int64Fixed>(val);

            Assert.AreEqual(ticks, i64.Value, "Wire value:" + when.ToString());
        }
        static void TestDate(DateTime when)
        {
            long ticks = (when - origin).Ticks;

            byte[] bits = BitConverter.GetBytes(ticks);
            if (!BitConverter.IsLittleEndian)
            {
                Array.Reverse(bits);
            }
            Array.Resize(ref bits, bits.Length + 1);
            Buffer.BlockCopy(bits, 0, bits, 1, bits.Length - 1);
            bits[0] = 9;

            Int64Fixed i64 = new Int64Fixed { Value = ticks };
            Assert.IsTrue(Program.CheckBytes(i64, bits));

            Int64Fixed i64Clone = Serializer.DeepClone(i64);
            Assert.AreEqual(ticks, i64Clone.Value, "Int64 roundtrip:" + ticks.ToString() + " (" + when.ToString() + ")");

            DateTimeFixed val = new DateTimeFixed { When = when},
                clone = ProtoBuf.Serializer.DeepClone(val);
            Assert.AreEqual(val.When, clone.When, "DateTime roundtrip:" + when.ToString());

            i64 = Serializer.ChangeType<DateTimeFixed, Int64Fixed>(val);

            Assert.AreEqual(ticks, i64.Value, "Wire value:" + when.ToString());
        }
Пример #3
0
        public void TestFixedOnly()
        {
            var when = new DateTime(2010, 05, 17, 8, 30, 0);

            DateTimeFixed val = new DateTimeFixed {
                When = when
            };
            var  i64   = Serializer.ChangeType <DateTimeFixed, Int64Fixed>(val);
            long ticks = (when - origin).Ticks;

            Assert.AreEqual(ticks, i64.Value, "Wire value:" + when.ToString());
        }
Пример #4
0
        public void TestFixedOnly()
        {
            var when = new DateTime(2010, 05, 17, 8, 30, 0);

            DateTimeFixed val = new DateTimeFixed { When = when };
            var i64 = Serializer.ChangeType<DateTimeFixed, Int64Fixed>(val);
            long ticks = (when - origin).Ticks;
            Assert.AreEqual(ticks, i64.Value, "Wire value:" + when.ToString());
        }