From 6b8f7eeb361e333dbd0f1692ffad4aacd98e964d Mon Sep 17 00:00:00 2001 From: Arnaud TAMAILLON Date: Fri, 26 Jan 2024 19:30:41 +0100 Subject: [PATCH] Fix unit tests (#54) - Switch to httpbin to match other tests - Manually install .NET Core 3.1 in GitHub Runner for CI --- .github/workflows/ci.yml | 3 ++- EasyVCR.Tests/ClientTest.cs | 14 +++++++------- EasyVCR.Tests/FakeDataService.cs | 9 +++++++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3031d32..eb8a7f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,8 +106,9 @@ jobs: - name: Install .NET SDK uses: actions/setup-dotnet@v3 with: - # .NET 5 is deprecated and removed from GitHub Actions, we need to manually install it + # .NET Core 3.1 and .NET 5 are deprecated and removed from GitHub Actions, we need to manually install them dotnet-version: | + 3.1.x 5.x.x 7.x.x diff --git a/EasyVCR.Tests/ClientTest.cs b/EasyVCR.Tests/ClientTest.cs index d6f2f6b..d94fb4e 100644 --- a/EasyVCR.Tests/ClientTest.cs +++ b/EasyVCR.Tests/ClientTest.cs @@ -379,7 +379,7 @@ public async Task TestIgnoreElementsFailMatch() // record baseline request first var client = HttpClients.NewHttpClient(cassette, Mode.Record); - var _ = await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData1); + var _ = await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData1); // try to replay the request with different body data client = HttpClients.NewHttpClient(cassette, Mode.Replay, new AdvancedSettings @@ -388,7 +388,7 @@ public async Task TestIgnoreElementsFailMatch() }); // should fail since we're strictly in replay mode and there's no exact match - await Assert.ThrowsExceptionAsync(async () => await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData2)); + await Assert.ThrowsExceptionAsync(async () => await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData2)); } [TestMethod] @@ -402,7 +402,7 @@ public async Task TestCustomMatchRule() // record baseline request first var client = HttpClients.NewHttpClient(cassette, Mode.Record); - var _ = await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData1); + var _ = await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData1); // try to replay the request with no custom match rule client = HttpClients.NewHttpClient(cassette, Mode.Replay, new AdvancedSettings() @@ -411,7 +411,7 @@ public async Task TestCustomMatchRule() }); // should pass since it passes the default match rules - await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData1); + await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData1); // try to replay the request with a custom match rule client = HttpClients.NewHttpClient(cassette, Mode.Replay, new AdvancedSettings @@ -420,7 +420,7 @@ public async Task TestCustomMatchRule() }); // should fail since the custom match rule always returns false and there's never a match - await Assert.ThrowsExceptionAsync(async () => await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData2)); + await Assert.ThrowsExceptionAsync(async () => await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData2)); } [TestMethod] @@ -434,7 +434,7 @@ public async Task TestIgnoreElementsPassMatch() // record baseline request first var client = HttpClients.NewHttpClient(cassette, Mode.Record); - var _ = await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData1); + var _ = await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData1); // try to replay the request with different body data, but ignoring the differences var ignoreElements = new List @@ -447,7 +447,7 @@ public async Task TestIgnoreElementsPassMatch() }); // should succeed since we're ignoring the differences - var response = await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData2); + var response = await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData2); Assert.IsNotNull(response); Assert.IsTrue(Utilities.ResponseCameFromRecording(response)); } diff --git a/EasyVCR.Tests/FakeDataService.cs b/EasyVCR.Tests/FakeDataService.cs index 0248265..cda1bd3 100644 --- a/EasyVCR.Tests/FakeDataService.cs +++ b/EasyVCR.Tests/FakeDataService.cs @@ -58,16 +58,21 @@ public async Task GetIPAddressDataRawResponse() return await Client.GetAsync(GetPreparedIPAddressDataUrl(_format)); } - protected abstract IPAddressData Convert(string responseBody); - public static string GetPreparedIPAddressDataUrl(string? format) { return $"{GetIPAddressDataUrl()}?format={format}"; } + protected abstract IPAddressData Convert(string responseBody); + public static string GetIPAddressDataUrl() { return "https://api.ipify.org/"; } + + public static string GetPostManPostEchoServiceUrl() + { + return "http://httpbin.org/post"; + } } }