Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit ef43b10

Browse files
committed
Fix a null reference exception and add some null checks
1 parent 8d9c161 commit ef43b10

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Microsoft.AspNetCore.Mvc.Testing/MvcWebApplicationBuilder.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ public MvcWebApplicationBuilder<TStartup> UseApplicationAssemblies()
9393
/// <returns>An instance of this <see cref="MvcWebApplicationBuilder{TStartup}"/></returns>
9494
public MvcWebApplicationBuilder<TStartup> UseRequestCulture(string culture, string uiCulture)
9595
{
96+
if (culture == null)
97+
{
98+
throw new ArgumentNullException(nameof(culture));
99+
}
100+
101+
if (uiCulture == null)
102+
{
103+
throw new ArgumentNullException(nameof(uiCulture));
104+
}
105+
96106
ConfigureBeforeStartup(services =>
97107
{
98108
services.TryAddSingleton(new TestCulture
@@ -116,6 +126,16 @@ public MvcWebApplicationBuilder<TStartup> UseRequestCulture(string culture, stri
116126
/// <returns>An instance of this <see cref="MvcWebApplicationBuilder{TStartup}"/></returns>
117127
public MvcWebApplicationBuilder<TStartup> UseStartupCulture(string culture, string uiCulture)
118128
{
129+
if (culture == null)
130+
{
131+
throw new ArgumentNullException(nameof(culture));
132+
}
133+
134+
if (uiCulture == null)
135+
{
136+
throw new ArgumentNullException(nameof(uiCulture));
137+
}
138+
119139
_systemCulture = new TestCulture { Culture = culture, UICulture = uiCulture };
120140
return this;
121141
}
@@ -130,6 +150,11 @@ public MvcWebApplicationBuilder<TStartup> UseSolutionRelativeContentRoot(
130150
string solutionRelativePath,
131151
string solutionName = "*.sln")
132152
{
153+
if (solutionRelativePath == null)
154+
{
155+
throw new ArgumentNullException(nameof(solutionRelativePath));
156+
}
157+
133158
var applicationBasePath = AppContext.BaseDirectory;
134159

135160
var directoryInfo = new DirectoryInfo(applicationBasePath);
@@ -160,6 +185,11 @@ public TestServer Build()
160185
.UseContentRoot(ContentRoot)
161186
.ConfigureServices(InitializeServices);
162187

188+
if (_systemCulture == null)
189+
{
190+
return new TestServer(builder);
191+
}
192+
163193
var originalCulture = CultureInfo.CurrentCulture;
164194
var originalUICulture = CultureInfo.CurrentUICulture;
165195
try

0 commit comments

Comments
 (0)