Fix a null reference exception and add some null checks
This commit is contained in:
parent
8d9c16132a
commit
ef43b100a6
|
|
@ -93,6 +93,16 @@ namespace Microsoft.AspNetCore.Mvc.Testing
|
||||||
/// <returns>An instance of this <see cref="MvcWebApplicationBuilder{TStartup}"/></returns>
|
/// <returns>An instance of this <see cref="MvcWebApplicationBuilder{TStartup}"/></returns>
|
||||||
public MvcWebApplicationBuilder<TStartup> UseRequestCulture(string culture, string uiCulture)
|
public MvcWebApplicationBuilder<TStartup> UseRequestCulture(string culture, string uiCulture)
|
||||||
{
|
{
|
||||||
|
if (culture == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(culture));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uiCulture == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(uiCulture));
|
||||||
|
}
|
||||||
|
|
||||||
ConfigureBeforeStartup(services =>
|
ConfigureBeforeStartup(services =>
|
||||||
{
|
{
|
||||||
services.TryAddSingleton(new TestCulture
|
services.TryAddSingleton(new TestCulture
|
||||||
|
|
@ -116,6 +126,16 @@ namespace Microsoft.AspNetCore.Mvc.Testing
|
||||||
/// <returns>An instance of this <see cref="MvcWebApplicationBuilder{TStartup}"/></returns>
|
/// <returns>An instance of this <see cref="MvcWebApplicationBuilder{TStartup}"/></returns>
|
||||||
public MvcWebApplicationBuilder<TStartup> UseStartupCulture(string culture, string uiCulture)
|
public MvcWebApplicationBuilder<TStartup> UseStartupCulture(string culture, string uiCulture)
|
||||||
{
|
{
|
||||||
|
if (culture == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(culture));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uiCulture == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(uiCulture));
|
||||||
|
}
|
||||||
|
|
||||||
_systemCulture = new TestCulture { Culture = culture, UICulture = uiCulture };
|
_systemCulture = new TestCulture { Culture = culture, UICulture = uiCulture };
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -130,6 +150,11 @@ namespace Microsoft.AspNetCore.Mvc.Testing
|
||||||
string solutionRelativePath,
|
string solutionRelativePath,
|
||||||
string solutionName = "*.sln")
|
string solutionName = "*.sln")
|
||||||
{
|
{
|
||||||
|
if (solutionRelativePath == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(solutionRelativePath));
|
||||||
|
}
|
||||||
|
|
||||||
var applicationBasePath = AppContext.BaseDirectory;
|
var applicationBasePath = AppContext.BaseDirectory;
|
||||||
|
|
||||||
var directoryInfo = new DirectoryInfo(applicationBasePath);
|
var directoryInfo = new DirectoryInfo(applicationBasePath);
|
||||||
|
|
@ -160,6 +185,11 @@ namespace Microsoft.AspNetCore.Mvc.Testing
|
||||||
.UseContentRoot(ContentRoot)
|
.UseContentRoot(ContentRoot)
|
||||||
.ConfigureServices(InitializeServices);
|
.ConfigureServices(InitializeServices);
|
||||||
|
|
||||||
|
if (_systemCulture == null)
|
||||||
|
{
|
||||||
|
return new TestServer(builder);
|
||||||
|
}
|
||||||
|
|
||||||
var originalCulture = CultureInfo.CurrentCulture;
|
var originalCulture = CultureInfo.CurrentCulture;
|
||||||
var originalUICulture = CultureInfo.CurrentUICulture;
|
var originalUICulture = CultureInfo.CurrentUICulture;
|
||||||
try
|
try
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue