Skip to content

Commit 6b8f7ee

Browse files
authored
Fix unit tests (#54)
- Switch to httpbin to match other tests - Manually install .NET Core 3.1 in GitHub Runner for CI
1 parent 991546c commit 6b8f7ee

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ jobs:
106106
- name: Install .NET SDK
107107
uses: actions/setup-dotnet@v3
108108
with:
109-
# .NET 5 is deprecated and removed from GitHub Actions, we need to manually install it
109+
# .NET Core 3.1 and .NET 5 are deprecated and removed from GitHub Actions, we need to manually install them
110110
dotnet-version: |
111+
3.1.x
111112
5.x.x
112113
7.x.x
113114

EasyVCR.Tests/ClientTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public async Task TestIgnoreElementsFailMatch()
379379

380380
// record baseline request first
381381
var client = HttpClients.NewHttpClient(cassette, Mode.Record);
382-
var _ = await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData1);
382+
var _ = await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData1);
383383

384384
// try to replay the request with different body data
385385
client = HttpClients.NewHttpClient(cassette, Mode.Replay, new AdvancedSettings
@@ -388,7 +388,7 @@ public async Task TestIgnoreElementsFailMatch()
388388
});
389389

390390
// should fail since we're strictly in replay mode and there's no exact match
391-
await Assert.ThrowsExceptionAsync<VCRException>(async () => await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData2));
391+
await Assert.ThrowsExceptionAsync<VCRException>(async () => await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData2));
392392
}
393393

394394
[TestMethod]
@@ -402,7 +402,7 @@ public async Task TestCustomMatchRule()
402402

403403
// record baseline request first
404404
var client = HttpClients.NewHttpClient(cassette, Mode.Record);
405-
var _ = await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData1);
405+
var _ = await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData1);
406406

407407
// try to replay the request with no custom match rule
408408
client = HttpClients.NewHttpClient(cassette, Mode.Replay, new AdvancedSettings()
@@ -411,7 +411,7 @@ public async Task TestCustomMatchRule()
411411
});
412412

413413
// should pass since it passes the default match rules
414-
await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData1);
414+
await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData1);
415415

416416
// try to replay the request with a custom match rule
417417
client = HttpClients.NewHttpClient(cassette, Mode.Replay, new AdvancedSettings
@@ -420,7 +420,7 @@ public async Task TestCustomMatchRule()
420420
});
421421

422422
// should fail since the custom match rule always returns false and there's never a match
423-
await Assert.ThrowsExceptionAsync<VCRException>(async () => await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData2));
423+
await Assert.ThrowsExceptionAsync<VCRException>(async () => await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData2));
424424
}
425425

426426
[TestMethod]
@@ -434,7 +434,7 @@ public async Task TestIgnoreElementsPassMatch()
434434

435435
// record baseline request first
436436
var client = HttpClients.NewHttpClient(cassette, Mode.Record);
437-
var _ = await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData1);
437+
var _ = await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData1);
438438

439439
// try to replay the request with different body data, but ignoring the differences
440440
var ignoreElements = new List<CensorElement>
@@ -447,7 +447,7 @@ public async Task TestIgnoreElementsPassMatch()
447447
});
448448

449449
// should succeed since we're ignoring the differences
450-
var response = await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData2);
450+
var response = await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData2);
451451
Assert.IsNotNull(response);
452452
Assert.IsTrue(Utilities.ResponseCameFromRecording(response));
453453
}

EasyVCR.Tests/FakeDataService.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,21 @@ public async Task<HttpResponseMessage> GetIPAddressDataRawResponse()
5858
return await Client.GetAsync(GetPreparedIPAddressDataUrl(_format));
5959
}
6060

61-
protected abstract IPAddressData Convert(string responseBody);
62-
6361
public static string GetPreparedIPAddressDataUrl(string? format)
6462
{
6563
return $"{GetIPAddressDataUrl()}?format={format}";
6664
}
6765

66+
protected abstract IPAddressData Convert(string responseBody);
67+
6868
public static string GetIPAddressDataUrl()
6969
{
7070
return "https://api.ipify.org/";
7171
}
72+
73+
public static string GetPostManPostEchoServiceUrl()
74+
{
75+
return "http://httpbin.org/post";
76+
}
7277
}
7378
}

0 commit comments

Comments
 (0)