-
Notifications
You must be signed in to change notification settings - Fork 0
test(arch): add TDD-red CachingLayerTests for IBlogPostCacheService boundary (#113) #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2d9cd8c
fefdee8
4a3a6d9
da92748
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| //======================================================= | ||
| //Copyright (c) 2026. All rights reserved. | ||
| //File Name : CachingLayerTests.cs | ||
| //Company : mpaulosky | ||
| //Author : Matthew Paulosky | ||
| //Solution Name : MyBlog | ||
| //Project Name : Architecture.Tests | ||
| //======================================================= | ||
|
|
||
| using MyBlog.Web.Features.BlogPosts.List; | ||
|
|
||
| namespace MyBlog.Architecture.Tests; | ||
|
|
||
| public class CachingLayerTests | ||
| { | ||
| private static readonly System.Reflection.Assembly WebAssembly = typeof(GetBlogPostsQuery).Assembly; | ||
|
|
||
| [Fact] | ||
| public void Features_Should_Not_Reference_IDistributedCache_Directly() | ||
| { | ||
| var result = Types.InAssembly(WebAssembly) | ||
| .That() | ||
| .ResideInNamespace("MyBlog.Web.Features") | ||
| .ShouldNot() | ||
| .HaveDependencyOnAny("Microsoft.Extensions.Caching.Distributed") | ||
| .GetResult(); | ||
|
|
||
| result.IsSuccessful.Should().BeTrue( | ||
| "VSA handlers must delegate caching to IBlogPostCacheService, not reference IDistributedCache directly"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Features_Should_Not_Reference_IMemoryCache_Directly() | ||
| { | ||
| var result = Types.InAssembly(WebAssembly) | ||
| .That() | ||
| .ResideInNamespace("MyBlog.Web.Features") | ||
| .ShouldNot() | ||
| .HaveDependencyOnAny("Microsoft.Extensions.Caching.Memory") | ||
| .GetResult(); | ||
|
Comment on lines
+35
to
+40
|
||
|
|
||
| result.IsSuccessful.Should().BeTrue( | ||
| "VSA handlers must delegate caching to IBlogPostCacheService, not reference IMemoryCache directly"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsPackable>false</IsPackable> | ||
| <IsTestProject>true</IsTestProject> | ||
| <RootNamespace>MyBlog.Domain.Tests</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="coverlet.collector"/> | ||
| <PackageReference Include="FluentAssertions"/> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
| <PackageReference Include="xunit"/> | ||
| <PackageReference Include="xunit.runner.visualstudio"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="Xunit"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\src\Domain\Domain.csproj"/> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| global using FluentAssertions; | ||
| global using MyBlog.Domain.Entities; | ||
|
Comment on lines
+1
to
+2
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResideInNamespace("MyBlog.Web.Features")only targets types in the exact namespace and will not include handlers underMyBlog.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 onMicrosoft.Extensions.Caching.Distributed. Consider switching toResideInNamespaceStartingWith("MyBlog.Web.Features")(or the include-subnamespaces overload) and, if the intent is “VSA handlers”, also filter toHaveNameEndingWith("Handler")to avoid accidentally policing non-handler feature types.