Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,4 @@ Thumbs.db

# Rider
.idea/
.nuget/
Comment thread
meaghanlewis marked this conversation as resolved.
Outdated
2 changes: 1 addition & 1 deletion aspnetcore/test/integration-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Learn how integration tests ensure that an app's components functio
monikerRange: '>= aspnetcore-3.1'
ms.author: tdykstra
ms.custom: mvc
ms.date: 3/24/2025
ms.date: 03/10/2026
uid: test/integration-tests
zone_pivot_groups: unit-testing-framework
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,21 @@ The test app can mock an <xref:Microsoft.AspNetCore.Authentication.Authenticatio

:::zone-end

The `TestAuthHandler` is called to authenticate a user when the authentication scheme is set to `TestScheme` where `AddAuthentication` is registered for `ConfigureTestServices`. It's important for the `TestScheme` scheme to match the scheme your app expects. Otherwise, authentication won't work.
The `TestAuthHandler` is called to authenticate a user when the authentication scheme is set to `TestScheme` where `AddAuthentication` is registered for `ConfigureTestServices`. `DefaultAuthenticateScheme` and `DefaultChallengeScheme` are explicitly set to `TestScheme` to ensure the test handler overrides any authentication configuration set by the app. It's important for the `TestScheme` scheme to match the scheme your app expects. Otherwise, authentication won't work.

:::zone pivot="xunit"

:::code language="csharp" source="~/test/integration-tests/snippets/xunit/IntegrationTests/AuthTests.cs" id="snippet3" highlight="7-12":::
:::code language="csharp" source="~/test/integration-tests/snippets/xunit/IntegrationTests/AuthTests.cs" id="snippet3" highlight="7-16":::

:::zone-end
:::zone pivot="mstest"

:::code language="csharp" source="~/test/integration-tests/snippets/mstest/IntegrationTests/AuthTests.cs" id="snippet3" highlight="7-12":::
:::code language="csharp" source="~/test/integration-tests/snippets/mstest/IntegrationTests/AuthTests.cs" id="snippet3" highlight="7-16":::

:::zone-end
:::zone pivot="nunit"

:::code language="csharp" source="~/test/integration-tests/snippets/nunit/IntegrationTests/AuthTests.cs" id="snippet3" highlight="7-12":::
:::code language="csharp" source="~/test/integration-tests/snippets/nunit/IntegrationTests/AuthTests.cs" id="snippet3" highlight="7-16":::

:::zone-end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ public async Task Get_SecurePageIsReturnedForAnAuthenticatedUser()
{
builder.ConfigureTestServices(services =>
{
services.AddAuthentication(defaultScheme: "TestScheme")
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = "TestScheme";
options.DefaultChallengeScheme = "TestScheme";
})
.AddScheme<AuthenticationSchemeOptions, TestAuthHandler>(
"TestScheme", options => { });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ public async Task Get_SecurePageIsReturnedForAnAuthenticatedUser()
{
builder.ConfigureTestServices(services =>
{
services.AddAuthentication(defaultScheme: "TestScheme")
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = "TestScheme";
options.DefaultChallengeScheme = "TestScheme";
})
.AddScheme<AuthenticationSchemeOptions, TestAuthHandler>(
"TestScheme", options => { });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ public async Task Get_SecurePageIsReturnedForAnAuthenticatedUser()
{
builder.ConfigureTestServices(services =>
{
services.AddAuthentication(defaultScheme: "TestScheme")
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = "TestScheme";
options.DefaultChallengeScheme = "TestScheme";
})
.AddScheme<AuthenticationSchemeOptions, TestAuthHandler>(
"TestScheme", options => { });
});
Expand Down
Loading