refactor: consolidate common usings into GlobalUsings.cs per project#3
Conversation
- Add GlobalUsings.cs to src/Web, tests/Unit.Tests, tests/Integration.Tests, tests/Architecture.Tests - Strip promoted using directives from all individual source files - All 61 unit tests and 6 architecture tests pass Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR consolidates common C# using directives into per-project GlobalUsings.cs files to reduce boilerplate and standardize namespace availability across the Web app and test projects.
Changes:
- Added
GlobalUsings.cstosrc/Weband each test project (Unit/Integration/Architecture). - Removed many per-file
usingdirectives, relying on global usings instead. - Reformatted touched files to match repo indentation/formatting.
Reviewed changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit.Tests/Testing/TestAuthorizationService.cs | Removes local usings; relies on Unit test global usings. |
| tests/Unit.Tests/Security/RoleClaimsHelperTests.cs | Removes local usings; relies on Unit test global usings. |
| tests/Unit.Tests/ResultTests.cs | Removes local usings; relies on Unit test global usings. |
| tests/Unit.Tests/Handlers/GetBlogPostsHandlerTests.cs | Removes local usings; relies on Unit test global usings. |
| tests/Unit.Tests/Handlers/EditBlogPostHandlerTests.cs | Removes local usings; relies on Unit test global usings. |
| tests/Unit.Tests/Handlers/DeleteBlogPostHandlerTests.cs | Removes local usings; relies on Unit test global usings. |
| tests/Unit.Tests/Handlers/CreateBlogPostHandlerTests.cs | Removes local usings; relies on Unit test global usings. |
| tests/Unit.Tests/GlobalUsings.cs | Adds global usings for commonly used Unit test namespaces. |
| tests/Unit.Tests/Features/UserManagement/ProfileTests.cs | Removes local usings; relies on Unit test global usings. |
| tests/Unit.Tests/Components/RazorSmokeTests.cs | Removes some local usings; continues using explicit component usings. |
| tests/Unit.Tests/Components/Layout/NavMenuTests.cs | Removes local usings; relies on Unit test global usings. |
| tests/Unit.Tests/BlogPostTests.cs | Removes local usings; relies on Unit test global usings. |
| tests/Integration.Tests/Infrastructure/MongoDbFixture.cs | Removes local usings; relies on Integration test global usings. |
| tests/Integration.Tests/GlobalUsings.cs | Adds global usings for commonly used Integration test namespaces. |
| tests/Integration.Tests/BlogPosts/MongoDbBlogPostRepositoryTests.cs | Removes local usings; relies on Integration test global usings. |
| tests/Architecture.Tests/VsaLayerTests.cs | Removes local usings; relies on Architecture test global usings. |
| tests/Architecture.Tests/GlobalUsings.cs | Adds global usings for commonly used Architecture test namespaces. |
| tests/Architecture.Tests/DomainLayerTests.cs | Removes local usings; relies on Architecture test global usings. |
| src/Web/Program.cs | Removes local usings (moved to global); retains local Claims using. |
| src/Web/GlobalUsings.cs | Adds global usings for commonly used Web project namespaces. |
| src/Web/Features/UserManagement/UserManagementHandler.cs | Removes local usings; relies on Web global usings/implicit usings. |
| src/Web/Features/UserManagement/RemoveRoleCommand.cs | Removes local usings; relies on Web global usings. |
| src/Web/Features/UserManagement/GetUsersWithRolesQuery.cs | Removes local usings; relies on Web global usings. |
| src/Web/Features/UserManagement/GetAvailableRolesQuery.cs | Removes local usings; relies on Web global usings. |
| src/Web/Features/UserManagement/AssignRoleCommand.cs | Removes local usings; relies on Web global usings. |
| src/Web/Features/BlogPosts/List/GetBlogPostsQuery.cs | Removes local usings; relies on Web global usings. |
| src/Web/Features/BlogPosts/List/GetBlogPostsHandler.cs | Removes local usings; relies on Web global usings. |
| src/Web/Features/BlogPosts/Edit/GetBlogPostByIdQuery.cs | Removes local usings; relies on Web global usings. |
| src/Web/Features/BlogPosts/Edit/EditBlogPostHandler.cs | Removes local usings; relies on Web global usings. |
| src/Web/Features/BlogPosts/Edit/EditBlogPostCommand.cs | Removes local usings; relies on Web global usings. |
| src/Web/Features/BlogPosts/Delete/DeleteBlogPostHandler.cs | Removes local usings; relies on Web global usings. |
| src/Web/Features/BlogPosts/Delete/DeleteBlogPostCommand.cs | Removes local usings; relies on Web global usings. |
| src/Web/Features/BlogPosts/Create/CreateBlogPostHandler.cs | Removes local usings; relies on Web global usings. |
| src/Web/Features/BlogPosts/Create/CreateBlogPostCommand.cs | Removes local usings; relies on Web global usings. |
| src/Web/Data/MongoDbBlogPostRepository.cs | Removes local usings; relies on Web global usings. |
| src/Web/Data/BlogPostMappings.cs | Removes local usings; relies on Web global usings. |
| src/Web/Data/BlogDbContext.cs | Removes local usings; relies on Web global usings. |
| var post = BlogPost.Create(request.Title, request.Content, request.Author); | ||
| await repo.AddAsync(post, ct); | ||
| localCache.Remove("blog:all"); | ||
| _ = distributedCache.RemoveAsync("blog:all", ct); |
There was a problem hiding this comment.
distributedCache.RemoveAsync("blog:all", ct) is invoked fire-and-forget (_ = ...) and not awaited. This can leave Redis cache invalidation racing with the response (stale reads right after create) and can also drop exceptions from the cache backend. Consider awaiting the call (as Edit/Delete handlers do) or explicitly handling/logging failures if you intentionally want it to be best-effort.
| _ = distributedCache.RemoveAsync("blog:all", ct); | |
| await distributedCache.RemoveAsync("blog:all", ct); |
## Summary Migrates Architecture.Tests test methods to xUnit v3 API conventions, following the Sprint 7 Domain.Tests pilot pattern. Closes #178 **Working as Gimli (Tester)** --- ## What Changed All 4 test files updated with proper xUnit v3 migration conventions: | File | Tests | Change | |------|-------|--------| | `DomainLayerTests.cs` | 4 | AAA comments + extract `assembly` variable for clean Arrange/Act split | | `VsaLayerTests.cs` | 3 | AAA comments + extract `domainAssembly` variable | | `ThemeLayerTests.cs` | 2 | AAA comments | | `CachingLayerTests.cs` | 2 | AAA comments | **Total: 11 tests migrated** ## xUnit v3 API Observations - `[Fact]` attribute is **identical** in xUnit v2 and v3 — no attribute changes required - No async/await patterns in architecture tests — no lifecycle changes needed - No `IClassFixture` / `ICollectionFixture` — stateless tests, no collection changes needed - FluentAssertions `.Should()` works unchanged with xUnit v3 - Parallelization via `xunit.runner.json` was already configured in Wave 1 (#182) ## Pattern Reference (Sprint 7 Domain.Tests Pilot) Followed the same approach as the Sprint 7 Domain.Tests migration: - xUnit v3 meta-package via `<PackageReference Include="xunit.v3"/>` ✅ (Wave 1) - `xunit.runner.json` with `parallelizeAssembly: true` ✅ (Wave 1) - Gimli Rule #3: AAA comments on all test methods ✅ (this PR) - Gimli Rule #6: File headers present on all files ✅ (pre-existing) ## Test Results ``` Passed! - Failed: 0, Passed: 11, Skipped: 0, Total: 11 — Architecture.Tests.dll Passed! - Failed: 0, Passed: 42, Skipped: 0, Total: 42 — Domain.Tests.dll ``` Zero failures. Ready to merge to `sprint/8-xunit-v3-pilot`. Co-authored-by: Boromir <boromir@squad.dev> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
## Summary Post-migration validation for Architecture.Tests xUnit v3 migration. No failures found. Closes #179 **Working as Gimli (Tester)** --- ## Findings After applying the xUnit v3 migration in PR #184, all 11 architecture tests pass with zero failures: ``` Passed! - Failed: 0, Passed: 11, Skipped: 0, Total: 11 — Architecture.Tests.dll (72ms) ``` **No fixes required.** The Architecture.Tests migration in Wave 2 is clean. ## Root Cause Analysis xUnit v3 is fully backward-compatible for all patterns used in Architecture.Tests: - `[Fact]` — identical in v2 and v3 ✅ - FluentAssertions `.Should()` — unchanged ✅ - NetArchTest.Rules builder chain — unchanged ✅ - No `IClassFixture` / `ICollectionFixture` patterns in use ✅ - No xUnit lifecycle overrides (`IAsyncLifetime`, `SetupAttribute`) ✅ The only migration work was Gimli Rule #3 compliance (AAA comments), which is purely cosmetic and cannot introduce test failures. ## Deliverables - ✅ Validated: 11 tests pass with xUnit v3 3.2.2 - ✅ Appended Sprint 8 Wave 2 learnings to `.squad/agents/gimli/history.md` - ✅ Drafted `gimli-xunit-v3-migration-pattern.md` decision (in local decisions inbox for Scribe) ## Prerequisite This PR should merge after #184 is merged to `sprint/8-xunit-v3-pilot`. Co-authored-by: Boromir <boromir@squad.dev> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
Consolidates common
usingdirectives intoGlobalUsings.csfiles in each project, reducing boilerplate and standardizing namespace access across the solution.Changes
New
GlobalUsings.csfilessrc/WebDomain.Abstractions,MediatR,Microsoft.EntityFrameworkCore,Microsoft.Extensions.Caching.*,MyBlog.Domain.Entities,MyBlog.Domain.Interfaces,MyBlog.Web.Datatests/Unit.TestsBunit,Domain.Abstractions,FluentAssertions,Microsoft.AspNetCore.Authorization,Microsoft.AspNetCore.Components.Authorization,Microsoft.Extensions.Caching.*,MyBlog.Domain.*,NSubstitute,System.Security.Claimstests/Integration.TestsFluentAssertions,Microsoft.EntityFrameworkCore,MyBlog.Domain.Entities,MyBlog.Web.Datatests/Architecture.TestsFluentAssertions,MyBlog.Domain.Entities,NetArchTest.RulesFiles updated
src/Web— feature handlers, commands, queries, data layer,Program.cstests/Unit.Tests— handler tests, component tests, domain teststests/Integration.Tests— repository tests, fixturetests/Architecture.Tests— VSA and domain layer testsVerification
dotnet build MyBlog.slnx --configuration Release— 0 warnings, 0 errors