test(repositories): add integration tests for Repository<T> and PlayerRepository (#461)#463
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 6 minutes and 1 seconds. ⌛ 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. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughA new integration test file is added to validate Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Assessment against linked issues
Possibly related PRs
🚥 Pre-merge checks | ❌ 2❌ Failed checks (2 warnings)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
03a95aa to
4434009
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/Dotnet.Samples.AspNetCore.WebApi.Tests/Integration/PlayerRepositoryTests.cs (1)
121-129: Reduce magic numbers in squad-number tests.Using fixed literals (
23,999) makes these tests more brittle to seed-data evolution. PreferPlayerFakesfor known existing values and derive an unknown value from current seeded data.As per coding guidelines: Always prefer `PlayerFakes` factory methods (`MakeNew()`, `MakeRequestModelForCreate()`, `MakeRequestModelForUpdate(n)`, `MakeFromStarting11(n)`) over constructing test data inline.♻️ Suggested refactor
public async Task FindBySquadNumberAsync_ExistingSquadNumber_ReturnsPlayer() { + var existingSquadNumber = PlayerFakes.MakeFromStarting11(1).SquadNumber; + // Act - var player = await _repository.FindBySquadNumberAsync(23); + var player = await _repository.FindBySquadNumberAsync(existingSquadNumber); // Assert player.Should().NotBeNull(); - player!.SquadNumber.Should().Be(23); + player!.SquadNumber.Should().Be(existingSquadNumber); } public async Task FindBySquadNumberAsync_UnknownSquadNumber_ReturnsNull() { + var unknownSquadNumber = (await _repository.GetAllAsync()).Max(p => p.SquadNumber) + 1; + // Act - var player = await _repository.FindBySquadNumberAsync(999); + var player = await _repository.FindBySquadNumberAsync(unknownSquadNumber); // Assert player.Should().BeNull(); } public async Task SquadNumberExistsAsync_ExistingSquadNumber_ReturnsTrue() { + var existingSquadNumber = PlayerFakes.MakeFromStarting11(1).SquadNumber; + // Act - var exists = await _repository.SquadNumberExistsAsync(23); + var exists = await _repository.SquadNumberExistsAsync(existingSquadNumber); // Assert exists.Should().BeTrue(); } public async Task SquadNumberExistsAsync_UnknownSquadNumber_ReturnsFalse() { + var unknownSquadNumber = (await _repository.GetAllAsync()).Max(p => p.SquadNumber) + 1; + // Act - var exists = await _repository.SquadNumberExistsAsync(999); + var exists = await _repository.SquadNumberExistsAsync(unknownSquadNumber); // Assert exists.Should().BeFalse(); }Also applies to: 133-140, 148-155, 159-166
🤖 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/Integration/PlayerRepositoryTests.cs`:
- Around line 106-113: The test RemoveAsync_UnknownId_NoExceptionThrown only
checks for no exception; update it to also verify the repository state is
unchanged: read the items (or count) from _repository before calling
RemoveAsync(Guid.NewGuid()), call the method, then assert the post-call
items/count equals the pre-call value; also, if RemoveAsync returns a
boolean/indication, assert it returns false (no-op). Locate this logic in the
PlayerRepositoryTests test method RemoveAsync_UnknownId_NoExceptionThrown and
use the repository's existing List/Count/Find methods to perform the
before/after comparison.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f5df0c04-ad0d-4bca-abc6-00591b207fe9
📒 Files selected for processing (2)
CHANGELOG.mdtest/Dotnet.Samples.AspNetCore.WebApi.Tests/Integration/PlayerRepositoryTests.cs
Repository<T> and PlayerRepository (#461)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
…461) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
39ad9e2 to
e463018
Compare
|



Summary
test/.../Integration/PlayerRepositoryTests.cswith 9 integration tests covering the non-trivial behaviors ofRepository<T>andPlayerRepositoryDatabaseFakes.MigrateAsync(), validating the full EF Core migration chain as a side effect[Trait("Category", "Integration")]to distinguish from unit testsRemoveAsync(entity found / not found) andSquadNumberExistsAsync(exists / does not exist) are exercisedTest coverage
GetAllAsyncAsNoTracking()via empty ChangeTrackerFindByIdAsyncnullRemoveAsyncFindBySquadNumberAsyncnullSquadNumberExistsAsynctrue; unknown returnsfalseTest plan
dotnet build --configuration Releasepasses with 0 warningsdotnet test --settings .runsettingspasses — 50/50 tests (9 new)dotnet csharpier --check .passesCloses #461
🤖 Generated with Claude Code
Summary by CodeRabbit