public override void Setup() { InMemoryConfiguration["ConnectionStrings:" + Constants.System.UmbracoConnectionName] = null; InMemoryConfiguration["Umbraco:CMS:Hosting:Debug"] = "true"; // create new WebApplicationFactory specifying 'this' as the IStartup instance var factory = new UmbracoWebApplicationFactory <UmbracoTestServerTestBase>(CreateHostBuilder, BeforeHostStart); // additional host configuration for web server integration tests Factory = factory.WithWebHostBuilder(builder => // Executes after the standard ConfigureServices method builder.ConfigureTestServices(services => // Add a test auth scheme with a test auth handler to authn and assign the user services.AddAuthentication(TestAuthHandler.TestAuthenticationScheme) .AddScheme <AuthenticationSchemeOptions, TestAuthHandler>(TestAuthHandler.TestAuthenticationScheme, options => { }))); Client = Factory.CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false }); LinkGenerator = Factory.Services.GetRequiredService <LinkGenerator>(); }
public override void Setup() { InMemoryConfiguration["ConnectionStrings:" + Constants.System.UmbracoConnectionName] = null; InMemoryConfiguration["Umbraco:CMS:Hosting:Debug"] = "true"; /* * It's worth noting that our usage of WebApplicationFactory is non-standard, * the intent is that your Startup.ConfigureServices is called just like * when the app starts up, then replacements are registered in this class with * builder.ConfigureServices (builder.ConfigureTestServices has hung around from before the * generic host switchover). * * This is currently a pain to refactor towards due to UmbracoBuilder+TypeFinder+TypeLoader setup but * we should get there one day. * * See https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests */ var factory = new UmbracoWebApplicationFactory <UmbracoTestServerTestBase>(CreateHostBuilder, BeforeHostStart); // additional host configuration for web server integration tests Factory = factory.WithWebHostBuilder(builder => { // Otherwise inferred as $(SolutionDir)/Umbraco.Tests.Integration (note lack of src/tests) builder.UseContentRoot(Assembly.GetExecutingAssembly().GetRootDirectorySafe()); // Executes after the standard ConfigureServices method builder.ConfigureTestServices(services => // Add a test auth scheme with a test auth handler to authn and assign the user services.AddAuthentication(TestAuthHandler.TestAuthenticationScheme) .AddScheme <AuthenticationSchemeOptions, TestAuthHandler>(TestAuthHandler.TestAuthenticationScheme, options => { })); }); Client = Factory.CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false }); LinkGenerator = Factory.Services.GetRequiredService <LinkGenerator>(); }