forked from linguanostra/GoogleMapsAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeZoneAPITests.cs
More file actions
151 lines (120 loc) · 5.07 KB
/
Copy pathTimeZoneAPITests.cs
File metadata and controls
151 lines (120 loc) · 5.07 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using FluentAssertions;
using GoogleMapsAPI.NET.API.Common.Components.Locations;
using GoogleMapsAPI.NET.Tests.API.Common;
using GoogleMapsAPI.NET.Tests.API.Extensions;
using GoogleMapsAPI.NET.Tests.API.Utils.MockConfig;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace GoogleMapsAPI.NET.Tests.API.TimeZone
{
/// <summary>
/// TimeZone API tests
/// </summary>
[TestClass]
public class TimeZoneAPITests : APITests
{
#region Static methods
/// <summary>
/// Test Log Angeles with timestamp
/// </summary>
[TestMethod]
public void TestLosAngelesWithTimestamp()
{
// Get mocked client
using (var client = GetMockedAPIClient())
{
// Arrange mocks for result
var webMocks = client.ArrangeWebResponseResultMocks(
new MockResultWebResponseConfig(@"{
""dstOffset"" : 0,
""rawOffset"" : -28800,
""status"" : ""OK"",
""timeZoneId"" : ""America/Los_Angeles"",
""timeZoneName"" : ""Pacific Standard Time""
}"));
// Make client call
var result = client.TimeZone.GetTimeZone(
new GeoCoordinatesLocation(39.6034810, -119.6822510), 1331766000);
// Assertions
webMocks.WebRequestUtil.AssertGetWasCalledOnceWithUrl(
"https://maps.googleapis.com/maps/api/timezone/json?" +
"location=39.603481%2C-119.682251×tamp=1331766000");
// Data
result.DstOffset.Should().Be(0);
result.RawOffset.Should().Be(-28800);
result.TimeZoneId.Should().Be("America/Los_Angeles");
result.TimeZoneName.Should().Be("Pacific Standard Time");
}
}
/// <summary>
/// Test Log Angeles with date
/// </summary>
[TestMethod]
public void TestLosAngelesWithDate()
{
// Get mocked client
using (var client = GetMockedAPIClient())
{
// Arrange mocks for result
var webMocks = client.ArrangeWebResponseResultMocks(
new MockResultWebResponseConfig(@"{
""dstOffset"" : 0,
""rawOffset"" : -28800,
""status"" : ""OK"",
""timeZoneId"" : ""America/Los_Angeles"",
""timeZoneName"" : ""Pacific Standard Time""
}"));
// Make client call
var result = client.TimeZone.GetTimeZone(
new GeoCoordinatesLocation(39.6034810, -119.6822510),
new DateTime(2012,3,14,23,0,0,DateTimeKind.Utc));
// Assertions
webMocks.WebRequestUtil.AssertGetWasCalledOnceWithUrl(
"https://maps.googleapis.com/maps/api/timezone/json?" +
"location=39.603481%2C-119.682251×tamp=1331766000");
// Data
result.DstOffset.Should().Be(0);
result.RawOffset.Should().Be(-28800);
result.TimeZoneId.Should().Be("America/Los_Angeles");
result.TimeZoneName.Should().Be("Pacific Standard Time");
}
}
/// <summary>
/// Test time zone response data
/// </summary>
[TestMethod]
public void TestTimeZoneResponseData()
{
// Get mocked client
using (var client = GetMockedAPIClient())
{
// Set response data
var responseData = @"{
""dstOffset"" : 3600,
""rawOffset"" : -28800,
""status"" : ""OK"",
""timeZoneId"" : ""America/Los_Angeles"",
""timeZoneName"" : ""Pacific Daylight Time""}";
// Arrange mocks for response data
var webMocks = client.ArrangeWebResponseResultMocks(
new MockResultWebResponseConfig(responseData));
// Make client call
var timeData = client.TimeZone.GetTimeZone(
new GeoCoordinatesLocation(39.6034810, -119.6822510),
1331766000);
// Assertions
webMocks.WebRequestUtil.AssertGetWasCalledOnceWithUrl(
"https://maps.googleapis.com/maps/api/timezone/json?" +
"location=39.603481%2C-119.682251×tamp=1331766000");
// Data
timeData.IsValid.Should().BeTrue();
timeData.HasErrorMessage.Should().BeFalse();
timeData.DstOffset.Should().Be(3600);
timeData.RawOffset.Should().Be(-28800);
timeData.TimeZoneId.Should().Be("America/Los_Angeles");
timeData.TimeZoneName.Should().Be("Pacific Daylight Time");
}
}
#endregion
}
}