| name | tdd-dotnet |
| description | Write a new feature using Red-Green-Refactor TDD with xUnit and FluentAssertions for PlaylistMiner .NET backend. |
TDD Feature Implementation (.NET)
Implement the requested feature using strict Red-Green-Refactor TDD.
Step 1: Red — Write Failing Tests
- Create test class in
tests/PlaylistMiner.UnitTests/ matching the source file location
- Name tests:
Test_MethodName_Scenario_ExpectedResult
- Use FluentAssertions:
.Should().Be(), .Should().Contain(), .Should().Throw<>()
- Use Moq for dependencies:
var mock = new Mock<IService>()
- Follow Arrange-Act-Assert pattern
- Run
dotnet test — confirm tests FAIL
Step 2: Green — Minimal Implementation
- Write the minimum code to make tests pass
- No refactoring, no optimization, no extras
- Run
dotnet test — confirm tests PASS
Step 3: Refactor
- Clean up implementation while keeping tests green
- Extract interfaces, rename variables, reduce duplication
- Run
dotnet test — confirm tests still PASS
Rules
- NEVER write implementation before the test
- One test class per production class
- Use
[Category("Unit")] for unit tests, [Category("Integration")] for integration tests
- Integration tests use Testcontainers (real PostgreSQL)
- All async methods accept
CancellationToken
- Return DTOs from Core, never EF entities