refactor(tests): rename test methods to Microsoft naming standard#399
refactor(tests): rename test methods to Microsoft naming standard#399nanotaboada merged 2 commits intomasterfrom
Conversation
- Apply {HttpMethod}_{Resource}_{Condition}_Returns{Outcome} to
PlayerControllerTests (PascalCase per .NET conventions)
- Apply {MethodName}_{StateUnderTest}_{ExpectedBehavior} to
PlayerServiceTests and PlayerValidatorTests
- Fix broken 201 assertion in Post_Players_NonExisting_Returns201Created
- Add UpdateAsync_PlayerNotFound and DeleteAsync_PlayerNotFound (service)
- Add DateOfBirthToday and DateOfBirthOnJanuary1st1900 boundary tests
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThe PR refactors test method naming across three unit test files to follow the Microsoft .NET standard, replacing verbose Given/When/Then patterns with concise {MethodName}{StateUnderTest}{ExpectedBehavior} conventions. Controller tests additionally use {METHOD}{Resource}{Condition}_Returns{Outcome}. New edge-case tests are added for UpdateAsync, DeleteAsync, and DateOfBirth boundary validation. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Assessment against linked issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 1 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📋 Issue PlannerBuilt with CodeRabbit's Coding Plans for faster development and fewer bugs. View plan used: ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerControllerTests.cs`:
- Around line 149-156: Replace the conditional if-check with an unconditional
type assertion: in PlayerControllerTests (the assertion block for PostAsync),
first assert result is of type CreatedAtRoute<PlayerResponseModel> (e.g.
result.Should().BeOfType<CreatedAtRoute<PlayerResponseModel>>() or
Assert.IsType<CreatedAtRoute<PlayerResponseModel>>(result)), then cast to
CreatedAtRoute<PlayerResponseModel> and assert StatusCode == 201, Value is
equivalent to the expected response, RouteName == "RetrieveBySquadNumber", and
that RouteValues contains the exact "squadNumber" entry with the expected value
(not just the key).
In `@test/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerValidatorTests.cs`:
- Around line 213-225: The test
ValidateAsync_DateOfBirthToday_ReturnsValidationError is flaky because it reads
DateTime.UtcNow.Date while PlayerRequestModelValidator also uses
DateTime.UtcNow.Date; refactor PlayerRequestModelValidator to accept an injected
time source (e.g., TimeProvider or an IClock) and use that instead of
DateTime.UtcNow, update CreateValidator() to accept and pass a deterministic
TimeProvider to the validator, and change the test to construct a fixed
TimeProvider (or mock IClock) and set request.DateOfBirth relative to that fixed
time so both the test and PlayerRequestModelValidator use the same stable clock.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1d819aaa-5792-4ac0-a740-fe2ce9407e8c
📒 Files selected for processing (5)
.github/copilot-instructions.mdCHANGELOG.mdtest/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerControllerTests.cstest/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerServiceTests.cstest/Dotnet.Samples.AspNetCore.WebApi.Tests/Unit/PlayerValidatorTests.cs
- Replace if-guarded 201 assertion with unconditional BeOfType and add RouteValues squadNumber value check (PlayerControllerTests) - Inject TimeProvider into PlayerRequestModelValidator to eliminate DateTime.UtcNow coupling - Add FakeTimeProvider in PlayerValidatorTests and pin DateOfBirthToday to a fixed clock shared with the validator Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|



Closes #396
Summary by CodeRabbit
Tests
Bug Fixes