Skip to content

test: add unit tests for BlogPostMappings#148

Merged
mpaulosky merged 2 commits into
sprint/6-code-qualityfrom
squad/143-blogpostmappings-tests
Apr 24, 2026
Merged

test: add unit tests for BlogPostMappings#148
mpaulosky merged 2 commits into
sprint/6-code-qualityfrom
squad/143-blogpostmappings-tests

Conversation

@mpaulosky

Copy link
Copy Markdown
Owner

Closes #143

Working as Gimli, the Tester (QA Engineer)

Changes

Adds 6 unit tests in tests/Unit.Tests/Data/BlogPostMappingsTests.cs:

Test Scenario
ToDto_MapsAllFields_Correctly Id, Title, Content, Author, CreatedAt all map to matching DTO fields
ToDto_UpdatedAt_IsNullOnNewPost UpdatedAt is null immediately after BlogPost.Create
ToDto_UpdatedAt_IsSetAfterUpdate UpdatedAt is non-null after calling post.Update(...)
ToDto_IsPublished_FalseOnNewPost IsPublished is false by default
ToDto_IsPublished_TrueAfterPublish IsPublished is true after post.Publish()
ToDto_IsPublished_FalseAfterUnpublish IsPublished is false after post.Publish() then post.Unpublish()

BlogPostMappings.ToDto() is internal — access granted via [assembly: InternalsVisibleTo("Unit.Tests")] in AssemblyInfo.cs.

Verification

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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 24, 2026 18:51
@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 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 BlogPostBlogPostDto field mapping, including UpdatedAt and IsPublished state 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();
}
}
@github-actions

github-actions Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Test Results Summary

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

Results for commit 95a42ab. ± 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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.93%. Comparing base (475185e) to head (95a42ab).
⚠️ Report is 13 commits behind head on sprint/6-code-quality.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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>
@mpaulosky
mpaulosky merged commit ca932cb into sprint/6-code-quality Apr 24, 2026
14 checks passed
@mpaulosky
mpaulosky deleted the squad/143-blogpostmappings-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