-
Notifications
You must be signed in to change notification settings - Fork 25.3k
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
Create a new topic for TestServer scenarios #16953
Comments
@javiercn, do you have any guidance to add for when I reach this issue? |
@danroth27 I don't understand this pattern in the context of a separate test project. Comparing the example that you linked, the host isn't created in the Arrange step ... it's a separate project that the factory bootstraps. Can you/Javier convert one test for me? ... the basic test below. I'll use that as a template to proceed with the updates. Conversely, point me to an existing sample that tests a separate project, and I can grok the pattern from it. public class BasicTests
: IClassFixture<WebApplicationFactory<RazorPagesProject.Startup>>
{
private readonly WebApplicationFactory<RazorPagesProject.Startup> _factory;
public BasicTests(WebApplicationFactory<RazorPagesProject.Startup> factory)
{
_factory = factory;
}
[Theory]
[InlineData("/")]
[InlineData("/Index")]
[InlineData("/About")]
[InlineData("/Privacy")]
[InlineData("/Contact")]
public async Task Get_EndpointsReturnSuccessAndCorrectContentType(string url)
{
// Arrange
var client = _factory.CreateClient();
// Act
var response = await client.GetAsync(url);
// Assert
response.EnsureSuccessStatusCode(); // Status Code 200-299
Assert.Equal("text/html; charset=utf-8",
response.Content.Headers.ContentType.ToString());
}
} |
@guardrex WebApplicationFactory is aware of both WebHost and GenericHost and creates the TestServer accordingly. You shouldn't need to modify that sample. @danroth27 I don't see anything in this article that needs updating. I don't see any articles that deal directly with TestServer for that matter. |
@danroth27 Ok to close this? |
@Tratcher @guardrex I filed this issue because a customer had pinged me about how to setup their TestServer when using HostBuilder. I pointed the customer to https://github.com/dotnet/aspnetcore/blob/master/src/Hosting/TestHost/test/TestServerTests.cs#L51, but I couldn't find this pattern explained in the docs. Is it covered and I just missed it? |
@danroth27 That pattern isn't covered in the docs, but that's by-design. IIRC, Javier said something like he/the team doesn't intend for devs to use |
We should add docs for TestServer, but it's scenarios are different. This integration testing doc is for testing entire applications. TestServer is built to test individual components like middleware. |
In that case, I'll mark this for a new doc. We'll need to round up the usual suspects:
I'm burning thru Blazor issues at a decent pace. I can work the issue if one of you will provide an outline, main code examples of what should be shown (or point out one or a few framework tests to mirror), and any tips, gotchas, etc. |
Maybe what we need is a testing section added to the middleware authoring doc: Intro: Example 1: Set up your test app, add your own middleware and services Example 2: Send a request using HttpClient Example 3: |
We're not 100% there yet, but we've been trying to coalesce testing guidance in the Test, debug, and troubleshoot node and then cross-link it where it applies. Thanks for that ☝️. I have enough here to work this now. If things go well with my next two Blazor tasks (CSP with Blazor and EF Core with Blazor), I think I can work this EDIT Due to high priority Blazor auth topic work, this will be pushed back a few weeks to mid- to late March. |
In .NET Core 3.0 pretty much everything in ASP.NET Core moved to use the new generic host, but this doc still discusses using TestServer with the older web host. This doc should be updated to show how to use TestServer with the generic host. Like this: https://github.com/dotnet/aspnetcore/blob/master/src/Hosting/TestHost/test/TestServerTests.cs#L51
The text was updated successfully, but these errors were encountered: