/// <summary> /// If the response status indicates fail because of quota exceeded - mark test as inconclusive. /// </summary> public static void NotExceedQuota(TimeZoneResponse response) { if (response?.Status == Entities.TimeZone.Response.Status.OVER_QUERY_LIMIT) { throw new InconclusiveException(QuotaExceedMessage); } }
public async Task <string> ConvertCityToTimeZoneName(string location) { TimeZoneResponse response = new TimeZoneResponse(); var plusName = location.Replace(" ", "+"); var address = "http://maps.google.com/maps/api/geocode/json?address=" + plusName + "&sensor=false"; var result = await Global.SendWebRequest(address); var latLongResult = JsonConvert.DeserializeObject <dynamic>(result); if (latLongResult.status == "OK") { string string1 = latLongResult.results[0].geometry.location.lat.ToString().Replace(",", "."); string string2 = latLongResult.results[0].geometry.location.lng.ToString().Replace(",", "."); var timeZoneRespontimeZoneRequest = "https://maps.googleapis.com/maps/api/timezone/json?location=" + string1 + "," + string2 + "&sensor=false×tamp=1362209227"; var timeZoneResponseString = await Global.SendWebRequest(timeZoneRespontimeZoneRequest); //new System.Net.WebClient().DownloadString(timeZoneRespontimeZoneRequest); var timeZoneResult = JsonConvert.DeserializeObject <dynamic>(timeZoneResponseString); if (timeZoneResult.status == "OK") { response.TimeZoneId = timeZoneResult.timeZoneId; return(response.TimeZoneId); } } return("error"); }
public async Task Test_SerializationAsync() { // Get the client. ITimeZoneClient client = Fixture.GetRequiredService <ITimeZoneClient>(); // Create the request. var request = new TimeZoneRequest( // The White House 38.8977M, -77.0365M, // 🎆🎆 July 4th, 2020 🎆🎆 new DateTime(2020, 07, 04) ); // Execute. TimeZoneResponse results = await client .GetTimeZoneAsync(request, default) .ConfigureAwait(false); // Create the container. var expected = new Container <TimeZoneResponse> { Value = results }; // Serialize to a string. string json = JsonSerializer.Serialize(expected); // Serialize again. var actual = JsonSerializer.Deserialize <Container <TimeZoneResponse> >(json); // Compare. Assert.Equal(expected.Value.Status, actual.Value.Status); Assert.Equal(expected.Value.TimeZoneId, actual.Value.TimeZoneId); Assert.Equal(expected.Value.RawOffset, actual.Value.RawOffset); }
public async Task Test_GetTimeZoneAsync() { // Get the client. ITimeZoneClient client = Fixture.GetRequiredService <ITimeZoneClient>(); // Create the request. var request = new TimeZoneRequest( // The White House 38.8977M, -77.0365M, // 🎆🎆 July 4th, 2020 🎆🎆 new DateTime(2020, 07, 04) ); // Execute. TimeZoneResponse actual = await client .GetTimeZoneAsync(request, default) .ConfigureAwait(false); // Assert. Assert.Equal(Status.OK, actual.Status); Assert.Equal(TimeSpan.FromHours(1), actual.DstOffset); Assert.Equal(TimeSpan.FromHours(-5), actual.RawOffset); Assert.Equal("America/New_York", actual.TimeZoneId); Assert.Equal("Eastern Daylight Time", actual.TimeZoneName); }
public void TimeZone_Correct_OverviewPath() { TimeZoneRequest request = new TimeZoneRequest(); request.Location = new Location(55.866413, 12.501063); request.Language = "en"; TimeZoneResponse result = GoogleMaps.TimeZone.Query(request); Assert.AreEqual(GoogleMapsApi.Entities.TimeZone.Response.Status.OK, result.Status); }
public static bool IsSuccess(this TimeZoneResponse timeZoneResponse) { switch (timeZoneResponse.Status) { case GoogleMapsApi.Entities.TimeZone.Response.Status.OK: return(true); default: return(false); } }
public void TimeZone_Correct_OverviewPath() { TimeZoneRequest request = new TimeZoneRequest(); request.Location = new Location(55.866413, 12.501063); request.Language = "en"; TimeZoneResponse result = GoogleMaps.TimeZone.Query(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(Status.OK, result.Status); }
public async Task TimeZone_Correct_OverviewPathAsync() { TimeZoneRequest request = new TimeZoneRequest { Location = new Location(55.866413, 12.501063), Language = "en", ApiKey = ApiKey }; TimeZoneResponse result = await GoogleMaps.TimeZone.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(Status.OK, result.Status); }
static private void PrintTZResource(TimeZoneResponse tz) { Console.WriteLine($"Name: {tz.GenericName}"); Console.WriteLine($"Windows ID: {tz.WindowsTimeZoneId}"); Console.WriteLine($"IANA ID: {tz.IANATimeZoneId}"); Console.WriteLine($"UTC offset: {tz.UtcOffset}"); Console.WriteLine($"Abbrev: {tz.Abbreviation}"); if (tz.ConvertedTime != null) { var ctz = tz.ConvertedTime; Console.WriteLine($"Local Time: {ctz.LocalTime}"); Console.WriteLine($"TZ Abbr: {ctz.TimeZoneDisplayAbbr} "); Console.WriteLine($"TZ Name: {ctz.TimeZoneDisplayName}"); Console.WriteLine($"UTC offset: {ctz.UtcOffsetWithDst }"); } if (tz.DstRule != null) { var dst = tz.DstRule; Console.WriteLine("Start: {0} - {1} - {2} - {3}", dst.DstStartTime, dst.DstStartMonth, dst.DstStartDateRule, dst.DstAdjust1); Console.WriteLine("End: {0} - {1} - {2} - {3}", dst.DstEndTime, dst.DstEndMonth, dst.DstEndDateRule, dst.DstAdjust2); } }
public TimeZoneResponseModel(int cityId, TimeZoneResponse response) { CityId = cityId; TimeZoneId = response.TimeZoneID; TimeZoneName = response.TimeZoneName; }
public TimeZoneResponseModel Create(int cityId, TimeZoneResponse response) { return(new TimeZoneResponseModel(cityId, response)); }