Exemple #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);
        }
Exemple #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
     });
 }
Exemple #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
     });
 }
Exemple #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);
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
 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;
     }
 }
Exemple #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
 }
Exemple #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
 }