Skip to content

Commit 1e66fd8

Browse files
committed
Fixed the double initialization issue with the WebApplicationFactory
1 parent e69216d commit 1e66fd8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ public virtual IServiceProvider Services
110110
}
111111
}
112112

113+
/// <summary>
114+
/// Helps determine if the `StartServer` method has been called already.
115+
/// </summary>
116+
private bool ServerStarted => _webHost != null || _host != null || _server != null;
117+
113118
/// <summary>
114119
/// Gets the <see cref="IReadOnlyList{WebApplicationFactory}"/> of factories created from this factory
115120
/// by further customizing the <see cref="IWebHostBuilder"/> when calling
@@ -239,7 +244,7 @@ private void ConfigureBuilderToUseKestrel(IWebHostBuilder builder)
239244
/// <exception cref="InvalidOperationException">Thrown if the provided <typeparamref name="TEntryPoint"/> type has no factory method.</exception>
240245
public void StartServer()
241246
{
242-
if (_webHost != null || _host != null)
247+
if (ServerStarted)
243248
{
244249
return;
245250
}

0 commit comments

Comments
 (0)