Skip to content

Commit 95e6eaa

Browse files
committed
fix tests
1 parent d028735 commit 95e6eaa

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/HostingTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,16 @@ public async Task WebhostLoadsKeyRingBeforeServerStarts()
2525
.Returns(Mock.Of<IKeyRing>())
2626
.Callback(() => tcs.TrySetResult());
2727

28-
var builder = new HostBuilder()
29-
.ConfigureWebHost(webHostBuilder =>
30-
{
31-
webHostBuilder
32-
.UseStartup<TestStartup>();
33-
})
28+
#pragma warning disable CS0618 // Type or member is obsolete
29+
var builder = new WebHostBuilder()
30+
.UseStartup<TestStartup>()
3431
.ConfigureServices(s =>
3532
s.AddDataProtection()
3633
.Services
3734
.Replace(ServiceDescriptor.Singleton(mockKeyRing.Object))
3835
.AddSingleton<IServer>(
3936
new FakeServer(onStart: () => tcs.TrySetException(new InvalidOperationException("Server was started before key ring was initialized")))));
37+
#pragma warning restore CS0618 // Type or member is obsolete
4038

4139
using (var host = builder.Build())
4240
{

src/Servers/Kestrel/Kestrel/test/HttpsConfigurationTests.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,21 @@ public async Task BindAddressFromSetting(string address, bool useKestrelHttpsCon
4242
}
4343
});
4444

45-
var host = hostBuilder.Build();
46-
await host.StartAsync();
47-
48-
Assert.Single(host.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>().Addresses, address);
45+
using var host = hostBuilder.Build();
4946

5047
if (address.StartsWith("https", StringComparison.OrdinalIgnoreCase) && !useKestrelHttpsConfiguration)
5148
{
52-
Assert.Throws<InvalidOperationException>(host.Run);
49+
Assert.Throws<InvalidOperationException>(host.Start);
50+
Assert.Empty(host.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>().Addresses);
5351
}
5452
else
5553
{
56-
// Binding succeeds - server is already started, so we just stop it
57-
await host.StopAsync();
54+
//// Binding succeeds - server is already started, so we just stop it
55+
await host.StartAsync();
56+
57+
var addr = Assert.Single(host.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>().Addresses);
58+
// addr will contain the realized port, so we'll remove the port for comparison
59+
Assert.Equal(address[..^2].ToString(), addr.Substring(0, addr.LastIndexOf(':')));
5860
}
5961
}
6062

0 commit comments

Comments
 (0)