UniVRM/UniJSON/Editor/Tests/MsgPack/TimeTests.cs
ousttrue df85433628 Merge commit 'df5f79584312cf4f6cc7ec1d73a78f6ba475c9ad' as 'UniJSON'
Co-authored-by: Deatrathias <dmailsec@gmail.com>
Co-authored-by: dj-kusuha <dj.kusuha+github@gmail.com>
Co-authored-by: ousttrue <ousttrue@gmail.com>
Co-authored-by: yutopp <yutopp@gmail.com>
2018-12-28 20:38:39 +09:00

51 lines
1.4 KiB
C#

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