Skip to content
bitzorcas
EN

Reference

Unit tests

Unit testing patterns — domain logic tests, value objects, Result\<T\> validation, IRequestRule testing, and the Vertical Slice unit test approach.

Last updated

BitzOrcas.Unit.Tests covers domain logic, value objects, and application-level validation rules — all tests that run without infrastructure dependencies.

Test scope

AreaExample
Value objectsEmailAddress validation, NoteTitle constraints
Result<T>Success/failure creation, error matching
Domain eventsEvent construction and properties
IRequestRuleCreateGreetingCommandRule validation
AggregatesNote creation, state transitions
ClockFixedClock deterministic time tests

Example: Result<T> test

[Fact]
public void CreateNote_WithEmptyTitle_ShouldReturnValidationError()
{
// Arrange
var service = new NoteService();
// Act
var result = service.CreateNote("", "content");
// Assert
result.IsFailure.ShouldBeTrue();
result.Error.Type.ShouldBe(ErrorType.Validation);
result.Error.Code.ShouldBe("Note.Title");
}

Example: IRequestRule test

[Fact]
public void CreateGreetingCommandRule_ValidName_ShouldPass()
{
var rule = new CreateGreetingCommandRule();
var cmd = new CreateGreetingCommand("Hello");
var errors = rule.Validate(cmd);
errors.ShouldBeEmpty();
}

Running

Terminal window
dotnet test tests/BitzOrcas.Unit.Tests