test(arch): add TDD-red CachingLayerTests for IBlogPostCacheService boundary (#113) - #116
Conversation
🏗️ PR Added to Squad Triage QueueThis PR has been labeled with Next steps:
|
) - Add tests/Domain.Tests/Domain.Tests.csproj stub (unblocks Gate 3 of pre-push hook which references this project but it was deleted in #104) - Register Domain.Tests in MyBlog.slnx so release build includes it The CachingLayerTests (already committed) are [Fact(Skip)] TDD-red, pending Sam's #110 handler refactor that adopts IBlogPostCacheService. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds new architecture-test coverage intended to enforce the caching abstraction boundary in the Web “Features” layer (handlers must not depend directly on IDistributedCache/IMemoryCache, and should instead delegate caching to IBlogPostCacheService).
Changes:
- Adds two (currently skipped) NetArchTest rules to detect direct dependencies on
Microsoft.Extensions.Caching.DistributedandMicrosoft.Extensions.Caching.MemoryfromMyBlog.Web.Features. - Adds a
GlobalUsings.csfile undertests/Domain.Tests/.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
tests/Architecture.Tests/CachingLayerTests.cs |
Introduces two skipped architecture tests intended to prevent direct cache dependencies in the Features layer. |
tests/Domain.Tests/GlobalUsings.cs |
Adds global usings under a tests/Domain.Tests folder. |
| var result = Types.InAssembly(WebAssembly) | ||
| .That() | ||
| .ResideInNamespace("MyBlog.Web.Features") | ||
| .ShouldNot() | ||
| .HaveDependencyOnAny("Microsoft.Extensions.Caching.Memory") | ||
| .GetResult(); |
There was a problem hiding this comment.
Same issue as the test above: ResideInNamespace("MyBlog.Web.Features") won’t match MyBlog.Web.Features.* sub-namespaces, so this rule won’t apply to most handlers. Use ResideInNamespaceStartingWith("MyBlog.Web.Features") (or include sub-namespaces) and consider narrowing to handler types (e.g., HaveNameEndingWith("Handler")) to align with the stated goal.
| global using FluentAssertions; | ||
| global using MyBlog.Domain.Entities; |
There was a problem hiding this comment.
This file is under tests/Domain.Tests/, but there is no Domain.Tests.csproj and MyBlog.slnx doesn’t include a Domain.Tests project, so these global usings won’t be compiled or used. Either add/restore a Domain.Tests test project and include it in the solution, or remove this folder/file to avoid orphaned, misleading code.
| var result = Types.InAssembly(WebAssembly) | ||
| .That() | ||
| .ResideInNamespace("MyBlog.Web.Features") | ||
| .ShouldNot() | ||
| .HaveDependencyOnAny("Microsoft.Extensions.Caching.Distributed") | ||
| .GetResult(); |
There was a problem hiding this comment.
ResideInNamespace("MyBlog.Web.Features") only targets types in the exact namespace and will not include handlers under MyBlog.Web.Features.* (e.g., MyBlog.Web.Features.BlogPosts.List). Once the [Fact] is un-skipped, this test will likely pass even if handlers still depend on Microsoft.Extensions.Caching.Distributed. Consider switching to ResideInNamespaceStartingWith("MyBlog.Web.Features") (or the include-subnamespaces overload) and, if the intent is “VSA handlers”, also filter to HaveNameEndingWith("Handler") to avoid accidentally policing non-handler feature types.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## sprint/5-redis-caching #116 +/- ##
=========================================================
Coverage ? 70.38%
=========================================================
Files ? 43
Lines ? 672
Branches ? 111
=========================================================
Hits ? 473
Misses ? 147
Partials ? 52 🚀 New features to boost your workflow:
|
…ad/113-arch-caching-test
Sam's #115 and #118 have merged, so handlers now use IBlogPostCacheService. Both arch tests pass green: - Features_Should_Not_Reference_IDistributedCache_Directly - Features_Should_Not_Reference_IMemoryCache_Directly Closes #113 Working as Gimli (Tester) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Closes #113
Working as Gimli (Tester)
What
Adds TDD-red architecture tests enforcing that VSA handlers in
MyBlog.Web.Featuresmust NOT directly referenceIDistributedCacheorIMemoryCache— they must delegate all caching toIBlogPostCacheService.Tests are currently skipped (TDD-red) pending #110 (handler refactor). Remove the
Skipattributes once #110 merges.Changes
tests/Architecture.Tests/CachingLayerTests.csFeatures_Should_Not_Reference_IDistributedCache_Directly,Features_Should_Not_Reference_IMemoryCache_Directlytests/Domain.Tests/GlobalUsings.cstests/Domain.Tests/Domain.Tests.csprojMyBlog.slnxDomain.Testsso Release build compiles it before--no-buildtest runActivation
Remove the
Skipattribute from both facts inCachingLayerTests.csafter #110 merges:Related
squad/109-cache-abstraction)