TimeTests.cs
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using NUnit.Framework;
using System;
namespace UniJSON.MsgPack
{
public class TimeTests
{
[Test]
public void TimeTest()
{
var f = new MsgPackFormatter();
{
f.GetStore().Clear();
var time = new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero);
f.Value(time);
var bytes = f.GetStoreBytes().ArrayOrCopy();
unchecked
{
Assert.AreEqual(new byte[]
{
(byte)MsgPackType.FIX_EXT_4, (byte)-1, 0, 0, 0, 0
}, bytes);
}
var parsed = MsgPackParser.Parse(bytes).GetValue();
Assert.AreEqual(time, parsed);
}
{
var time = new DateTimeOffset(2018, 12, 8, 2, 12, 15, TimeSpan.Zero);
Assert.AreEqual(1544235135, time.ToUnixTimeSeconds());
f.GetStore().Clear();
f.Value(time);
var bytes = f.GetStoreBytes().ArrayOrCopy();
var parsed = MsgPackParser.Parse(bytes).GetValue();
Assert.AreEqual(time, parsed);
}
{
f.GetStore().Clear();
Assert.Catch(() =>
{
f.Value(new DateTimeOffset());
});
}
}
}
}