Add ability to override the testing web content root using environment variables
This commit is contained in:
parent
d4beab5d09
commit
28c0c4d128
|
|
@ -128,6 +128,11 @@ namespace Microsoft.AspNetCore.Mvc.Testing
|
|||
|
||||
private void SetContentRoot(IWebHostBuilder builder)
|
||||
{
|
||||
if (SetContentRootFromSetting(builder))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var metadataAttributes = GetContentRootMetadataAttributes(
|
||||
typeof(TEntryPoint).Assembly.FullName,
|
||||
typeof(TEntryPoint).Assembly.GetName().Name);
|
||||
|
|
@ -161,6 +166,24 @@ namespace Microsoft.AspNetCore.Mvc.Testing
|
|||
}
|
||||
}
|
||||
|
||||
private static bool SetContentRootFromSetting(IWebHostBuilder builder)
|
||||
{
|
||||
// Attempt to look for TEST_CONTENTROOT_APPNAME in settings. This should result in looking for
|
||||
// ASPNETCORE_TEST_CONTENTROOT_APPNAME environment variable.
|
||||
var assemblyName = typeof(TEntryPoint).Assembly.GetName().Name;
|
||||
var settingSuffix = assemblyName.ToUpperInvariant().Replace(".", "_");
|
||||
var settingName = $"TEST_CONTENTROOT_{settingSuffix}";
|
||||
|
||||
var settingValue = builder.GetSetting(settingName);
|
||||
if (settingValue == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
builder.UseContentRoot(settingValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
private WebApplicationFactoryContentRootAttribute[] GetContentRootMetadataAttributes(
|
||||
string tEntryPointAssemblyFullName,
|
||||
string tEntryPointAssemblyName)
|
||||
|
|
|
|||
Loading…
Reference in New Issue