WebApplicationFactory throws error that contentRootPath does not exist in ASP.NET Core integration test

后端 未结 6 1220
醉梦人生
醉梦人生 2021-02-13 18:52

I have a ASP.NET Core project with some simple Razor pages and a Web API controller.

I\'m using Clean Architecture as a starting point. I\'ve renamed the project names,

6条回答
  •  有刺的猬
    2021-02-13 19:33

    My solution for this problem is define WebApplicationFactory with Application Startup but setup WebHostBuilder with TestStartup.

    Example:

    public class MyApplicationFactory : WebApplicationFactory
    {
        protected override IWebHostBuilder CreateWebHostBuilder()
        {
            return WebHost.CreateDefaultBuilder();
        }
    
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.UseStartup();
    
            base.ConfigureWebHost(builder);
        }
    }
    

提交回复
热议问题