Examples

Code reviews

Repository, pull request, review and lock - the library's reference domain.

A lock test needs a valid chain of related rows before it can check the lock itself. This example shows how to keep that repeated branch in a helper while leaving numbering and time predictable.

Mirrors a real code-review app: the seed is an organization and an owner, and the graph is CodeRepository → PullRequestRecord → CodeReviewRecord → ActiveCodeReviewLock. Source: tests/Zeeq.Biome.Tests/CodeReviews.

Every scenario exists twice in one CodeReviewTests partial class: CodeReviewTests.WithBiome.cs uses Biome, and CodeReviewTests.Typical.cs sets up the same entities by hand with identical assertions. Read them side by side to see what Biome removes.

The blueprints

CodeReviews/Domain.cs
// Give each repository its own counter across Adds and variants.
internal static readonly Sequence<int> Numbers = Sequence
    .Of(1, n => n + 1)
    .Per<CodeRepository>();

internal static readonly Blueprint<CodeReviewSeed, CodeRepository> Repository = Blueprint.For<
    CodeReviewSeed,
    CodeRepository
>(ctx =>
    new()
    {
        Id = ctx.NewId("repo"),
        Organization = ctx.Seed.Organization,
        CreatedAt = ctx.Now,
    }
);

internal static readonly ChildBlueprint<
    CodeReviewSeed,
    CodeRepository,
    PullRequestRecord
> PullRequest = Blueprint
    .ChildOf<CodeReviewSeed, CodeRepository, PullRequestRecord>(
        (repo, ctx) => new() { Id = ctx.NewId("pr"), Repository = repo }
    )
    // Assign the number first so the title and branch use its final value.
    .Derive(pr => pr.Number, Numbers)
    .Derive(pr => pr.Title, (pr, _) => $"PR {pr.Number}")
    .Derive(pr => pr.Branch, (pr, _) => $"feature/{pr.Number}");

internal static readonly ChildBlueprint<
    CodeReviewSeed,
    PullRequestRecord,
    CodeReviewRecord
> Review = Blueprint.ChildOf<CodeReviewSeed, PullRequestRecord, CodeReviewRecord>(
    (pr, ctx) =>
        new()
        {
            Id = ctx.NewId("review"),
            // Use the repository that owns this pull request.
            PullRequest = pr,
            Repository = ctx.Ancestor<CodeRepository>(),
            CreatedAt = ctx.Now,
        }
);

A locked review in one line

The scenario helper builds the four-level default chain. The test checks that the lock and pull request share a repository and that the store receives all six rows.

var store = new RecordingStore();
var biome = TestBiome.Start(out var seed, store);

// Use the helper to build the entire branch with its default relationships.
await biome.AddLockedReview(out var activeLock).BuildAsync();

// The lock and pull request share a repository. The row count includes the seed.
await Assert
    .That(activeLock.Repository)
    .IsSameReferenceAs(activeLock.Review.PullRequest.Repository);
await Assert.That(store.Entities.Count).IsEqualTo(6);
The setup shrinks from 26 lines to 3, but the more useful change is where the relationships are defined. The lock, review, and pull request need the same repository instance. Keeping that wiring in blueprints avoids repeating it in each test.

Numbers resume across calls and variants

The same Numbers sequence is shared by the closed variant, and .Under(repos) fans out across both repositories.

CodeReviewTests.WithBiome.cs
var biome = TestBiome.Start(out _);

// Add the closed trait while keeping the original numbering rules.
var closed = Blueprints.PullRequest.With(PullRequests.Closed);

await biome
    .AddCodeRepositories(out var repos, 2)
    .AddPullRequests(out var first, 2)
    // Resume both counters so each repository gets closed PRs 3 and 4.
    .Under(repos)
    .Add(closed, out var second, count: 2)
    .Under(repos[0])
    .AddPullRequest(out var fifth)
    .BuildAsync();

// first:  1, 2, 1, 2    (numbering restarts per repository)
// fifth:  5, Title "PR 5", Branch "feature/5"

Explicit values are reserved first

Explicit numbers are skipped by the sequence, even when they come later in the same step:

CodeReviewTests.WithBiome.cs
await TestBiome
    .Start(out _)
    .AddCodeRepository(out var repo)
    .AddPullRequests(
        out var prs,
        // Reserve 1 and 3 before filling either default, even the first one.
        _ => { },
        pr => pr.Number = 1,
        pr => pr.Number = 3,
        _ => { }
    )
    .Under(repo)
    .AddPullRequest(out var next)
    .BuildAsync();
// prs: 2, 1, 3, 4   next: 5
Set explicit numbers in the same step as the defaults, or an earlier one. A later step can't retroactively fix numbers that are already assigned.

Commas, plus, and transients

CodeReviewTests.WithBiome.cs
await TestBiome
    .Start(out _)
    .AddCodeRepository(out _)
    .AddPullRequests(
        out var prs,
        // Create two closed PRs and apply Merged to the second one only.
        PullRequests.Closed,
        PullRequests.Closed + PullRequests.Merged
    )
    .BuildAsync();

Transient inputs stay inspectable but are not saved:

CodeReviewTests.WithBiome.cs
var store = new RecordingStore();
var biome = TestBiome.Start(out _, store);

biome.AddCodeRepository(out _).AddPullRequests(out var prs, 2);

// Mark the PR step transient even though this call uses the root builder.
await biome.Transient().BuildAsync();

// biome.All<PullRequestRecord>().Count == 2, but the store holds none

Time

A shared FakeTimeProvider is read live, and every source of now is rounded to 1 µs:

CodeReviewTests.WithBiome.cs
// Include seven ticks below microsecond precision to show where rounding occurs.
var instant = new DateTimeOffset(2026, 10, 11, 12, 0, 0, TimeSpan.Zero).AddTicks(17);
var time = new FakeTimeProvider(instant);
var biome = TestBiome.Start(out _, time: time);

biome.AddCodeRepository(out var first);

// The first repository keeps its timestamp when the clock advances.
time.Advance(TimeSpan.FromHours(1));
await biome
    .AddOne(
        Blueprints.Repository,
        out var second,
        // Backdate from the advanced clock after Biome rounds it.
        (repo, ctx) => repo.CreatedAt = ctx.Ago(TimeSpan.FromMinutes(5))
    )
    .AddPullRequest(out _)
    .AddCodeReview(out _)
    .AddActiveLock(out var activeLock)
    .BuildAsync();

// first.CreatedAt   == instant.AddTicks(-7)                      (rounded to 1 µs)
// second.CreatedAt  == instant.AddTicks(-7).AddMinutes(55)
// activeLock.ExpiresAt == instant.AddTicks(-7).AddMinutes(65)
Ago and FromNow derive from the rounded now, so a value read back from Postgres equals the value in memory.