Skip to content

Commit 0f0c28c

Browse files
committed
Address remaining PR test feedback
Root cause: recent test refactors introduced assertion/name mismatches and test-guard synchronization risks that triggered new review threads.
1 parent f211719 commit 0f0c28c

4 files changed

Lines changed: 36 additions & 35 deletions

File tree

test/Geocoding.Tests/GoogleBusinessKeyTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Geocoding.Tests;
66

7+
[Collection("Settings")]
78
public class GoogleBusinessKeyTest
89
{
910
[Fact]

test/Geocoding.Tests/GoogleGeocoderTest.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -184,31 +184,6 @@ public async Task Geocode_WithPostalCodeFilter_ReturnsResultInExpectedPostalCode
184184
Assert.Contains(addresses, x => HasShortName(x, "94043"));
185185
}
186186

187-
[Fact]
188-
public void GoogleGeocodingException_WithProviderMessage_PreservesStatusAndMessage()
189-
{
190-
// Act
191-
var exception = new GoogleGeocodingException(GoogleStatus.RequestDenied, "This API is not activated on your API project.");
192-
193-
// Assert
194-
Assert.Equal(GoogleStatus.RequestDenied, exception.Status);
195-
Assert.Equal("This API is not activated on your API project.", exception.ProviderMessage);
196-
Assert.Contains("RequestDenied", exception.Message);
197-
Assert.Contains("This API is not activated on your API project.", exception.Message);
198-
}
199-
200-
[Fact]
201-
public void GoogleGeocodingException_WithoutProviderMessage_LeavesProviderMessageNull()
202-
{
203-
// Act
204-
var exception = new GoogleGeocodingException(GoogleStatus.OverQueryLimit);
205-
206-
// Assert
207-
Assert.Equal(GoogleStatus.OverQueryLimit, exception.Status);
208-
Assert.Null(exception.ProviderMessage);
209-
Assert.Contains("OverQueryLimit", exception.Message);
210-
}
211-
212187
[Fact]
213188
public async Task Geocode_HttpFailure_PreservesInnerExceptionPreview()
214189
{

test/Geocoding.Tests/GoogleTestGuard.cs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,54 @@ internal static class GoogleTestGuard
1212

1313
public static void EnsureAvailable(string apiKey)
1414
{
15-
string? skipReason;
15+
if (TryGetCachedSkipReason(apiKey, out string? skipReason))
16+
{
17+
if (!String.IsNullOrWhiteSpace(skipReason))
18+
Assert.Skip(skipReason);
19+
20+
return;
21+
}
22+
23+
string? validatedSkipReason = ValidateCore(apiKey);
1624

1725
lock (_sync)
1826
{
19-
if (_validated && String.Equals(_validatedApiKey, apiKey, StringComparison.Ordinal))
27+
if (!_validated || !String.Equals(_validatedApiKey, apiKey, StringComparison.Ordinal))
2028
{
21-
skipReason = _skipReason;
22-
}
23-
else
24-
{
25-
skipReason = ValidateCore(apiKey);
2629
_validatedApiKey = apiKey;
27-
_skipReason = skipReason;
30+
_skipReason = validatedSkipReason;
2831
_validated = true;
2932
}
33+
34+
skipReason = _skipReason;
3035
}
3136

3237
if (!String.IsNullOrWhiteSpace(skipReason))
3338
Assert.Skip(skipReason);
3439
}
3540

41+
private static bool TryGetCachedSkipReason(string apiKey, out string? skipReason)
42+
{
43+
lock (_sync)
44+
{
45+
if (_validated && String.Equals(_validatedApiKey, apiKey, StringComparison.Ordinal))
46+
{
47+
skipReason = _skipReason;
48+
return true;
49+
}
50+
}
51+
52+
skipReason = null;
53+
return false;
54+
}
55+
3656
private static string? ValidateCore(string apiKey)
3757
{
3858
try
3959
{
60+
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20));
4061
var geocoder = new GoogleGeocoder(apiKey);
41-
_ = geocoder.GeocodeAsync("1600 pennsylvania ave nw, washington dc", CancellationToken.None)
62+
_ = geocoder.GeocodeAsync("1600 pennsylvania ave nw, washington dc", cts.Token)
4263
.GetAwaiter()
4364
.GetResult()
4465
.FirstOrDefault();
@@ -49,6 +70,10 @@ public static void EnsureAvailable(string apiKey)
4970
{
5071
return BuildSkipReason(ex);
5172
}
73+
catch (OperationCanceledException)
74+
{
75+
return "Google integration test guard timed out while validating API key availability.";
76+
}
5277
}
5378

5479
private static string BuildSkipReason(GoogleGeocodingException ex)

test/Geocoding.Tests/YahooGeocoderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public override Task Geocode_InvalidZipCode_ReturnsResults(string address)
8585
}
8686

8787
[Fact]
88-
public void BuildRequest_GeneratesSignedGetRequest()
88+
public void BuildRequest_WithPlacefinderUrl_ReturnsSignedGetRequest()
8989
{
9090
// Arrange
9191
var geocoder = new YahooGeocoder("consumer-key", "consumer-secret");

0 commit comments

Comments
 (0)