forked from anthonyreilly/NetCoreForce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateFormatTests.cs
95 lines (73 loc) · 2.94 KB
/
DateFormatTests.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using NetCoreForce.Client;
using NetCoreForce.Client.Models;
using Xunit;
namespace NetCoreForce.Client.Tests
{
//https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm
public class DateFormatTests
{
public class TestObject
{
public DateTimeOffset DateProp { get; set; }
}
readonly DateTimeOffset _dto = new DateTimeOffset(2017,5,1,12,0,0,0,new TimeSpan(-5,0,0));
readonly string _expectedDate = "2017-05-01T12:00:00-05:00";
[Fact]
public void SerializedFullDate()
{
TestObject obj = new TestObject() { DateProp = _dto };
string serialized = JsonSerializer.SerializeComplete(obj, false);
Assert.Contains(_expectedDate, serialized);
}
[Fact]
public void FullDateFormatExtension()
{
string convertedDate = _dto.ToSfDateString();
Assert.Equal(_expectedDate, convertedDate);
}
[Fact]
public void FullDateFormat()
{
string convertedDate = _dto.ToString(DateFormats.FullDateFormatString);
Assert.Equal(_expectedDate, convertedDate);
}
[Fact]
public void FullDateFormatFromDateTime()
{
var dt = new DateTime(2018,1,1,0,0,0, DateTimeKind.Utc);
string convertedDate = DateFormats.FullDateString(dt);
string expected = "2018-01-01T00:00:00+00:00";
Assert.Equal(expected, convertedDate);
}
[Fact]
public void DateTimeAndDateTimeOffset()
{
DateTimeOffset dto = DateTimeOffset.Now;
DateTime dt = DateTime.Now;
DateTimeOffset dtoConverted = dt;
string convertedDateTimeOffset = dto.ToString(DateFormats.FullDateFormatString);
string convertedDateTime = dt.ToString(DateFormats.FullDateFormatString);
string convertedDateTimeOffsetConverted = dt.ToString(DateFormats.FullDateFormatString);
Assert.Equal(convertedDateTimeOffset, convertedDateTime);
Assert.Equal(convertedDateTimeOffset, convertedDateTimeOffsetConverted);
}
[Fact]
public void AccessTokenTimetampConversionSeconds()
{
AccessTokenResponse token = new AccessTokenResponse();
token.IssuedAt = 1530216542;
var expected = new DateTime(2018, 6, 28, 20, 9, 2, DateTimeKind.Utc);
Assert.Equal(expected, token.IssuedAtDateTime);
}
[Fact]
public void AccessTokenTimetampConversionMilliseconds()
{
AccessTokenResponse token = new AccessTokenResponse();
token.IssuedAt = 1537283732843;
var expected = new DateTime(2018, 9, 18, 15, 15, 32, 843, DateTimeKind.Utc);
Assert.Equal(expected, token.IssuedAtDateTime);
}
}
}