Skip to content

test: add unit tests for BlogPost, Result, and ValidationBehavior#145

Merged
mpaulosky merged 3 commits into
sprint/6-code-qualityfrom
squad/141-domain-tests
Apr 24, 2026
Merged

test: add unit tests for BlogPost, Result, and ValidationBehavior#145
mpaulosky merged 3 commits into
sprint/6-code-qualityfrom
squad/141-domain-tests

Conversation

@mpaulosky

Copy link
Copy Markdown
Owner

Closes #141

Working as Gimli, the Tester (QA Engineer)

Changes

Adds 42 unit tests across three new test files in tests/Domain.Tests/:

File Tests Coverage
Entities/BlogPostTests.cs 14 BlogPost.Create, Update, Publish, Unpublish, guard clauses
Abstractions/ResultTests.cs 13 Result.Ok, Result.Fail, Result.Ok<T>, Result.Fail<T>, Result.FromValue<T>, implicit conversions
Behaviors/ValidationBehaviorTests.cs 9 No-validators path, passing validator, failing validator, multi-validator join, next delegation

Also adds NSubstitute, FluentValidation, and MediatR package references to Domain.Tests.csproj and the corresponding global usings.

Verification

Passed! - Failed: 0, Passed: 42, Skipped: 0, Total: 42

Boromir and others added 2 commits April 24, 2026 11:41
…closes #137

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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 24, 2026 18:46
@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.

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 unit test coverage for key Domain building blocks (BlogPost entity, Result type, and MediatR ValidationBehavior) and performs a small cancellation-token naming cleanup in several Web handlers.

Changes:

  • Added new unit tests in tests/Domain.Tests for BlogPost, Result, and ValidationBehavior.
  • Updated tests/Domain.Tests project configuration (package references + global usings).
  • Renamed ct to cancellationToken in several Web feature handlers for consistency.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Domain.Tests/GlobalUsings.cs Adds global usings needed by the new Domain unit tests (FluentValidation, MediatR, NSubstitute, Domain namespaces).
tests/Domain.Tests/Entities/BlogPostTests.cs Adds coverage for BlogPost create/update/publish/unpublish and guard clauses.
tests/Domain.Tests/Abstractions/ResultTests.cs Adds coverage for Result/Result factory methods, FromValue, and implicit conversions.
tests/Domain.Tests/Behaviors/ValidationBehaviorTests.cs Adds coverage for ValidationBehavior no-validator path, passing/failing validators, and next-delegation behavior.
tests/Domain.Tests/Domain.Tests.csproj Adds test dependencies (FluentValidation/MediatR/NSubstitute) but introduces inconsistent XML indentation/formatting.
src/Web/Features/UserManagement/UserManagementHandler.cs Renames cancellation token parameter/usage (ctcancellationToken).
src/Web/Features/BlogPosts/List/GetBlogPostsHandler.cs Renames cancellation token parameter/usage (ctcancellationToken).
src/Web/Features/BlogPosts/Edit/EditBlogPostHandler.cs Renames cancellation token parameter/usage (ctcancellationToken).
src/Web/Features/BlogPosts/Delete/DeleteBlogPostHandler.cs Renames cancellation token parameter/usage (ctcancellationToken).
src/Web/Features/BlogPosts/Create/CreateBlogPostHandler.cs Renames cancellation token parameter/usage (ctcancellationToken).

Comment thread tests/Domain.Tests/Domain.Tests.csproj Outdated
Comment on lines +3 to +10
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>MyBlog.Domain.Tests</RootNamespace>
</PropertyGroup>

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

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

tests/Domain.Tests/Domain.Tests.csproj lost the standard indentation used by other test projects (tabs/indented XML), which also conflicts with the repo’s .editorconfig setting for *.csproj. Please reformat this file to match the existing csproj style (indented elements) to avoid noisy diffs and potential formatter/editor issues.

Copilot uses AI. Check for mistakes.
Comment on lines +101 to +109
public void FromValue_NullValue_ReturnsFailureResultWithNullMessage()
{
// Arrange / Act
var result = Result.FromValue<string>(null);

// Assert
result.Failure.Should().BeTrue();
result.Error.Should().Be("Provided value is null.");
}

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

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

Test name says it returns a failure result with a null message, but the assertion expects the specific error string "Provided value is null.". Rename the test to reflect the expected behavior (or adjust the assertion if the message is meant to be null).

Copilot uses AI. Check for mistakes.
@github-actions

github-actions Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Test Results Summary

206 tests  ±0   206 ✅ ±0   15s ⏱️ -1s
  5 suites ±0     0 💤 ±0 
  5 files   ±0     0 ❌ ±0 

Results for commit 0292c7e. ± Comparison against base commit 475185e.

♻️ This comment has been updated with latest results.

@codecov

codecov Bot commented Apr 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.16667% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.93%. Comparing base (475185e) to head (0292c7e).
⚠️ Report is 13 commits behind head on sprint/6-code-quality.

Files with missing lines Patch % Lines
...b/Features/UserManagement/UserManagementHandler.cs 0.00% 11 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                   @@
##           sprint/6-code-quality     #145   +/-   ##
======================================================
  Coverage                  76.93%   76.93%           
======================================================
  Files                         43       43           
  Lines                        672      672           
  Branches                     111      111           
======================================================
  Hits                         517      517           
  Misses                       105      105           
  Partials                      50       50           
Files with missing lines Coverage Δ
...Features/BlogPosts/Create/CreateBlogPostHandler.cs 100.00% <100.00%> (ø)
...Features/BlogPosts/Delete/DeleteBlogPostHandler.cs 100.00% <100.00%> (ø)
...Web/Features/BlogPosts/Edit/EditBlogPostHandler.cs 86.20% <100.00%> (ø)
...Web/Features/BlogPosts/List/GetBlogPostsHandler.cs 100.00% <100.00%> (ø)
...b/Features/UserManagement/UserManagementHandler.cs 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Fix Domain.Tests.csproj XML indentation to use tabs (match project style)
- Rename test FromValue_NullValue_ReturnsFailureResultWithNullMessage to
  FromValue_NullValue_ReturnsFailureResultWithProvidedValueIsNullError to
  accurately reflect the asserted error string

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mpaulosky
mpaulosky merged commit 9d9cf81 into sprint/6-code-quality Apr 24, 2026
14 checks passed
@mpaulosky
mpaulosky deleted the squad/141-domain-tests branch April 24, 2026 19:30
mpaulosky added a commit that referenced this pull request Apr 25, 2026
## Sprint 6: Code Quality

**Goal:** Eliminate analyzer warnings, enforce internal visibility on
Web feature types, expand test coverage, and migrate Unit.Tests into
Web.Tests.

---

## Merged Feature PRs

- Closes #137 — PR #144 — fix(quality): rename `ct` →
`cancellationToken` in all MediatR handlers
- Closes #138 — PR #145 — test: add unit tests for BlogPost, Result, and
ValidationBehavior (42 tests)
- Closes #139 — PR #146 — test: add unit tests for UserManagementHandler
(16 tests)
- Closes #140 — PR #147 — fix(quality): make Web feature types
`internal` (CA1515, ~28 types)
- Closes #141 — PR #148 — test: add unit tests for BlogPostMappings (22
tests)
- Closes #142 — PR #149 — fix(quality): add ConfigureAwait(false) and
specific exception catches
- Closes #143 — PR #150 — fix(quality): address Domain and
ServiceDefaults analyzer warnings
- Closes #151 — PR #152 — feat(tests): migrate Unit.Tests → Web.Tests
and remove Unit.Tests project

---

## Test Summary

- **80+ new tests** added across all PRs
- **105 Web.Tests passing** (0 failures)
- `DynamicProxyGenAssembly2` added to `InternalsVisibleTo` in Web.csproj
for NSubstitute support

## Notable Changes

- `Unit.Tests` project removed; all tests now live in `Web.Tests`
- ~28 Web feature types changed from `public` to `internal` (CA1515
compliance)
- All MediatR handler parameters renamed from `ct` to
`cancellationToken` for clarity
- `ConfigureAwait(false)` applied to all async calls in service layer
- Domain and ServiceDefaults analyzer warnings resolved

---

## Checklist

- [x] All sprint issues closed (#137#143, #151)
- [x] CI green (0 build errors)
- [x] 105 Web.Tests passing
- [x] Milestone at 100%

---------

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

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