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

Using Flurl with UnitTestEx #52

Closed
karpikpl opened this issue Feb 2, 2023 · 2 comments
Closed

Using Flurl with UnitTestEx #52

karpikpl opened this issue Feb 2, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@karpikpl
Copy link
Collaborator

karpikpl commented Feb 2, 2023

Flurl can be used with TestServer - see this stack overflow answer - https://stackoverflow.com/questions/50155702/can-i-use-flurlclient-with-asp-net-core-testserver
but UnitTestEx does not expose TestServer via an API, would it be possible to allow it?

@chullybun chullybun added the enhancement New feature or request label Feb 4, 2023
chullybun added a commit that referenced this issue Feb 9, 2023
chullybun added a commit that referenced this issue Feb 9, 2023
* Resolve issues #51 and #52.

* Fix value expectations test,

* Update log output for test troubleshooting

* Adjust delay check for NUnit
@chullybun
Copy link
Collaborator

Published NuGet package v2.1.2.

@karpikpl
Copy link
Collaborator Author

karpikpl commented Mar 3, 2023

The fix worked. I was able to use Flurl and have a valid unit test:

	public async Task HealthCheckEndpoint_Should_BeExposed_And_Return503_When_CheckFails()
	{
		// Arrange
		// fake & record all http calls in the test subject
		using (var httpTest = new HttpTest()) {
			httpTest.RespondWith("server error", 500);

			using var test = CreateApiTester<SampleApp.Startup>();
			test.Http().TestServer.PreserveExecutionContext = true;

			// Act
			var result = await test.Http()
				.RunAsync(HttpMethod.Get, "/health");

			// Assert
			System.Text.Json.JsonElement response = result.GetValue<dynamic>();
			var status = response.GetProperty("healthReport").GetProperty("status").GetString();
			status.Should().Be("Unhealthy", because: "the health check was mocked to fail");
			httpTest.ShouldHaveMadeACall();
			httpTest.ShouldHaveCalled("https://www.mock-url.com/*")
				.WithVerb(HttpMethod.Head);
		}
	}

@karpikpl karpikpl closed this as completed Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants