Description
Feedback from @shanselman:
We should do better with testing. There's issues with moving from the inside out:
LEVELS OF TESTING
- GOOD - Unit Testing - Make a PageModel and call On Get
- GOOD - Functional Testing - Make a WebApplicationFactory and make in-memory HTTP calls
- BAD - Automated Browser Testing with Real Server - can't easily use Selenium or call a real server. I shouldn't have to do this. We should decouple the WebApplicationFactory from the concrete TestServer implementation. @davidfowl
public class RealServerFactory<TStartup> : WebApplicationFactory<Startup> where TStartup : class
{
IWebHost _host;
public string RootUri { get; set; }
public RealServerFactory()
{
ClientOptions.BaseAddress = new Uri("https://localhost");
}
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.UseEnvironment("Development"); //will be default in RC1
}
protected override TestServer CreateServer(IWebHostBuilder builder)
{
//Real TCP port
_host = builder.Build();
_host.Start();
RootUri = _host.ServerFeatures.Get<IServerAddressesFeature>().Addresses.FirstOrDefault();
//Fake Server we won't use...sad!
return new TestServer(new WebHostBuilder().UseStartup<TStartup>());
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_host.Dispose();
}
}
}
/cc @javiercn