Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests #54

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions EasyVCR.Tests/ClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<VCRException>(async () => await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData2));
await Assert.ThrowsExceptionAsync<VCRException>(async () => await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData2));
}

[TestMethod]
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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<VCRException>(async () => await client.PostAsync(FakeDataService.GetPreparedIPAddressDataUrl("json"), bodyData2));
await Assert.ThrowsExceptionAsync<VCRException>(async () => await client.PostAsync(FakeDataService.GetPostManPostEchoServiceUrl(), bodyData2));
}

[TestMethod]
Expand All @@ -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<CensorElement>
Expand All @@ -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));
}
Expand Down
9 changes: 7 additions & 2 deletions EasyVCR.Tests/FakeDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,21 @@ public async Task<HttpResponseMessage> 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";
}
}
}
Loading