Guides

No-DB unit tests

Use Biome without a store for pure unit tests.

Omit the store

The district app can tell whether a class is full from its capacity and student roster. A test for that calculation can use the same blueprints without a database. Biome defaults to NullStore, and each Add returns entities immediately, so the test can call the policy as soon as the roster is ready.

TestBiome
    .Start(out _)
    .AddDistrict(out _)
    .AddSchool(out _)
    // Fill every seat so the policy sees a full class.
    .AddClass(out var schoolClass, c => c.Capacity = 2)
    .AddStudents(out var students, 2);

// Adds build the roster immediately, so the policy can run here.
var isFull = ClassCapacity.IsFull(schoolClass, students);
await Assert.That(isFull).IsTrue();
Call BuildAsync when you need to save or run the save hooks. For a pure function over entities, the Add calls are enough.

When you still want a store

A RecordingStore captures the rows Biome would save. A test can verify that parents come before children and that a student marked transient stays out of the save.

RecordingStore.cs
internal sealed class RecordingStore : IBiomeStore
{
    internal List<object> Entities { get; } = [];
    internal Action? OnSave { get; init; }

    public ValueTask SaveAsync(IReadOnlyList<object> entities, CancellationToken cancellationToken)
    {
        // Capture the rows for assertions without a database.
        Entities.AddRange(entities);
        OnSave?.Invoke();
        return ValueTask.CompletedTask;
    }
}
ClassRosterTests.cs
var store = new RecordingStore();
var biome = TestBiome.Start(out _, store);

await biome
    .AddDistrict(out var district)
    .AddSchool(out var school)
    .AddClass(out var schoolClass)
    // Keep the student available for the relationship check below.
    .AddStudent(out var student)
    .Transient()
    .BuildAsync();

await Assert.That(student.ClassId).IsEqualTo(schoolClass.Id);

// The store sees parents in order, without the student.
await Assert.That(store.Entities.SequenceEqual([district, school, schoolClass])).IsTrue();

Inspecting what was built

Keep the starting builder when you want to inspect entities a helper created. The quick start helper AddFullClass exposes the class and its students. Use the builder to find their school or district.

Inspect
var biome = TestBiome.Start(out _);
biome.AddFullClass(out _, out _);

// Inspect rows the helper creates without adding out parameters to it.
var school = biome.Last<School>();
var districts = biome.All<District>();
All<T>() and Last<T>() include transient entities and aggregate wrappers, but not seed rows. Prefer naming entities with out when the test is about them, and use All / Last for entities that helpers create.