Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/rules/testing-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task Handle_ValidCommand_ReturnsId()

- **xUnit** - Test framework
- **FluentAssertions** - `.Should()` assertions
- **Moq** - `Mock<T>` for dependencies
- **NSubstitute** - `Substitute.For<T>()` for dependencies

## Architecture Tests

Expand Down
24 changes: 12 additions & 12 deletions .claude/skills/testing-guide/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ public class ArchitectureTests
```csharp
public class Create{Entity}HandlerTests
{
private readonly Mock<IRepository<{Entity}>> _repositoryMock;
private readonly Mock<ICurrentUser> _currentUserMock;
private readonly IRepository<{Entity}> _repositoryMock;
private readonly ICurrentUser _currentUserMock;
private readonly Create{Entity}Handler _handler;

public Create{Entity}HandlerTests()
{
_repositoryMock = new Mock<IRepository<{Entity}>>();
_currentUserMock = new Mock<ICurrentUser>();
_currentUserMock.Setup(x => x.TenantId).Returns("test-tenant");
_repositoryMock = Substitute.For<IRepository<{Entity}>>();
_currentUserMock = Substitute.For<ICurrentUser>();
_currentUserMock.TenantId.Returns("test-tenant");

_handler = new Create{Entity}Handler(
_repositoryMock.Object,
_currentUserMock.Object);
_repositoryMock,
_currentUserMock);
}

[Fact]
Expand All @@ -92,17 +92,17 @@ public class Create{Entity}HandlerTests
// Arrange
var command = new Create{Entity}Command("Test", 99.99m);
_repositoryMock
.Setup(x => x.AddAsync(It.IsAny<{Entity}>(), It.IsAny<CancellationToken>()))
.AddAsync(Arg.Any<{Entity}>(), Arg.Any<CancellationToken>())
.Returns(Task.CompletedTask);

// Act
var result = await _handler.Handle(command, CancellationToken.None);

// Assert
result.Id.Should().NotBeEmpty();
_repositoryMock.Verify(x => x.AddAsync(
It.Is<{Entity}>(e => e.Name == "Test" && e.Price == 99.99m),
It.IsAny<CancellationToken>()), Times.Once);
await _repositoryMock.Received(1).AddAsync(
Arg.Is<{Entity}>(e => e.Name == "Test" && e.Price == 99.99m),
Arg.Any<CancellationToken>());
}
}
```
Expand Down Expand Up @@ -220,4 +220,4 @@ dotnet test --filter "FullyQualifiedName~Create{Entity}HandlerTests"
3. **Handlers need tests** - Mock dependencies
4. **Entities need tests** - Test factory methods and domain logic
5. **Use FluentAssertions** - `.Should()` syntax
6. **Use Moq for mocking** - `Mock<T>` pattern
6. **Use NSubstitute for mocking** - `Substitute.For<T>()` pattern