示例#1
0
        public void TestValueTimeUnit()
        {
            TimeSpanOnly ts = Program.Build <TimeSpanOnly>(0x0A, 0x04,  // tag 1 string, 4 bytes
                                                           0x08, 0x08,  // tag 1; value: 4 (zigzag)
                                                           0x10, 0x01); // tag 2; unit: hour

            Assert.AreEqual(new TimeSpan(4, 0, 0), ts.HowLong);
        }
示例#2
0
 public void TestInvalidMinMax()
 {
     Program.ExpectFailure <ProtoException>(() =>
     {
         TimeSpanOnly ts = Program.Build <TimeSpanOnly>(0x0A, 0x04,  // tag 1 string, 4 bytes
                                                        0x08, 0x03,  // tag 1; invalid
                                                        0x10, 0x0F); // tag 2; min/max
     });
 }
示例#3
0
 public void TestInvalidTimeUnit()
 {
     Program.ExpectFailure <ProtoException>(() =>
     {
         TimeSpanOnly ts = Program.Build <TimeSpanOnly>(0x0A, 0x04,  // tag 1 string, 4 bytes
                                                        0x08, 0x08,  // tag 1; value: 4 (zigzag)
                                                        0x10, 0x4A); // tag 2; unit: invalid
     });
 }
示例#4
0
        public void TestValidMinMax()
        {
            TimeSpanOnly ts = Program.Build <TimeSpanOnly>(0x0A, 0x04,  // tag 1 string, 4 bytes
                                                           0x08, 0x02,  // tag 1; value: 1 (zigzag)
                                                           0x10, 0x0F); // tag 2; min/max

            Assert.AreEqual(TimeSpan.MaxValue, ts.HowLong);

            ts = Program.Build <TimeSpanOnly>(0x0A, 0x04,  // tag 1 string, 4 bytes
                                              0x08, 0x01,  // tag 1; value: -1 (zigzag)
                                              0x10, 0x0F); // tag 2; min/max

            Assert.AreEqual(TimeSpan.MinValue, ts.HowLong);
        }
示例#5
0
        static TimeSpan TestTimeSpan(TimeSpan value, out int len)
        {
            TimeSpanOnly p = new TimeSpanOnly {
                HowLong = value
            };

            using (MemoryStream ms = new MemoryStream())
            {
                Serializer.Serialize(ms, p);
                ms.Position = 0;
                p           = Serializer.Deserialize <TimeSpanOnly>(ms);
                len         = (int)ms.Length;
                return(p.HowLong);
            }
        }
示例#6
0
        static TimeSpan TestTimeSpan(TimeSpan value, out int len)
        {
            TimeSpanOnly p = new TimeSpanOnly {
                HowLong = value
            };

            using (MemoryStream ms = new MemoryStream())
            {
                var tm = TypeModel.Create(false, ProtoCompatibilitySettingsValue.FullCompatibility);
                tm.Serialize(ms, p);
                ms.Position = 0;
                p           = tm.Deserialize <TimeSpanOnly>(ms);
                len         = (int)ms.Length;
                return(p.HowLong);
            }
        }
示例#7
0
 static TimeSpan TestTimeSpan(TimeSpan value, out int len)
 {
     TimeSpanOnly p = new TimeSpanOnly { HowLong = value };
     using (MemoryStream ms = new MemoryStream())
     {
         Serializer.Serialize(ms, p);
         ms.Position = 0;
         p = Serializer.Deserialize<TimeSpanOnly>(ms);
         len = (int)ms.Length;
         return p.HowLong;
     }
 }
示例#8
0
 public void TestInvalidMinMax()
 {
     TimeSpanOnly ts = Program.Build <TimeSpanOnly>(0x0A, 0x04,  // tag 1 string, 4 bytes
                                                    0x08, 0x03,  // tag 1; invalid
                                                    0x10, 0x0F); // tag 2; min/max
 }
示例#9
0
 public void TestInvalidTimeUnit()
 {
     TimeSpanOnly ts = Program.Build <TimeSpanOnly>(0x0A, 0x04,  // tag 1 string, 4 bytes
                                                    0x08, 0x08,  // tag 1; value: 4 (zigzag)
                                                    0x10, 0x4A); // tag 2; unit: invalid
 }