From e0b4c13895fee575544f963b7dbc59d12f8ef7b4 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Mon, 16 Apr 2018 14:35:59 -0700 Subject: [PATCH] [Fixes #7587] Default to Development environment in tests --- .../WebApplicationFactory.cs | 23 +++++++++++++------ .../Infrastructure/MvcTestFixture.cs | 1 + 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs b/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs index 910db78d92..f1edf8fc04 100644 --- a/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs +++ b/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs @@ -243,13 +243,22 @@ namespace Microsoft.AspNetCore.Mvc.Testing /// array as arguments. /// /// A instance. - protected virtual IWebHostBuilder CreateWebHostBuilder() => - WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint(Array.Empty()) ?? - throw new InvalidOperationException(Resources.FormatMissingCreateWebHostBuilderMethod( - nameof(IWebHostBuilder), - typeof(TEntryPoint).Assembly.EntryPoint.DeclaringType.FullName, - typeof(WebApplicationFactory).Name, - nameof(CreateWebHostBuilder))); + protected virtual IWebHostBuilder CreateWebHostBuilder() + { + var builder = WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint(Array.Empty()); + if (builder == null) + { + throw new InvalidOperationException(Resources.FormatMissingCreateWebHostBuilderMethod( + nameof(IWebHostBuilder), + typeof(TEntryPoint).Assembly.EntryPoint.DeclaringType.FullName, + typeof(WebApplicationFactory).Name, + nameof(CreateWebHostBuilder))); + } + else + { + return builder.UseEnvironment("Development"); + } + } /// /// Creates the with the bootstrapped application in . diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Infrastructure/MvcTestFixture.cs b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Infrastructure/MvcTestFixture.cs index f80e530537..7e32759610 100644 --- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Infrastructure/MvcTestFixture.cs +++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Infrastructure/MvcTestFixture.cs @@ -17,6 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests { builder .UseRequestCulture("en-GB", "en-US") + .UseEnvironment("Production") .ConfigureServices( services => services.Configure( options => options.CompatibilityVersion = CompatibilityVersion.Version_2_1));