Skip to content

Commit 1bc557f

Browse files
committed
Fixed the errors and test failures.
1 parent ab33407 commit 1bc557f

8 files changed

+16
-10
lines changed

src/Mvc/Mvc.Testing/src/PublicAPI.Shipped.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.CreateDefaul
1616
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.CreateDefaultClient(System.Uri! baseAddress, params System.Net.Http.DelegatingHandler![]! handlers) -> System.Net.Http.HttpClient!
1717
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.Dispose() -> void
1818
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.Factories.get -> System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint!>!>!
19-
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.Server.get -> Microsoft.AspNetCore.TestHost.TestServer!
2019
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.WebApplicationFactory() -> void
2120
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.WithWebHostBuilder(System.Action<Microsoft.AspNetCore.Hosting.IWebHostBuilder!>! configuration) -> Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint!>!
2221
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions
@@ -41,7 +40,6 @@ virtual Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.Conf
4140
virtual Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder! builder) -> void
4241
virtual Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.CreateHost(Microsoft.Extensions.Hosting.IHostBuilder! builder) -> Microsoft.Extensions.Hosting.IHost!
4342
virtual Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.CreateHostBuilder() -> Microsoft.Extensions.Hosting.IHostBuilder?
44-
virtual Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.CreateServer(Microsoft.AspNetCore.Hosting.IWebHostBuilder! builder) -> Microsoft.AspNetCore.TestHost.TestServer!
4543
virtual Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.CreateWebHostBuilder() -> Microsoft.AspNetCore.Hosting.IWebHostBuilder?
4644
virtual Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.Dispose(bool disposing) -> void
4745
virtual Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.DisposeAsync() -> System.Threading.Tasks.ValueTask

src/Mvc/Mvc.Testing/src/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.Initialize() -> void
33
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.Server.get -> Microsoft.AspNetCore.TestHost.TestServer?
44
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.TestServer.get -> Microsoft.AspNetCore.TestHost.ITestServer?
5+
virtual Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>.CreateServer(Microsoft.AspNetCore.Hosting.IWebHostBuilder! builder) -> Microsoft.AspNetCore.TestHost.ITestServer!

src/Mvc/Mvc.Testing/src/Resources.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema
@@ -120,6 +120,9 @@
120120
<data name="InvalidAssemblyEntryPoint" xml:space="preserve">
121121
<value>The provided Type '{0}' does not belong to an assembly with an entry point. A common cause for this error is providing a Type from a class library.</value>
122122
</data>
123+
<data name="InvalidTestServerConfiguration" xml:space="preserve">
124+
<value>The host doesn't contain a valid ITestServer configuration.</value>
125+
</data>
123126
<data name="MissingBuilderMethod" xml:space="preserve">
124127
<value>No method 'public static {0} CreateHostBuilder(string[] args)' or 'public static {1} CreateWebHostBuilder(string[] args)' found on '{2}'. Alternatively, {3} can be extended and '{4}' or '{5}' can be overridden to provide your own instance.</value>
125128
</data>

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public partial class WebApplicationFactory<TEntryPoint> : IDisposable, IAsyncDis
3737
private readonly List<HttpClient> _clients = new();
3838
private readonly List<WebApplicationFactory<TEntryPoint>> _derivedFactories = new();
3939

40-
4140
/// <summary>
4241
/// <para>
4342
/// Creates an instance of <see cref="WebApplicationFactory{TEntryPoint}"/>. This factory can be used to
@@ -94,7 +93,7 @@ public ITestServer? TestServer
9493
get
9594
{
9695
Initialize();
97-
return _server!;
96+
return _server;
9897
}
9998
}
10099

@@ -157,7 +156,8 @@ internal virtual WebApplicationFactory<TEntryPoint> WithWebHostBuilderCore(Actio
157156
/// <summary>
158157
/// Initializes the instance by configurating the host builder.
159158
/// </summary>
160-
/// <exception cref="InvalidOperationException">Thrown if the provided <see cref="TEntryPoint"/> type has no factory method.</exception>
159+
/// <exception cref="InvalidOperationException">Thrown if the provided <typeparamref name="TEntryPoint"/> type has no factory method.</exception>
160+
[MemberNotNull(nameof(_server))]
161161
public void Initialize()
162162
{
163163
if (_server != null)
@@ -233,6 +233,10 @@ private void ConfigureHostBuilder(IHostBuilder hostBuilder)
233233
});
234234
_host = CreateHost(hostBuilder);
235235
_server = _host.Services.GetRequiredService<IServer>() as ITestServer;
236+
if (_server is null)
237+
{
238+
throw new InvalidOperationException(Resources.InvalidTestServerConfiguration);
239+
}
236240
}
237241

238242
private void SetContentRoot(IWebHostBuilder builder)

src/Mvc/test/Mvc.FunctionalTests/ApiExplorerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ public async Task ApiExplorer_LogsInvokedDescriptionProvidersOnStartup()
15731573
[Fact]
15741574
public void ApiExplorer_BuildsMetadataForActionWithTypedResult()
15751575
{
1576-
var apiDescCollectionProvider = Factory.Server.Services.GetService<IApiDescriptionGroupCollectionProvider>();
1576+
var apiDescCollectionProvider = Factory.Services.GetService<IApiDescriptionGroupCollectionProvider>();
15771577
var testGroupName = nameof(ApiExplorerWithTypedResultController).Replace("Controller", string.Empty);
15781578
var group = apiDescCollectionProvider.ApiDescriptionGroups.Items.Where(i => i.GroupName == testGroupName).SingleOrDefault();
15791579
Assert.NotNull(group);

src/Mvc/test/Mvc.FunctionalTests/ComponentRenderingFunctionalTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private HttpClient CreateClient(
198198

199199
// We configure the inner handler with a handler to this TestServer instance so that calls to the
200200
// server can get routed properly.
201-
loopHandler.InnerHandler = fixture.Server.CreateHandler();
201+
loopHandler.InnerHandler = fixture.TestServer.CreateHandler();
202202

203203
void ConfigureTestWeatherForecastService(IServiceCollection services) =>
204204
// We configure the test service here with an HttpClient that uses this loopback handler to talk

src/Mvc/test/Mvc.FunctionalTests/Infrastructure/MvcTestFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
4242
});
4343
}
4444

45-
protected override TestServer CreateServer(IWebHostBuilder builder)
45+
protected override ITestServer CreateServer(IWebHostBuilder builder)
4646
{
4747
var originalCulture = CultureInfo.CurrentCulture;
4848
var originalUICulture = CultureInfo.CurrentUICulture;

src/Mvc/test/Mvc.FunctionalTests/TestingInfrastructureInheritanceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
141141
base.ConfigureWebHost(builder);
142142
}
143143

144-
protected override TestServer CreateServer(IWebHostBuilder builder)
144+
protected override ITestServer CreateServer(IWebHostBuilder builder)
145145
{
146146
CreateServerCalled = true;
147147
return base.CreateServer(builder);

0 commit comments

Comments
 (0)