Skip to content

Commit fae3dd1

Browse files
authored
Switch to new host apis (#23783)
* Update tests * Switch to new host apis * Update host apis * Update CookieTests.cs * Update tests * PR feedback/cleanup * More cleanup
1 parent 241e45d commit fae3dd1

16 files changed

+1477
-1146
lines changed

src/Identity/test/InMemory.Test/FunctionalTest.cs

+105-100
Large diffs are not rendered by default.

src/Security/Authentication/test/AuthenticationMiddlewareTests.cs

+33-28
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.AspNetCore.Http;
99
using Microsoft.AspNetCore.TestHost;
1010
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Hosting;
1112
using Xunit;
1213

1314
namespace Microsoft.AspNetCore.Authentication
@@ -17,33 +18,38 @@ public class AuthenticationMiddlewareTests
1718
[Fact]
1819
public async Task OnlyInvokesCanHandleRequestHandlers()
1920
{
20-
var builder = new WebHostBuilder()
21-
.Configure(app =>
22-
{
23-
app.UseAuthentication();
24-
})
25-
.ConfigureServices(services => services.AddAuthentication(o =>
26-
{
27-
o.AddScheme("Skip", s =>
28-
{
29-
s.HandlerType = typeof(SkipHandler);
30-
});
31-
// Won't get hit since CanHandleRequests is false
32-
o.AddScheme("throws", s =>
33-
{
34-
s.HandlerType = typeof(ThrowsHandler);
35-
});
36-
o.AddScheme("607", s =>
37-
{
38-
s.HandlerType = typeof(SixOhSevenHandler);
39-
});
40-
// Won't get run since 607 will finish
41-
o.AddScheme("305", s =>
42-
{
43-
s.HandlerType = typeof(ThreeOhFiveHandler);
44-
});
45-
}));
46-
var server = new TestServer(builder);
21+
using var host = new HostBuilder()
22+
.ConfigureWebHost(builder =>
23+
builder.UseTestServer()
24+
.Configure(app =>
25+
{
26+
app.UseAuthentication();
27+
})
28+
.ConfigureServices(services => services.AddAuthentication(o =>
29+
{
30+
o.AddScheme("Skip", s =>
31+
{
32+
s.HandlerType = typeof(SkipHandler);
33+
});
34+
// Won't get hit since CanHandleRequests is false
35+
o.AddScheme("throws", s =>
36+
{
37+
s.HandlerType = typeof(ThrowsHandler);
38+
});
39+
o.AddScheme("607", s =>
40+
{
41+
s.HandlerType = typeof(SixOhSevenHandler);
42+
});
43+
// Won't get run since 607 will finish
44+
o.AddScheme("305", s =>
45+
{
46+
s.HandlerType = typeof(ThreeOhFiveHandler);
47+
});
48+
})))
49+
.Build();
50+
51+
await host.StartAsync();
52+
using var server = host.GetTestServer();
4753
var response = await server.CreateClient().GetAsync("http://example.com/");
4854
Assert.Equal(607, (int)response.StatusCode);
4955
}
@@ -191,6 +197,5 @@ public Task SignOutAsync(AuthenticationProperties properties)
191197
throw new NotImplementedException();
192198
}
193199
}
194-
195200
}
196201
}

0 commit comments

Comments
 (0)