Skip to content

test(unit): add handler unit tests for IBlogPostCacheService (#111) - #117

Merged
mpaulosky merged 2 commits into
sprint/5-redis-cachingfrom
squad/111-caching-unit-tests
Apr 24, 2026
Merged

test(unit): add handler unit tests for IBlogPostCacheService (#111)#117
mpaulosky merged 2 commits into
sprint/5-redis-cachingfrom
squad/111-caching-unit-tests

Conversation

@mpaulosky

Copy link
Copy Markdown
Owner

Closes #111

Working as Gimli (Tester)

Summary

Adds a new Unit.Tests project with TDD-red handler unit tests that document the expected IBlogPostCacheService contract after Sam's #110 handler refactor. Tests are marked with the TDD-red pattern — they exist as executable specifications but will not compile on sprint/5-redis-caching until #110 merges.

Also adds the Domain.Tests stub project (required by Gate 3 of the pre-push hook, removed in #104) and registers it in MyBlog.slnx.

Why TDD-red?

IBlogPostCacheService (introduced in #109) is only available on squad/109-cache-abstraction / squad/110-handler-refactor. The handler constructors on sprint/5 still use IMemoryCache + IDistributedCache. Adding Unit.Tests to MyBlog.slnx would fail Gate 2 on this branch, so the project is present on disk but not registered in the solution file until #110 merges.

Changes

File What
tests/Unit.Tests/Unit.Tests.csproj New test project (net10.0, xunit, NSubstitute, FluentAssertions)
tests/Unit.Tests/GlobalUsings.cs Global usings including IBlogPostCacheService
tests/Unit.Tests/Handlers/GetBlogPostsHandlerTests.cs 3 tests: delegates to cache, fetch-on-miss, exception→fail
tests/Unit.Tests/Handlers/GetBlogPostByIdHandlerTests.cs 4 tests: id forwarded, cache-miss, null from repo, exception
tests/Unit.Tests/Handlers/CreateBlogPostHandlerTests.cs 3 tests: success+InvalidateAllAsync, no InvalidateById, repo throws
tests/Unit.Tests/Handlers/EditBlogPostHandlerTests.cs 3 tests: success invalidates both keys, NotFound, concurrency
tests/Unit.Tests/Handlers/DeleteBlogPostHandlerTests.cs 3 tests: success invalidates both keys, repo throws, concurrency
tests/Domain.Tests/Domain.Tests.csproj Stub project (re-added for Gate 3)
tests/Domain.Tests/GlobalUsings.cs Minimal usings for stub
MyBlog.slnx Add Domain.Tests only (Unit.Tests excluded until #110 merges)

Depends On

⚠️ This task was flagged as "needs review" — Unit.Tests does not compile on sprint/5-redis-caching base. Please have a squad member verify test contracts match Sam's #110 implementation before merging.

Copilot AI review requested due to automatic review settings April 24, 2026 01:34
@github-actions github-actions Bot added the squad Squad triage inbox — Lead will assign to a member label Apr 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🏗️ PR Added to Squad Triage Queue

This PR has been labeled with squad and added to the triage queue.

Next steps:

  • The squad Lead will review and assign to an appropriate team member
  • A squad:member label will be added after triage

If you know which squad member should handle this, you can add the appropriate squad:member label yourself.

@github-actions

github-actions Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Test Results Summary

203 tests   203 ✅  14s ⏱️
  5 suites    0 💤
  5 files      0 ❌

Results for commit 05ac5fc.

♻️ This comment has been updated with latest results.

@codecov

codecov Bot commented Apr 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (sprint/5-redis-caching@239da3b). Learn more about missing BASE report.

Additional details and impacted files
@@                    Coverage Diff                    @@
##             sprint/5-redis-caching     #117   +/-   ##
=========================================================
  Coverage                          ?   70.38%           
=========================================================
  Files                             ?       43           
  Lines                             ?      672           
  Branches                          ?      111           
=========================================================
  Hits                              ?      473           
  Misses                            ?      147           
  Partials                          ?       52           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Adds new (currently TDD-red) unit-test specifications for the upcoming IBlogPostCacheService-based handler refactor, and reintroduces a stub Domain.Tests project to satisfy the repo’s pre-push Gate 3 expectations.

Changes:

  • Add a new tests/Unit.Tests project with handler tests written against the future IBlogPostCacheService contract (intentionally not wired into MyBlog.slnx yet).
  • Add a stub tests/Domain.Tests project and register it in MyBlog.slnx.
  • Add supporting global usings for the new test projects.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Unit.Tests/Unit.Tests.csproj New Unit test project targeting net10.0 with xUnit/NSubstitute/FluentAssertions references.
tests/Unit.Tests/GlobalUsings.cs Adds global usings for Unit.Tests, including caching abstractions.
tests/Unit.Tests/Handlers/GetBlogPostsHandlerTests.cs TDD-red tests describing expected caching delegation behavior for “get all” handler.
tests/Unit.Tests/Handlers/GetBlogPostByIdHandlerTests.cs TDD-red tests describing expected caching delegation behavior for “get by id” query path.
tests/Unit.Tests/Handlers/CreateBlogPostHandlerTests.cs TDD-red tests for create behavior + cache invalidation expectations.
tests/Unit.Tests/Handlers/EditBlogPostHandlerTests.cs TDD-red tests for edit behavior, invalidation expectations, and concurrency error mapping.
tests/Unit.Tests/Handlers/DeleteBlogPostHandlerTests.cs TDD-red tests for delete behavior, invalidation expectations, and concurrency error mapping.
tests/Domain.Tests/Domain.Tests.csproj Stub Domain.Tests project (net10.0) to satisfy local Gate 3 requirements.
tests/Domain.Tests/GlobalUsings.cs Minimal global usings for Domain.Tests stub.
MyBlog.slnx Registers tests/Domain.Tests in the solution.

<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>MyBlog.Unit.Tests</RootNamespace>
Boromir and others added 2 commits April 23, 2026 18:55
…111)

Add Unit.Tests project with 5 handler test files covering the post-#110
IBlogPostCacheService contract. Tests are intentionally TDD-red and will not
compile until Sam's #110 handler refactor merges IBlogPostCacheService into
sprint/5-redis-caching. Also adds Domain.Tests stub (required by Gate 3) and
registers it in MyBlog.slnx. Unit.Tests is NOT added to slnx to avoid Gate 2
build failure on this branch.

- GetBlogPostsHandlerTests: delegates to cache, fetch-on-miss, exception→fail
- GetBlogPostByIdHandlerTests: id forwarded, cache-miss invokes repo, null, exception
- CreateBlogPostHandlerTests: success + InvalidateAllAsync, no InvalidateById, repo throws
- EditBlogPostHandlerTests: success invalidates both keys, NotFound, concurrency
- DeleteBlogPostHandlerTests: success invalidates both keys, repo throws, concurrency

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… slnx

Sam's #115 (IBlogPostCacheService) and #118 (handler refactor) have merged.
Changes:
- Add Unit.Tests to MyBlog.slnx (safe now that IBlogPostCacheService exists)
- Fix 3 NSubstitute mock setups: async lambda → ValueTask<T>(task) ctor
  (NSubstitute cannot convert async lambdas to ValueTask<T> return type)

All 16 unit tests pass green across 5 handler test classes.

Closes #111
Working as Gimli (Tester)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mpaulosky
mpaulosky force-pushed the squad/111-caching-unit-tests branch from e48d72d to 05ac5fc Compare April 24, 2026 01:56
@mpaulosky
mpaulosky merged commit 29cb8f4 into sprint/5-redis-caching Apr 24, 2026
10 of 11 checks passed
@mpaulosky
mpaulosky deleted the squad/111-caching-unit-tests branch April 24, 2026 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

squad Squad triage inbox — Lead will assign to a member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants