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

Verify working on .NET 7 Preview & all LTS versions #11

Merged
merged 3 commits into from
Jul 4, 2022
Merged

Conversation

maxkagamine
Copy link
Owner

@maxkagamine maxkagamine commented Jul 4, 2022

The latest .NET 7 preview introduces a breaking change to the StringContent constructor where it no longer accepts null for mediaType (dotnet/runtime#63231). ReturnsResponse has been updated to default to text/plain (which is still StringContent's default when the mediaType parameter is not used). Fixes #9.

To better catch these sorts of problems in the future, the unit tests will now run against the latest/preview .NET version, every LTS version, and legacy .NET Framework. Unfortunately this still needs to be updated manually. Currently the frameworks that are tested are:

  • .NET 7.0 Preview
  • .NET 6.0 (end of life Nov 2024)
  • .NET Core 3.1 (end of life Dec 2022)
  • .NET Framework 4.8

Action verifyFooPostedStuff = () => handler.VerifyRequest(HttpMethod.Post, fooUrl,
async r => (await r.Content.ReadAsStringAsync()) == "stuff");
Action verifyFooPostedOtherStuff = () => handler.VerifyRequest(HttpMethod.Post, fooUrl,
async r => (await r.Content.ReadAsStringAsync()) == "other stuff", failMessage: "oh noes");
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems in .NET Framework the HttpRequestMessage gets disposed, which prevents us from accessing the request body in Verify. That said, these overloads aren't especially useful anyway; they were generated alongside the SetupRequest methods, but the match predicate is meant for setups, so it's probably safe to leave them out (and avoid encouraging their use).

@maxkagamine maxkagamine marked this pull request as ready for review July 4, 2022 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dotnet 7: The value cannot be null or empty. (Parameter 'mediaType')
1 participant