Skip to content

Ammending the request pipeline with WebApplicationFactory #7203

@chris-brown

Description

@chris-brown

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions