[Fixes #7587] No easy way to change ASPNETCORE_ENVIRONMENT

This commit is contained in:
Javier Calvarro Nelson 2018-04-13 00:52:58 -07:00
parent d5e044f693
commit 22510e1377
1 changed files with 16 additions and 7 deletions

View File

@ -243,13 +243,22 @@ namespace Microsoft.AspNetCore.Mvc.Testing
/// array as arguments.
/// </remarks>
/// <returns>A <see cref="IWebHostBuilder"/> instance.</returns>
protected virtual IWebHostBuilder CreateWebHostBuilder() =>
WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint<TEntryPoint>(Array.Empty<string>()) ??
throw new InvalidOperationException(Resources.FormatMissingCreateWebHostBuilderMethod(
nameof(IWebHostBuilder),
typeof(TEntryPoint).Assembly.EntryPoint.DeclaringType.FullName,
typeof(WebApplicationFactory<TEntryPoint>).Name,
nameof(CreateWebHostBuilder)));
protected virtual IWebHostBuilder CreateWebHostBuilder()
{
var builder = WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint<TEntryPoint>(Array.Empty<string>());
if (builder == null)
{
throw new InvalidOperationException(Resources.FormatMissingCreateWebHostBuilderMethod(
nameof(IWebHostBuilder),
typeof(TEntryPoint).Assembly.EntryPoint.DeclaringType.FullName,
typeof(WebApplicationFactory<TEntryPoint>).Name,
nameof(CreateWebHostBuilder)));
}
else
{
return builder.UseEnvironment("Development");
}
}
/// <summary>
/// Creates the <see cref="TestServer"/> with the bootstrapped application in <paramref name="builder"/>.