Skip to content

Testclient getasync not returning right statuscode. #20119

@sabrigo

Description

@sabrigo

When making a call to a non-existent url, the getasync should return 404 not found error, however it is always returning response status as ok, even though there is no catch all situation I have implemented.

Further, when enabled verbose logging (screenshot below), I get the following information but the response status was sent as 200.

image

image

		public async Task Get_Should_ThrowError_When_ARoute_Is_Invalid()
		{
			var hostBuilder =
				new HostBuilder().ConfigureWebHost(webHost =>
				{
					webHost.UseTestServer();
                                        webHost.UseStartup<Startup>();
				});
			var host = hostBuilder.StartAsync().Result;

			await Assert.ThrowsAsync<Exception>(async () =>
			{
				var client = host.GetTestClient();
				var response = await client.GetAsync($"RequestUri");
				var result = await response.Content.ReadAsStringAsync();
			});
		}

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions