Class WebApplicationTestFactory
- Assembly
- Cuemon.Extensions.Xunit.Hosting.AspNetCore.Mvc.dll
Provides a set of static methods for ASP.NET Core, ASP.NET Core MVC, Razor and related unit testing.
public static class WebApplicationTestFactory
- Inheritance
-
ObjectWebApplicationTestFactory
Methods
Create(Action<IServiceCollection>, Action<IApplicationBuilder>, Action<IHostBuilder>)
Creates and returns an IWebApplicationTest implementation.
public static IWebApplicationTest Create(Action<IServiceCollection> serviceSetup = null, Action<IApplicationBuilder> pipelineSetup = null, Action<IHostBuilder> hostSetup = null)
Parameters
serviceSetup
Action<IServiceCollection>The Microsoft.Extensions.DependencyInjection.IServiceCollection which may be configured.
pipelineSetup
Action<IApplicationBuilder>The Microsoft.AspNetCore.Builder.IApplicationBuilder which may be configured.
hostSetup
Action<IHostBuilder>The Microsoft.Extensions.Hosting.IHostBuilder which may be configured.
Returns
- IWebApplicationTest
An instance of an IWebApplicationTest implementation.
CreateWithHostBuilderContext(Action<HostBuilderContext, IServiceCollection>, Action<HostBuilderContext, IApplicationBuilder>, Action<IHostBuilder>)
Creates and returns an IWebApplicationTest implementation.
public static IWebApplicationTest CreateWithHostBuilderContext(Action<HostBuilderContext, IServiceCollection> serviceSetup = null, Action<HostBuilderContext, IApplicationBuilder> pipelineSetup = null, Action<IHostBuilder> hostSetup = null)
Parameters
serviceSetup
Action<HostBuilderContext, IServiceCollection>The Microsoft.Extensions.DependencyInjection.IServiceCollection which may be configured.
pipelineSetup
Action<HostBuilderContext, IApplicationBuilder>The Microsoft.AspNetCore.Builder.IApplicationBuilder which may be configured.
hostSetup
Action<IHostBuilder>The Microsoft.Extensions.Hosting.IHostBuilder which may be configured.
Returns
- IWebApplicationTest
An instance of an IWebApplicationTest implementation.
Run(Action<IServiceCollection>, Action<IApplicationBuilder>, Action<IHostBuilder>)
Runs a filter/middleware test.
public static async Task Run(Action<IServiceCollection> serviceSetup = null, Action<IApplicationBuilder> pipelineSetup = null, Action<IHostBuilder> hostSetup = null)
Parameters
serviceSetup
Action<IServiceCollection>The Microsoft.Extensions.DependencyInjection.IServiceCollection which may be configured.
pipelineSetup
Action<IApplicationBuilder>The Microsoft.AspNetCore.Builder.IApplicationBuilder which may be configured.
hostSetup
Action<IHostBuilder>The Microsoft.Extensions.Hosting.IHostBuilder which may be configured.
Returns
- Task
A task that represents the execution of the middleware.
Exceptions
- System.InvalidOperationException
serviceSetup
did not have a registered service of Microsoft.AspNetCore.Http.IHttpContextAccessor.
RunWithHostBuilderContext(Action<HostBuilderContext, IServiceCollection>, Action<HostBuilderContext, IApplicationBuilder>, Action<IHostBuilder>)
Runs a filter/middleware test.
public static async Task RunWithHostBuilderContext(Action<HostBuilderContext, IServiceCollection> serviceSetup = null, Action<HostBuilderContext, IApplicationBuilder> pipelineSetup = null, Action<IHostBuilder> hostSetup = null)
Parameters
serviceSetup
Action<HostBuilderContext, IServiceCollection>The Microsoft.Extensions.DependencyInjection.IServiceCollection which may be configured.
pipelineSetup
Action<HostBuilderContext, IApplicationBuilder>The Microsoft.AspNetCore.Builder.IApplicationBuilder which may be configured.
hostSetup
Action<IHostBuilder>The Microsoft.Extensions.Hosting.IHostBuilder which may be configured.
Returns
- Task
A task that represents the execution of the middleware.
Exceptions
- System.InvalidOperationException
serviceSetup
did not have a registered service of Microsoft.AspNetCore.Http.IHttpContextAccessor.