Skip to content

feat(validation): add DateOfBirth rules and fix Birth null mapping#397

Merged
nanotaboada merged 5 commits intomasterfrom
feat/player-validation-and-response-formatting
Mar 7, 2026
Merged

feat(validation): add DateOfBirth rules and fix Birth null mapping#397
nanotaboada merged 5 commits intomasterfrom
feat/player-validation-and-response-formatting

Conversation

@nanotaboada
Copy link
Copy Markdown
Owner

@nanotaboada nanotaboada commented Mar 7, 2026

Closes #344

Summary by CodeRabbit

  • New Features

    • Validation: player birth dates must be in the past and on/after Jan 1, 1900.
  • Bug Fixes

    • Fixed handling of null birth dates to avoid formatting errors.
  • Tests

    • Added comprehensive unit tests for player validation, uniqueness checks, and date constraints.
  • Chores

    • Ignore test results in VCS and added VS Code tooling configuration; improved test utilities for response formatting.

nanotaboada and others added 2 commits March 7, 2026 16:01
)

- Add optional DateOfBirth range validation (past, >= 1900-01-01) in
  PlayerRequestModelValidator using FluentValidation When(HasValue)
- Fix PlayerMappingProfile to return null instead of "" for Birth
  when DateOfBirth is not provided
- Add PlayerValidatorTests covering all validator rule branches
- Update PlayerFakes Birth computation to match null-safe mapping
- Add TestResults/ to .gitignore (exposed by running coverage suite)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e1490130-8eba-4f67-8311-3e981eab115b

📥 Commits

Reviewing files that changed from the base of the PR and between 2264c0d and 026d34a.

📒 Files selected for processing (1)
  • src/Dotnet.Samples.AspNetCore.WebApi/Validators/PlayerRequestModelValidator.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Dotnet.Samples.AspNetCore.WebApi/Validators/PlayerRequestModelValidator.cs

Walkthrough

Adds conditional DateOfBirth validation (must be past and ≥1900 when provided), makes Player→PlayerResponseModel Birth mapping null-safe (returns null when no date), adds unit tests for validator and updates test fakes, plus a VS Code MCP config and .gitignore entry for TestResults/.

Changes

Cohort / File(s) Summary
Configuration
/.gitignore, /.vscode/mcp.json
Adds TestResults/ to gitignore and adds a VS Code MCP configuration (.vscode/mcp.json) to run the GitHub MCP server via Docker with a github_token prompt.
Validation
src/.../Validators/PlayerRequestModelValidator.cs
Adds a conditional rule: when DateOfBirth has value, it must be in the past and on/after 1900-01-01 UTC; existing validation rules remain.
Mapping
src/.../Mappings/PlayerMappingProfile.cs
Changes Birth mapping to return formatted date string when DateOfBirth present, otherwise null (avoids empty-string mapping).
Tests
test/.../Unit/PlayerValidatorTests.cs
Adds PlayerValidatorTests with ~10 tests covering validator rules including DateOfBirth scenarios and squad-number uniqueness using mocked repository.
Test Utilities
test/.../Utilities/PlayerFakes.cs
Adds FormatBirth(DateTime?) helper and updates fake response-model construction to use null-safe birth formatting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • #209 — Player Model Validation Consistency and Response Formatting — Implements the issue's objectives: DateOfBirth validation, null Birth mapping, and added validator tests.

Possibly related PRs

  • #194 — Modifies PlayerMappingProfile’s Birth mapping — directly related to the mapping change here.
  • #214 — Changes to PlayerRequestModelValidator.cs — related due to overlapping validator edits.
  • #206 — Updates PlayerFakes utilities — related to the test-helper formatting changes.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 75.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title follows Conventional Commits format (feat:), is under 80 characters (66), and accurately describes the main changes: adding DateOfBirth validation rules and fixing Birth null mapping.
Linked Issues check ✅ Passed All coding requirements from issue #344 are met: DateOfBirth validation (past & >=1900) is conditional and optional, Birth mapping returns null for null DateOfBirth, comprehensive unit tests cover all cases, PlayerFakes uses null-safe formatting, and existing tests remain unmodified.
Out of Scope Changes check ✅ Passed All code changes are within scope: DateOfBirth validation, Birth mapping, PlayerValidatorTests, PlayerFakes formatting updates, .gitignore and .vscode/mcp.json additions support development workflow without altering core objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/player-validation-and-response-formatting

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nanotaboada nanotaboada changed the title feat(validation): add DateOfBirth rules and fix Birth null mapping (#344) feat(validation): add DateOfBirth rules and fix Birth null mapping Mar 7, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerFakes.cs (1)

104-104: LGTM!

The Birth formatting logic correctly mirrors the production mapping in PlayerMappingProfile.cs, ensuring test data consistency.

Consider extracting a helper method to reduce duplication of the formatting logic across the three call sites:

private static string? FormatBirth(DateTime? dateOfBirth) =>
    dateOfBirth.HasValue ? $"{dateOfBirth.Value:MMMM d, yyyy}" : null;

Also applies to: 160-160, 184-186

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerFakes.cs` at line
104, Extract the duplicated birth-formatting logic into a private helper (e.g.,
FormatBirth) inside PlayerFakes so all three call sites use it instead of
repeating the ternary; replace instances like Birth =
player.DateOfBirth.HasValue ? $"{player.DateOfBirth.Value:MMMM d, yyyy}" : null
with Birth = FormatBirth(player.DateOfBirth) and implement FormatBirth(DateTime?
dateOfBirth) to return the same formatted string or null.
test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerValidatorTests.cs (1)

172-224: Comprehensive DateOfBirth test coverage.

The three test cases properly exercise all validation branches:

  • null → passes (field is optional)
  • Future date → fails
  • Before 1900 → fails

For consistency with the validator fix suggested earlier, consider using DateTimeKind.Utc on line 215:

request.DateOfBirth = new DateTime(1899, 12, 31, 0, 0, 0, DateTimeKind.Utc);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerValidatorTests.cs`
around lines 172 - 224, Update the test that sets request.DateOfBirth to
1899-12-31 to construct the DateTime with DateTimeKind.Utc so the validator sees
a UTC date; locate the test method
GivenValidateAsync_WhenDateOfBirthIsBeforeYear1900_ThenValidationShouldFail and
modify the assignment to request.DateOfBirth to use new DateTime(1899, 12, 31,
0, 0, 0, DateTimeKind.Utc) (ensuring consistency with other tests that use UTC
and the validator expectations).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.vscode/mcp.json:
- Around line 23-26: Update the "github_token" prompt entry's description to
instruct contributors to use fine-grained personal access tokens (not classic
PATs), enumerate the minimum repository permissions required (Contents: read or
read & write, Issues: read or read & write, Pull requests: read or read & write
— adjust to actual usage), and state that if a classic PAT is unavoidable the
minimum scope required is repo; locate the entry by the id "github_token" and
modify its "description" field accordingly to include these permission and
token-type guidance.

In
`@src/Dotnet.Samples.AspNetCore.WebApi/Validators/PlayerRequestModelValidator.cs`:
- Line 50: The validator's minimum date uses an unspecified DateTime which
mismatches the UTC comparison on line 48; update the `.Must(date => date >= new
DateTime(1900, 1, 1))` check to use a UTC-kind date (e.g., construct the
boundary with DateTimeKind.Utc or call DateTime.SpecifyKind) so the comparison
against DateTime.UtcNow is consistent; keep the predicate on the same lambda in
PlayerRequestModelValidator.

---

Nitpick comments:
In `@test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerValidatorTests.cs`:
- Around line 172-224: Update the test that sets request.DateOfBirth to
1899-12-31 to construct the DateTime with DateTimeKind.Utc so the validator sees
a UTC date; locate the test method
GivenValidateAsync_WhenDateOfBirthIsBeforeYear1900_ThenValidationShouldFail and
modify the assignment to request.DateOfBirth to use new DateTime(1899, 12, 31,
0, 0, 0, DateTimeKind.Utc) (ensuring consistency with other tests that use UTC
and the validator expectations).

In `@test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerFakes.cs`:
- Line 104: Extract the duplicated birth-formatting logic into a private helper
(e.g., FormatBirth) inside PlayerFakes so all three call sites use it instead of
repeating the ternary; replace instances like Birth =
player.DateOfBirth.HasValue ? $"{player.DateOfBirth.Value:MMMM d, yyyy}" : null
with Birth = FormatBirth(player.DateOfBirth) and implement FormatBirth(DateTime?
dateOfBirth) to return the same formatted string or null.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 46bb7163-2305-42e5-9b55-393675543841

📥 Commits

Reviewing files that changed from the base of the PR and between 3625020 and 45f86a7.

📒 Files selected for processing (6)
  • .gitignore
  • .vscode/mcp.json
  • src/Dotnet.Samples.AspNetCore.WebApi/Mappings/PlayerMappingProfile.cs
  • src/Dotnet.Samples.AspNetCore.WebApi/Validators/PlayerRequestModelValidator.cs
  • test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerValidatorTests.cs
  • test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerFakes.cs

Comment thread .vscode/mcp.json
Comment thread src/Dotnet.Samples.AspNetCore.WebApi/Validators/PlayerRequestModelValidator.cs Outdated
nanotaboada and others added 2 commits March 7, 2026 16:20
)

- Add DateOfBirth must-be-past and >= 1900-01-01 UTC validation rules
  to PlayerRequestModelValidator
- Extract FormatBirth helper in PlayerFakes to eliminate duplicated
  birth date formatting logic across test utilities
- Add PlayerValidatorTests covering valid and invalid DateOfBirth cases

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Add .vscode/mcp.json with docker-based GitHub MCP server entry
- Prompt for fine-grained PAT with repo and issues scopes

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerValidatorTests.cs (1)

172-224: Add boundary coverage for today and exactly 1900-01-01.

The new DOB tests cover null, future, and pre-1900 values, but they don’t lock down the two boundaries this PR introduces: rejecting today and accepting 1900-01-01. Adding those cases would protect the new validator rule from off-by-one regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerValidatorTests.cs`
around lines 172 - 224, Add two unit tests in PlayerValidatorTests: one that
sets request.DateOfBirth = DateTime.UtcNow.Date (or DateTime.UtcNow without time
part) and asserts validator.ValidateAsync(request) fails and contains an error
with PropertyName "DateOfBirth" to cover the "today" boundary, and another that
sets request.DateOfBirth = new DateTime(1900,1,1,0,0,0,DateTimeKind.Utc) and
asserts validation succeeds (IsValid true) to ensure 1900-01-01 is accepted; use
the existing CreateValidator(), PlayerFakes.MakeRequestModelForCreate(), and
validator.ValidateAsync(...) pattern so the new tests match the style of the
surrounding tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/Dotnet.Samples.AspNetCore.WebApi/Validators/PlayerRequestModelValidator.cs`:
- Around line 47-49: The DateOfBirth rule currently compares full DateTime
values (RuleFor(...).Must(date => date < DateTime.UtcNow)), which allows
same-day dates earlier than now; change the predicate to compare only the date
component (e.g., use date.Value.Date < DateTime.UtcNow.Date) so same-day birth
dates are rejected and ensure you handle the nullable DateOfBirth
(DateOfBirth.Value.Date) consistently in the Must lambda for the
PlayerRequestModelValidator.

---

Nitpick comments:
In `@test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerValidatorTests.cs`:
- Around line 172-224: Add two unit tests in PlayerValidatorTests: one that sets
request.DateOfBirth = DateTime.UtcNow.Date (or DateTime.UtcNow without time
part) and asserts validator.ValidateAsync(request) fails and contains an error
with PropertyName "DateOfBirth" to cover the "today" boundary, and another that
sets request.DateOfBirth = new DateTime(1900,1,1,0,0,0,DateTimeKind.Utc) and
asserts validation succeeds (IsValid true) to ensure 1900-01-01 is accepted; use
the existing CreateValidator(), PlayerFakes.MakeRequestModelForCreate(), and
validator.ValidateAsync(...) pattern so the new tests match the style of the
surrounding tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 02244ca5-19a6-4fac-afc5-1508e2c20edc

📥 Commits

Reviewing files that changed from the base of the PR and between 45f86a7 and 2264c0d.

📒 Files selected for processing (4)
  • .vscode/mcp.json
  • src/Dotnet.Samples.AspNetCore.WebApi/Validators/PlayerRequestModelValidator.cs
  • test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerValidatorTests.cs
  • test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerFakes.cs
🚧 Files skipped from review as they are similar to previous changes (2)
  • .vscode/mcp.json
  • test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerFakes.cs

#344)

- Change DateOfBirth predicate from `date < DateTime.UtcNow` to
  `date!.Value.Date < DateTime.UtcNow.Date` to reject same-day dates
- Access nullable value via `.Value.Date` consistently in both Must
  lambdas, safe within the When(HasValue) guard

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 7, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Player Model Validation Consistency and Response Formatting

1 participant