Skip to content

Commit e47e719

Browse files
Add test for the CreatingTicket event
Add an integration test that validates that all providers raise the OnCreatingTicket event.
1 parent befa2fe commit e47e719

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/AspNet.Security.OAuth.Providers.Tests/OAuthTests`1.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using Microsoft.AspNetCore.Mvc.Testing;
2424
using Microsoft.Extensions.DependencyInjection;
2525
using Shouldly;
26+
using Xunit;
2627
using Xunit.Abstractions;
2728

2829
namespace AspNet.Security.OAuth
@@ -133,6 +134,38 @@ protected HttpClient CreateBackchannel(AuthenticationBuilder builder)
133134

134135
public LoopbackRedirectHandler LoopbackRedirectHandler { get; set; }
135136

137+
[Fact]
138+
public async Task OnCreatingTicket_Is_Raised_By_Handler()
139+
{
140+
// Arrange
141+
bool onCreatingTicketEventRaised = false;
142+
143+
void ConfigureServices(IServiceCollection services)
144+
{
145+
services.PostConfigureAll<TOptions>((options) =>
146+
{
147+
options.Events.OnCreatingTicket = (context) =>
148+
{
149+
onCreatingTicketEventRaised = true;
150+
return Task.CompletedTask;
151+
};
152+
153+
if (options is Apple.AppleAuthenticationOptions appleOptions)
154+
{
155+
appleOptions.ValidateTokens = false; // Apple test token has expired
156+
}
157+
});
158+
}
159+
160+
using var server = CreateTestServer(ConfigureServices);
161+
162+
// Act
163+
var claims = await AuthenticateUserAsync(server);
164+
165+
// Assert
166+
onCreatingTicketEventRaised.ShouldBeTrue();
167+
}
168+
136169
/// <summary>
137170
/// Run the ChannelAsync for authentication
138171
/// </summary>

0 commit comments

Comments
 (0)