Skip to content

Commit 8bb8774

Browse files
nanotaboadaclaude
andcommitted
test(validators): fix naming and add missing coverage (#427)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b781936 commit 8bb8774

3 files changed

Lines changed: 51 additions & 2 deletions

File tree

.claude/commands/pre-commit.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Run the pre-commit checklist for this project:
55
1. Update `CHANGELOG.md` `[Unreleased]` section — add an entry under the appropriate subsection (Added / Changed / Fixed / Removed) describing the changes made, referencing the issue number.
66
2. Run `dotnet build --configuration Release` — must succeed.
77
3. Run `dotnet test --settings .runsettings` — all tests must pass.
8-
4. Run `dotnet csharpier --check .` — must pass (run `dotnet csharpier .` to auto-fix).
8+
4. If `dotnet csharpier` is available, run `dotnet csharpier --check .` — must pass
9+
(run `dotnet csharpier .` to auto-fix). Skip this step with a note if not installed.
910
5. If `coderabbit` CLI is installed, run `coderabbit review --type uncommitted --prompt-only`:
1011
- If actionable/serious findings are reported, stop and address them before proposing the commit.
1112
- If only nitpick-level findings, report them and continue to the commit proposal.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ This project uses famous football stadiums (A-Z) that hosted FIFA World Cup matc
4444

4545
### Added
4646

47+
- Add `ValidateAsync_SquadNumberNegative_ReturnsValidationError` test to exercise the `GreaterThan(0)` rule with a negative value, which passes `NotEmpty()` but fails the greater-than rule (#427)
48+
- Add `ValidateAsync_FirstNameEmptyInUpdateRuleSet_ReturnsValidationError` test to verify the `"Update"` rule set enforces structural field validation (#427)
4749
- Add `adr/` directory with 12 Architecture Decision Records documenting architectural choices, technology decisions, and design trade-offs (#372)
4850
- Add ADR index and template at `adr/README.md` (#372)
4951
- Add Architecture Decisions section to `README.md` referencing the ADR index (#372)
@@ -52,6 +54,8 @@ This project uses famous football stadiums (A-Z) that hosted FIFA World Cup matc
5254

5355
### Changed
5456

57+
- Rename `ValidateAsync_SquadNumber_BelongsToPlayerBeingUpdated_ReturnsNoErrors` to `ValidateAsync_SquadNumberBelongsToPlayerBeingUpdated_ReturnsNoErrors` to align with the 3-segment naming convention for service/validator tests (#427)
58+
- Make CSharpier step in `/pre-commit` conditional (skip with a note if not installed), consistent with the Docker and CodeRabbit steps (#427)
5559
- Add "Verify tag commit is reachable from master" step to CD workflow using `git merge-base --is-ancestor` before any build or publish steps (#439)
5660

5761
### Fixed

test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerValidatorTests.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,30 @@ public async Task ValidateAsync_SquadNumberNotGreaterThanZero_ReturnsValidationE
123123
result.Errors.Should().Contain(error => error.PropertyName == "SquadNumber");
124124
}
125125

126+
[Fact]
127+
[Trait("Category", "Unit")]
128+
public async Task ValidateAsync_SquadNumberNegative_ReturnsValidationError()
129+
{
130+
// Arrange
131+
var request = PlayerFakes.MakeRequestModelForCreate();
132+
request.SquadNumber = -5;
133+
var validator = CreateValidator();
134+
135+
// Act
136+
var result = await validator.ValidateAsync(
137+
request,
138+
options => options.IncludeRuleSets("Create")
139+
);
140+
141+
// Assert
142+
result.IsValid.Should().BeFalse();
143+
result
144+
.Errors.Should()
145+
.Contain(error =>
146+
error.PropertyName == "SquadNumber" && error.ErrorMessage.Contains("greater than 0")
147+
);
148+
}
149+
126150
[Fact]
127151
[Trait("Category", "Unit")]
128152
public async Task ValidateAsync_SquadNumberNotUnique_ReturnsValidationError()
@@ -153,7 +177,7 @@ public async Task ValidateAsync_SquadNumberNotUnique_ReturnsValidationError()
153177

154178
[Fact]
155179
[Trait("Category", "Unit")]
156-
public async Task ValidateAsync_SquadNumber_BelongsToPlayerBeingUpdated_ReturnsNoErrors()
180+
public async Task ValidateAsync_SquadNumberBelongsToPlayerBeingUpdated_ReturnsNoErrors()
157181
{
158182
// Arrange
159183
// Simulate a PUT request for an existing player: the squad number in the
@@ -178,6 +202,26 @@ public async Task ValidateAsync_SquadNumber_BelongsToPlayerBeingUpdated_ReturnsN
178202
result.Errors.Should().BeEmpty();
179203
}
180204

205+
[Fact]
206+
[Trait("Category", "Unit")]
207+
public async Task ValidateAsync_FirstNameEmptyInUpdateRuleSet_ReturnsValidationError()
208+
{
209+
// Arrange
210+
var request = PlayerFakes.MakeRequestModelForUpdate(10);
211+
request.FirstName = string.Empty;
212+
var validator = CreateValidator();
213+
214+
// Act
215+
var result = await validator.ValidateAsync(
216+
request,
217+
options => options.IncludeRuleSets("Update")
218+
);
219+
220+
// Assert
221+
result.IsValid.Should().BeFalse();
222+
result.Errors.Should().Contain(error => error.PropertyName == "FirstName");
223+
}
224+
181225
/* -------------------------------------------------------------------------
182226
* AbbrPosition
183227
* ---------------------------------------------------------------------- */

0 commit comments

Comments
 (0)