Repository navigation
refactor: address NDepend immutability, static design and exception findings - #405
Merged
Merged
Conversation
…indings (#391) - ND1900: make Buyer._paymentMethods and test fields readonly; raise dotnet_style_readonly_field to warning so format enforces it. - ND1902: UserInfo.Anonymous returns a new instance per call; UpdateRoleEndpoint.BuiltInRoles is an ImmutableArray; delete the unused PublicApi UserInfo/ClaimValue. - ND1206-ND1208: AuthorizationConstants is static; delete unused BasketNotFoundException, FileItem, BlazorAdmin Cookies (and its JS) and OrderItemViewModel.Discount; HttpService helpers are static and reuse one JsonSerializerOptions. - ND2207: DeleteRoleEndpoint returns a 400 instead of throwing Exception; Manage pages and EmailVerificationService throw InvalidOperationException instead of ApplicationException. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SummarySummary
CoverageApplicationCore - 98.3%
BlazorAdmin - 9.7%
BlazorShared - 11.5%
Docker.DotNet - 29.4%
eShopWeb.AppHost - 100%
eShopWeb.AspireServiceDefaults - 78.8%
Infrastructure - 77.5%
PublicApi - 94.3%
Web - 73%
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #391
Relates to #98
The NDepend sample report came from an older snapshot, so I checked each finding against current
mainfirst. The plan, with a decision for each finding, is in.claude/plans/2026-12-01-issue-391-ndepend-immutability-static-exceptions.md.Changes
ND1900: fields should be readonly
Buyer._paymentMethodsis nowreadonly. So are the 7 test fields thatIDE0044found inCreateCatalogItemEndpointTest,CreateRoleEndpointTestandCustomerOrdersWithItemsSpecification..editorconfig:dotnet_style_readonly_fieldgoes fromsuggestiontowarning, sodotnet format --verify-no-changeskeeps this from coming back.ND1902: static fields with a mutable type
UserInfo.Anonymousused to be one shared, mutable instance thatGetCurrentUserEndpointreturned to every anonymous caller. It is now a static property that returns a new instance each time. System.Text.Json ignores static properties, so the JSON is unchanged.AuthenticateEndpoint.UserInfo/ClaimValuehad no references, so I deleted them.UpdateRoleEndpoint.BuiltInRoles:string[]→ImmutableArray<string>(same pattern, found during review).ND1206 / ND1207 / ND1208: stateless, never-instantiated, could be static
AuthorizationConstantsis now astatic class.BasketNotFoundException(never thrown; the beginner docs now nameEmptyBasketOnCheckoutExceptionas the example),Infrastructure/Data/FileItem, BlazorAdminCookieswith its twoJSInteropConstantsentries and thegetCookie/deleteCookieJS inPages/Admin/Index.cshtml, and the unusedOrderItemViewModel.Discount.HttpService:ToJsonandFromHttpResponseMessageare now static, and the code reuses one cachedJsonSerializerOptionsinstead of building a new one on every response.ND2207: too-general exception types
DeleteRoleEndpointused to throwSystem.Exception(a 500) for a role with no name. It now returns a 400 throughThrowError, the same waySaveRolesForUserEndpointdoes, and the OpenAPI description lists the 400.SaveRolesForUserEndpointalready usedThrowError, so it needed no change.ManageControllerno longer exists. Its replacements, thePages/Manage/*pages (Disable2fa, ExternalLogins, GenerateRecoveryCodes, MyAccount), andEmailVerificationServicenow throwInvalidOperationExceptioninstead ofApplicationException. Nothing catches either type.Justified, no change
PaymentMethod(ND1207): it belongs to theBuyeraggregate, which is kept as a domain-model example and is not mapped inCatalogContext. Its instances would come from EF materialization, not fromnew.ClaimValue(ND1207): a false positive in the current code.GetCurrentUserEndpointcreates instances and BlazorAdmin deserializes them.HttpService._jsonOptions(static field of a mutable type): kept on purpose. CachingJsonSerializerOptionsis the recommended pattern (CA1869), the options become read-only after first use, andApplicationCore/Extensions/JsonExtensions.csalready does the same thing.Tests and verification
UnitTests/BlazorAdmin/Authorization/UserInfoTests:Anonymousis unauthenticated with no token or claims, and changing one instance does not affect the next one.EmailVerificationServicetest to expectInvalidOperationException.DeleteRoleEndpointhas no test. The PublicApi tests are integration tests against a realRoleManager, and it will not create a role with an empty name.dotnet ./BuildTestFormat.cs: build OK. AppHostTests 6/6, EndToEndTests 2/3 (1 skipped), FunctionalTests 87/87, IntegrationTests 20/20, PublicApiIntegrationTests 158/158, UnitTests 187/187. Format clean.usingand changedBuiltInRolestoImmutableArray.🤖 Generated with Claude Code