Skip to content

Commit ab33407

Browse files
committed
Expose the initialization capability
1 parent b12c354 commit ab33407

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.Initialize() -> void
23
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.Server.get -> Microsoft.AspNetCore.TestHost.TestServer?
34
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.TestServer.get -> Microsoft.AspNetCore.TestHost.ITestServer?

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public ITestServer? TestServer
9393
{
9494
get
9595
{
96-
EnsureServer();
96+
Initialize();
9797
return _server!;
9898
}
9999
}
@@ -105,7 +105,7 @@ public virtual IServiceProvider Services
105105
{
106106
get
107107
{
108-
EnsureServer();
108+
Initialize();
109109
return _host?.Services ?? _server.Host.Services;
110110
}
111111
}
@@ -154,7 +154,11 @@ internal virtual WebApplicationFactory<TEntryPoint> WithWebHostBuilderCore(Actio
154154
return factory;
155155
}
156156

157-
private void EnsureServer()
157+
/// <summary>
158+
/// Initializes the instance by configurating the host builder.
159+
/// </summary>
160+
/// <exception cref="InvalidOperationException">Thrown if the provided <see cref="TEntryPoint"/> type has no factory method.</exception>
161+
public void Initialize()
158162
{
159163
if (_server != null)
160164
{
@@ -493,7 +497,7 @@ public HttpClient CreateClient(WebApplicationFactoryClientOptions options) =>
493497
/// <returns>The <see cref="HttpClient"/>.</returns>
494498
public HttpClient CreateDefaultClient(params DelegatingHandler[] handlers)
495499
{
496-
EnsureServer();
500+
Initialize();
497501

498502
HttpClient client;
499503
if (handlers == null || handlers.Length == 0)

0 commit comments

Comments
 (0)