-
Notifications
You must be signed in to change notification settings - Fork 10
/
CryptoDateTests.cs
43 lines (38 loc) · 1.56 KB
/
CryptoDateTests.cs
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
using System;
using Crypto.Websocket.Extensions.Core.Utils;
using Xunit;
namespace Crypto.Websocket.Extensions.Tests
{
public class CryptoDateTests
{
[Theory]
[InlineData(1577573034.123456, "1577573034.123456")]
[InlineData(1577573034.123451, "1577573034.123451")]
[InlineData(0000000000.123456, "0.123456")]
[InlineData(0.0, "0.000000")]
public void UnixTimeConversion_ShouldSupportSixDecimalMilliseconds(double? timeInSec, string result)
{
var converted = CryptoDateUtils.ConvertFromUnixSeconds(timeInSec);
var convertedBack = converted.ToUnixSeconds();
var convertedString = converted.ToUnixSecondsString();
Assert.Equal(timeInSec, convertedBack);
Assert.Equal(result, convertedString);
}
[Fact]
public void UnixTimeConversionDecimal_ShouldSupportSixDecimalMilliseconds()
{
TestDecimal(1577573034.123456m, "1577573034.123456");
TestDecimal(1577573034.123451m, "1577573034.123451");
TestDecimal(0000000000.123456m, "0.123456");
TestDecimal(0m, "0.000000");
}
private static void TestDecimal(decimal? timeInSec, string result)
{
var converted = CryptoDateUtils.ConvertFromUnixSeconds(timeInSec);
var convertedBack = converted.ToUnixSecondsDecimal();
var convertedString = converted.ToUnixSecondsString();
Assert.Equal(timeInSec, convertedBack);
Assert.Equal(result, convertedString);
}
}
}