Skip to content

refactor: consolidate common usings into GlobalUsings.cs per project#3

Merged
mpaulosky merged 1 commit into
mainfrom
squad/global-usings-consolidation
Apr 18, 2026
Merged

refactor: consolidate common usings into GlobalUsings.cs per project#3
mpaulosky merged 1 commit into
mainfrom
squad/global-usings-consolidation

Conversation

@mpaulosky

Copy link
Copy Markdown
Owner

Summary

Consolidates common using directives into GlobalUsings.cs files in each project, reducing boilerplate and standardizing namespace access across the solution.

Changes

New GlobalUsings.cs files

Project Global usings added
src/Web Domain.Abstractions, MediatR, Microsoft.EntityFrameworkCore, Microsoft.Extensions.Caching.*, MyBlog.Domain.Entities, MyBlog.Domain.Interfaces, MyBlog.Web.Data
tests/Unit.Tests Bunit, Domain.Abstractions, FluentAssertions, Microsoft.AspNetCore.Authorization, Microsoft.AspNetCore.Components.Authorization, Microsoft.Extensions.Caching.*, MyBlog.Domain.*, NSubstitute, System.Security.Claims
tests/Integration.Tests FluentAssertions, Microsoft.EntityFrameworkCore, MyBlog.Domain.Entities, MyBlog.Web.Data
tests/Architecture.Tests FluentAssertions, MyBlog.Domain.Entities, NetArchTest.Rules

Files updated

  • 18 files in src/Web — feature handlers, commands, queries, data layer, Program.cs
  • 11 files in tests/Unit.Tests — handler tests, component tests, domain tests
  • 2 files in tests/Integration.Tests — repository tests, fixture
  • 2 files in tests/Architecture.Tests — VSA and domain layer tests

Verification

  • dotnet build MyBlog.slnx --configuration Release — 0 warnings, 0 errors
  • ✅ Unit.Tests: 61 passed, 0 failed
  • ✅ Architecture.Tests: 6 passed, 0 failed

- 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>
Copilot AI review requested due to automatic review settings April 18, 2026 18:45
@mpaulosky
mpaulosky merged commit 28bfa24 into main Apr 18, 2026
2 checks passed
@mpaulosky
mpaulosky deleted the squad/global-usings-consolidation branch April 18, 2026 18:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.cs to src/Web and each test project (Unit/Integration/Architecture).
  • Removed many per-file using directives, 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);

Copilot AI Apr 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
_ = distributedCache.RemoveAsync("blog:all", ct);
await distributedCache.RemoveAsync("blog:all", ct);

Copilot uses AI. Check for mistakes.
mpaulosky added a commit that referenced this pull request Apr 26, 2026
## 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>
mpaulosky added a commit that referenced this pull request Apr 26, 2026
## 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>
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.

2 participants