Skip to content

Commit

Permalink
Switch to new host apis (#23783)
Browse files Browse the repository at this point in the history
* Update tests

* Switch to new host apis

* Update host apis

* Update CookieTests.cs

* Update tests

* PR feedback/cleanup

* More cleanup
  • Loading branch information
HaoK authored Jul 11, 2020
1 parent 241e45d commit fae3dd1
Show file tree
Hide file tree
Showing 16 changed files with 1,477 additions and 1,146 deletions.
205 changes: 105 additions & 100 deletions src/Identity/test/InMemory.Test/FunctionalTest.cs

Large diffs are not rendered by default.

61 changes: 33 additions & 28 deletions src/Security/Authentication/test/AuthenticationMiddlewareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Xunit;

namespace Microsoft.AspNetCore.Authentication
Expand All @@ -17,33 +18,38 @@ public class AuthenticationMiddlewareTests
[Fact]
public async Task OnlyInvokesCanHandleRequestHandlers()
{
var builder = new WebHostBuilder()
.Configure(app =>
{
app.UseAuthentication();
})
.ConfigureServices(services => services.AddAuthentication(o =>
{
o.AddScheme("Skip", s =>
{
s.HandlerType = typeof(SkipHandler);
});
// Won't get hit since CanHandleRequests is false
o.AddScheme("throws", s =>
{
s.HandlerType = typeof(ThrowsHandler);
});
o.AddScheme("607", s =>
{
s.HandlerType = typeof(SixOhSevenHandler);
});
// Won't get run since 607 will finish
o.AddScheme("305", s =>
{
s.HandlerType = typeof(ThreeOhFiveHandler);
});
}));
var server = new TestServer(builder);
using var host = new HostBuilder()
.ConfigureWebHost(builder =>
builder.UseTestServer()
.Configure(app =>
{
app.UseAuthentication();
})
.ConfigureServices(services => services.AddAuthentication(o =>
{
o.AddScheme("Skip", s =>
{
s.HandlerType = typeof(SkipHandler);
});
// Won't get hit since CanHandleRequests is false
o.AddScheme("throws", s =>
{
s.HandlerType = typeof(ThrowsHandler);
});
o.AddScheme("607", s =>
{
s.HandlerType = typeof(SixOhSevenHandler);
});
// Won't get run since 607 will finish
o.AddScheme("305", s =>
{
s.HandlerType = typeof(ThreeOhFiveHandler);
});
})))
.Build();

await host.StartAsync();
using var server = host.GetTestServer();
var response = await server.CreateClient().GetAsync("http://example.com/");
Assert.Equal(607, (int)response.StatusCode);
}
Expand Down Expand Up @@ -191,6 +197,5 @@ public Task SignOutAsync(AuthenticationProperties properties)
throw new NotImplementedException();
}
}

}
}
Loading

0 comments on commit fae3dd1

Please sign in to comment.