|
1 | | -using System.Net; |
| 1 | +using System.Globalization; |
| 2 | +using System.Net; |
2 | 3 | using System.Net.Http; |
3 | 4 | using System.Reflection; |
| 5 | +using System.Text.Json; |
| 6 | +using Geocoding.Extensions; |
4 | 7 | using Geocoding.MapQuest; |
5 | 8 | using Geocoding.Tests.Utility; |
6 | 9 | using Xunit; |
@@ -46,6 +49,59 @@ public void UseOSM_SetTrue_ThrowsNotSupportedException() |
46 | 49 | Assert.Contains("no longer supported", exception.Message, StringComparison.OrdinalIgnoreCase); |
47 | 50 | } |
48 | 51 |
|
| 52 | + [Fact] |
| 53 | + public void RequestVerb_Normalization_IsCultureInvariant() |
| 54 | + { |
| 55 | + // Arrange |
| 56 | + var originalCulture = CultureInfo.CurrentCulture; |
| 57 | + var originalUICulture = CultureInfo.CurrentUICulture; |
| 58 | + |
| 59 | + try |
| 60 | + { |
| 61 | + CultureInfo.CurrentCulture = new CultureInfo("tr-TR"); |
| 62 | + CultureInfo.CurrentUICulture = new CultureInfo("tr-TR"); |
| 63 | + var request = new TestRequest("mapquest-key"); |
| 64 | + |
| 65 | + // Act |
| 66 | + request.SetVerb("mixid"); |
| 67 | + |
| 68 | + // Assert |
| 69 | + Assert.Equal("MIXID", request.RequestVerb); |
| 70 | + } |
| 71 | + finally |
| 72 | + { |
| 73 | + CultureInfo.CurrentCulture = originalCulture; |
| 74 | + CultureInfo.CurrentUICulture = originalUICulture; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + [Fact] |
| 79 | + public void MapQuestLocation_Deserialization_PreservesProviderDefaults() |
| 80 | + { |
| 81 | + // Arrange |
| 82 | + const string json = """ |
| 83 | + { |
| 84 | + "location": "1600 Pennsylvania Ave NW, Washington, DC 20500, US", |
| 85 | + "latLng": { "lat": 38.8977, "lng": -77.0365 }, |
| 86 | + "displayLatLng": { "lat": 38.8977, "lng": -77.0365 }, |
| 87 | + "street": "1600 Pennsylvania Ave NW", |
| 88 | + "adminArea5": "Washington", |
| 89 | + "adminArea3": "DC", |
| 90 | + "adminArea1": "US", |
| 91 | + "postalCode": "20500" |
| 92 | + } |
| 93 | + """; |
| 94 | + |
| 95 | + // Act |
| 96 | + var location = JsonSerializer.Deserialize<MapQuestLocation>(json, JsonExtensions.JsonOptions); |
| 97 | + |
| 98 | + // Assert |
| 99 | + Assert.NotNull(location); |
| 100 | + Assert.Equal("MapQuest", location.Provider); |
| 101 | + Assert.Equal("1600 Pennsylvania Ave NW, Washington, DC 20500, US", location.FormattedAddress); |
| 102 | + Assert.Equal(new Location(38.8977, -77.0365), location.Coordinates); |
| 103 | + } |
| 104 | + |
49 | 105 | [Fact] |
50 | 106 | public async Task CreateRequest_GeocodeRequest_CreatesJsonPost() |
51 | 107 | { |
@@ -111,4 +167,17 @@ protected override HttpClient BuildClient() |
111 | 167 | return new HttpClient(_handler, disposeHandler: false); |
112 | 168 | } |
113 | 169 | } |
| 170 | + |
| 171 | + private sealed class TestRequest : BaseRequest |
| 172 | + { |
| 173 | + public TestRequest(string key) |
| 174 | + : base(key) { } |
| 175 | + |
| 176 | + public override string RequestAction => "address"; |
| 177 | + |
| 178 | + public void SetVerb(string verb) |
| 179 | + { |
| 180 | + RequestVerb = verb; |
| 181 | + } |
| 182 | + } |
114 | 183 | } |
0 commit comments