Im trying to create a integration test for my Exception handling middleware How do you add to the existing ApplicationBuilder with WebApplicationFactory?
Im using WebApplicationFactory<T> with my Startup.cs and I want to add an additional middleware to the request pipeline so I can mimic a error response.
The example below completely overrides my Startup which is not the desired result. I noticed builder has the following extension methods ConfigureTestServices() and ConfigureTestContainer() but there doesnt appear to be an equivilant to configure the request pipeline thats under test.
_client = fixture.WithWebHostBuilder(builder =>
{
builder.Configure(app =>
{
app.Map("/error", a => a.Run(c => throw new Exception("My error message")));
});
}).CreateDefaultClient();
Perhaps I could use a IStartupFilter which throws at the end of the request pipeline. But im not sure how I could get that to invoke after my middleware.
Im trying to create a integration test for my Exception handling middleware How do you add to the existing
ApplicationBuilderwith WebApplicationFactory?Im using
WebApplicationFactory<T>with myStartup.csand I want to add an additional middleware to the request pipeline so I can mimic a error response.The example below completely overrides my Startup which is not the desired result. I noticed builder has the following extension methods
ConfigureTestServices()andConfigureTestContainer()but there doesnt appear to be an equivilant to configure the request pipeline thats under test.Perhaps I could use a
IStartupFilterwhich throws at the end of the request pipeline. But im not sure how I could get that to invoke after my middleware.