test: add unit tests for BlogPostMappings#148
Merged
mpaulosky merged 2 commits intoApr 24, 2026
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
🏗️ 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 the BlogPostMappings.ToDto() mapping used by the Web layer to convert BlogPost domain entities into BlogPostDto objects, improving confidence in DTO/data flow correctness.
Changes:
- Added unit tests validating
BlogPost→BlogPostDtofield mapping, includingUpdatedAtandIsPublishedstate transitions. - Enabled test access to internal mapping via
InternalsVisibleTo("Unit.Tests")(per PR description).
Reviewed changes
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/Unit.Tests/Data/BlogPostMappingsTests.cs | Adds mapping-focused unit tests for ToDto() covering mapped fields and state-dependent properties. |
| src/Web/Properties/AssemblyInfo.cs | Grants Unit.Tests access to internal BlogPostMappings to allow direct testing (per PR description). |
Comment on lines
+14
to
+100
| [Fact] | ||
| public void ToDto_MapsAllFields_Correctly() | ||
| { | ||
| // Arrange | ||
| var post = BlogPost.Create("Test Title", "Test Content", "Test Author"); | ||
|
|
||
| // Act | ||
| var dto = post.ToDto(); | ||
|
|
||
| // Assert | ||
| dto.Id.Should().Be(post.Id); | ||
| dto.Title.Should().Be(post.Title); | ||
| dto.Content.Should().Be(post.Content); | ||
| dto.Author.Should().Be(post.Author); | ||
| dto.CreatedAt.Should().Be(post.CreatedAt); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToDto_UpdatedAt_IsNullOnNewPost() | ||
| { | ||
| // Arrange | ||
| var post = BlogPost.Create("Title", "Content", "Author"); | ||
|
|
||
| // Act | ||
| var dto = post.ToDto(); | ||
|
|
||
| // Assert | ||
| dto.UpdatedAt.Should().BeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToDto_UpdatedAt_IsSetAfterUpdate() | ||
| { | ||
| // Arrange | ||
| var post = BlogPost.Create("Title", "Content", "Author"); | ||
| post.Update("New Title", "New Content"); | ||
|
|
||
| // Act | ||
| var dto = post.ToDto(); | ||
|
|
||
| // Assert | ||
| dto.UpdatedAt.Should().NotBeNull(); | ||
| dto.UpdatedAt.Should().Be(post.UpdatedAt); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToDto_IsPublished_FalseOnNewPost() | ||
| { | ||
| // Arrange | ||
| var post = BlogPost.Create("Title", "Content", "Author"); | ||
|
|
||
| // Act | ||
| var dto = post.ToDto(); | ||
|
|
||
| // Assert | ||
| dto.IsPublished.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToDto_IsPublished_TrueAfterPublish() | ||
| { | ||
| // Arrange | ||
| var post = BlogPost.Create("Title", "Content", "Author"); | ||
| post.Publish(); | ||
|
|
||
| // Act | ||
| var dto = post.ToDto(); | ||
|
|
||
| // Assert | ||
| dto.IsPublished.Should().BeTrue(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToDto_IsPublished_FalseAfterUnpublish() | ||
| { | ||
| // Arrange | ||
| var post = BlogPost.Create("Title", "Content", "Author"); | ||
| post.Publish(); | ||
| post.Unpublish(); | ||
|
|
||
| // Act | ||
| var dto = post.ToDto(); | ||
|
|
||
| // Assert | ||
| dto.IsPublished.Should().BeFalse(); | ||
| } | ||
| } |
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## sprint/6-code-quality #148 +/- ##
======================================================
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 indentation in BlogPostMappingsTests.cs to use tabs (size 2) consistent with the rest of Unit.Tests (e.g., CreateBlogPostHandlerTests.cs). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4 tasks
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #143
Working as Gimli, the Tester (QA Engineer)
Changes
Adds 6 unit tests in
tests/Unit.Tests/Data/BlogPostMappingsTests.cs:ToDto_MapsAllFields_CorrectlyToDto_UpdatedAt_IsNullOnNewPostUpdatedAtis null immediately afterBlogPost.CreateToDto_UpdatedAt_IsSetAfterUpdateUpdatedAtis non-null after callingpost.Update(...)ToDto_IsPublished_FalseOnNewPostIsPublishedis false by defaultToDto_IsPublished_TrueAfterPublishIsPublishedis true afterpost.Publish()ToDto_IsPublished_FalseAfterUnpublishIsPublishedis false afterpost.Publish()thenpost.Unpublish()BlogPostMappings.ToDto()is internal — access granted via[assembly: InternalsVisibleTo("Unit.Tests")]inAssemblyInfo.cs.Verification