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