test: add unit tests for BlogPost, Result, and ValidationBehavior#145
Conversation
🏗️ PR Added to Squad Triage QueueThis PR has been labeled with Next steps:
|
There was a problem hiding this comment.
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.TestsforBlogPost,Result, andValidationBehavior. - Updated
tests/Domain.Testsproject configuration (package references + global usings). - Renamed
cttocancellationTokenin 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 (ct → cancellationToken). |
| src/Web/Features/BlogPosts/List/GetBlogPostsHandler.cs | Renames cancellation token parameter/usage (ct → cancellationToken). |
| src/Web/Features/BlogPosts/Edit/EditBlogPostHandler.cs | Renames cancellation token parameter/usage (ct → cancellationToken). |
| src/Web/Features/BlogPosts/Delete/DeleteBlogPostHandler.cs | Renames cancellation token parameter/usage (ct → cancellationToken). |
| src/Web/Features/BlogPosts/Create/CreateBlogPostHandler.cs | Renames cancellation token parameter/usage (ct → cancellationToken). |
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsPackable>false</IsPackable> | ||
| <IsTestProject>true</IsTestProject> | ||
| <RootNamespace>MyBlog.Domain.Tests</RootNamespace> | ||
| </PropertyGroup> |
There was a problem hiding this comment.
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.
| 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."); | ||
| } |
There was a problem hiding this comment.
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).
Codecov Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
- 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>
## 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>
Closes #141
Working as Gimli, the Tester (QA Engineer)
Changes
Adds 42 unit tests across three new test files in
tests/Domain.Tests/:Entities/BlogPostTests.csBlogPost.Create,Update,Publish,Unpublish, guard clausesAbstractions/ResultTests.csResult.Ok,Result.Fail,Result.Ok<T>,Result.Fail<T>,Result.FromValue<T>, implicit conversionsBehaviors/ValidationBehaviorTests.csnextdelegationAlso adds
NSubstitute,FluentValidation, andMediatRpackage references toDomain.Tests.csprojand the corresponding global usings.Verification