Skip to content

IdentityUser extension: retarget to .NET 10, NUnit 4, role services and a model test - #2200

Merged
vladimir-pecanac-main merged 3 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/94708-aspdotnet-extending-identityuser
Sep 19, 2026
Merged

vladimir-pecanac-main merged 3 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/94708-aspdotnet-extending-identityuser

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Retargets aspnetcore-features/IdentityUserExtension to .NET 10 and closes two gaps the sample had.

Retarget and packages

  • Both projects move from net7.0 to net10.0.
  • The six framework packages go to 10.0.12 (they were skewed at 7.0.7 and 7.0.9).
  • Test stack: Microsoft.NET.Test.Sdk 18.10.0, NUnit 4.6.1, NUnit3TestAdapter 6.3.0, NUnit.Analyzers 4.15.0, coverlet.collector 10.0.1. The existing assertions are already constraint-model, so NUnit 3 to 4 needed no rewrite.

Warnings

<Nullable>enable</Nullable> is on in both projects and four properties had no initializer, so the solution built with four CS8618 warnings. DisplayName, Post.Title and Post.Text are now required; Posts gets a collection expression rather than required, because the first live test constructs a user without posts. The build is clean.

Roles

AddDefaultIdentity<ApplicationUser>() routes through AddIdentityCore and registers no RoleManager, no role store and the single-generic claims factory, while this context creates AspNetRoles and AspNetUserRoles. .AddRoles<IdentityRole<Guid>>() is added in Program.cs and in TestServiceCollectionBuilder.

Migration

Regenerated on EF Core 10. The generated Up() is identical to the 2023 file column for column; only the ProductVersion annotation moves, from 7.0.9 to 10.0.12. The default schema version still creates seven Identity tables and no passkey table.

Tests

Both existing tests live in ApplicationUserLiveTest and need a real SQL Server, so CI ran zero tests on this folder under --filter "FullyQualifiedName!~Live" while reporting green. ApplicationUserModelTest builds the model over the already-referenced Sqlite provider with no database, and asserts the Guid key, the 100 character DisplayName cap and the absence of AspNetUserPasskeys at the default schema version. Three tests now run under that filter.

Built and tested on SDK 10.0.302 / runtime 10.0.10: 0 errors, 0 warnings, 3 of 3 non-Live tests passing.

Retarget both projects from net7.0 to net10.0 and move the six framework
packages to 10.0.12. Test stack moves to Microsoft.NET.Test.Sdk 18.10.0,
NUnit 4.6.1, NUnit3TestAdapter 6.3.0, NUnit.Analyzers 4.15.0 and
coverlet.collector 10.0.1; the existing assertions are constraint-model
already and needed no rewrite.

Clear the four CS8618 warnings: required on DisplayName, Post.Title and
Post.Text, and a collection expression on Posts so the first live test can
still construct a user without posts.

AddDefaultIdentity registers no RoleManager and no role store, so the
AspNetRoles and AspNetUserRoles tables this context creates had nothing
driving them. Add .AddRoles<IdentityRole<Guid>>() in Program.cs and in
TestServiceCollectionBuilder.

Add Services/UserProfileService.RecordSignIn so the article's runtime
example has a home in the sample.

Regenerate the migration on EF Core 10. The generated Up() is identical to
the 2023 file column for column; only the ProductVersion annotation moves,
from 7.0.9 to 10.0.12, and the default schema version still creates seven
Identity tables with no passkey table.

Add ApplicationUserModelTest, which builds the model over Sqlite with no
database and asserts the Guid key, the 100 character DisplayName cap and
the absence of AspNetUserPasskeys. Both existing tests carry Live in the
name, so CI ran zero tests on this folder; these three run under the
FullyQualifiedName!~Live filter.
@vladimir-pecanac-main
vladimir-pecanac-main merged commit deb3168 into CodeMazeBlog:main Sep 19, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant