Input blueprints
Blueprint.FromInput, and Blueprint.ChildFromInput for typed children, require a referenced library package that exposes those API forms. Check the API for the package selected by your project; if you use Zeeq.Biome.EntityFrameworkCore, use the matching package version. This documentation does not identify a public release for these forms.When the row can't be edited after it is built
A customizer runs after the factory has created the entity. That works while the test only assigns settable properties. It stops working when the property is init-only (including positional record properties), which a customizer cannot assign, or when one choice drives several values. A required member must be initialized by the factory, but if it has a setter a customizer can still set it.
An input blueprint moves customization earlier. The test customizes a small, settable input object. Then the factory reads the input and builds the row in one step. Your production model does not need to change to suit the tests.
For example, an academic term has an EndsOn date that tests never choose directly. They choose how many weeks the term lasts:
public sealed class AcademicTerm
{
public required string Id { get; init; }
public required string Name { get; init; }
public required DateOnly StartsOn { get; init; }
public required DateOnly EndsOn { get; init; }
}
// Tests set the duration before the factory initializes the term's dates.
public sealed class TermInput
{
public string? Name { get; set; }
public DateOnly StartsOn { get; set; }
public int Weeks { get; set; }
}
public static partial class Blueprints
{
public static readonly InputBlueprint<SchoolSeed, TermInput, AcademicTerm> Term = Blueprint
.FromInput<SchoolSeed, TermInput, AcademicTerm>(
() => new(),
(input, ctx) =>
new()
{
Id = ctx.NewId("term"),
Name = input.Name!,
StartsOn = input.StartsOn,
// Compute the init-only end date from the chosen duration.
EndsOn = input.StartsOn.AddDays(input.Weeks * 7),
}
)
// Fill the input before construction so the name can use the final duration.
.Derive(t => t.StartsOn, (_, ctx) => DateOnly.FromDateTime(ctx.Now.UtcDateTime))
.Derive(t => t.Weeks, (_, _) => 18)
.Derive(t => t.Name, (t, _) => $"{t.Weeks}-week term");
}
The factory initializes every required member, so the row is always valid. Derive fills input properties that are still unset, in declaration order, before the factory runs. A test then states only the choice it cares about:
await TestBiome
.Start(out _)
// The factory calculates EndsOn from the nine-week duration.
.AddOne(Blueprints.Term, out var halfTerm, t => t.Weeks = 9)
.BuildAsync();
var startsOn = DateOnly.FromDateTime(DateTime.UtcNow);
var halfTerm = new AcademicTerm
{
Id = $"term_{Guid.CreateVersion7():N}",
Name = "9-week term",
StartsOn = startsOn,
// Keep the end date consistent with the duration in the name.
EndsOn = startsOn.AddDays(9 * 7),
};
halfTerm.EndsOn is nine weeks after StartsOn, and the test never mentioned a date. Both versions stay in memory, because neither saves anything.
Typed child inputs
A child can use an input too. Blueprint.ChildFromInput takes the input factory and a build function that receives the typed parent, the input, and the child context. It behaves like ChildOf: the child compiles only after its parent, and ctx.Ancestor<T>() reaches further up.
In this version of the school app, an enrollment row is immutable. A sequence supplies its seat number.
public sealed class Enrollment
{
public required string Id { get; init; }
public required string DistrictId { get; init; }
public required string SchoolId { get; init; }
public required string ClassId { get; init; }
public required int Seat { get; init; }
public required string Source { get; init; }
public required DateTimeOffset EnrolledAtUtc { get; init; }
}
// Customize the input before the factory initializes the immutable enrollment.
public sealed class EnrollmentInput
{
public int Seat { get; set; }
public bool IsTransfer { get; set; }
public DateTimeOffset EnrolledAtUtc { get; set; }
}
// Each class gets its own seat sequence.
public static readonly Sequence<int> EnrollmentSeats = Sequence.Of(1, n => n + 1).PerParent();
public static readonly ChildInputBlueprint<
SchoolSeed,
SchoolClass,
EnrollmentInput,
Enrollment
> Enrollment = Blueprint
.ChildFromInput<SchoolSeed, SchoolClass, EnrollmentInput, Enrollment>(
() => new(),
(schoolClass, input, ctx) =>
new()
{
Id = ctx.NewId("enr"),
DistrictId = schoolClass.DistrictId,
// The typed parent gives the class ID. Its ancestor gives the school ID.
SchoolId = ctx.Ancestor<School>().Id,
ClassId = schoolClass.Id,
Seat = input.Seat,
Source = input.IsTransfer ? "transfer" : "standard",
EnrolledAtUtc = input.EnrolledAtUtc,
}
)
.Derive(i => i.Seat, EnrollmentSeats) // Assign the seat before building the row.
.Derive(i => i.EnrolledAtUtc, (_, ctx) => ctx.Now);
Customizers and Derive work on EnrollmentInput, while out variables and the anchor hold the Enrollment rows. The count applies to each class, and the sequence continues when the test returns to the same class.
await TestBiome
.Start(out _)
.AddDistrict(out _)
.AddSchool(out _)
.AddClass(out var algebra)
// Return to Algebra so the transfer takes the next seat in the same sequence.
.Add(Blueprints.Enrollment, out var seated, 2)
.Under(algebra)
.AddOne(Blueprints.Enrollment, out var transfer, e => e.IsTransfer = true)
.BuildAsync();
A customizer that needs the parent or the clock takes a second parameter. For a child input, that is the ChildContext, so ctx.Parent and ctx.Ago(…) are available:
await TestBiome
.Start(out _)
.AddDistrict(out _)
.AddSchool(out _)
.AddClass(out _)
.AddOne(
Blueprints.Enrollment,
out var early,
// Use the session clock so the test can control the enrollment time.
(e, ctx) => e.EnrolledAtUtc = ctx.Ago(TimeSpan.FromDays(3))
)
.BuildAsync();
out holds the output. Add a handwritten context-aware overload only when tests use it repeatedly. See Generated grafts and scenario helpers.What an input is, and is not
An input is construction data. Biome does not record it, save it, or let it be a parent:
All<EnrollmentInput>()is always empty.out,.Under(…),.Transient(),All<Enrollment>()andLast<Enrollment>()all work on the outputs.- A root input blueprint stays a root after
.Under(…).Underdoes not fill its input or supply a parent. UseChildFromInputwhen the row needs a parent. - Global defaults (
options.Default) apply to the output row after the factory runs.Deriveon an input blueprint applies to the input.
Order of work in one Add step
A step builds all of its inputs before it builds any output, so a sequence can reserve every explicit value first:
- Each input is created, then its traits (
.With) and call-site customizers run. Derive(property, sequence)reserves every explicit value in the step.- For each input, in order: its
Derives fill unset input properties, then the factory builds the output. - Each output gets the global defaults, then is recorded with its parent link.
Input factories, derives, traits and customizers see only entities from earlier completed steps, through ctx.All<T>() and ctx.Last<T>(). Wire relationships through the typed parent and ctx.Ancestor<T>(), not through inspection.
Aggregates: one input, several rows
An input blueprint can also build a group of rows from one choice. When the output implements IBiomeAggregate, Biome saves its parts in place of the wrapper.
Opening a district creates a district, its first school, and the school's main office. A test can choose the school's name and code in one input. The factory connects the three rows and the wrapper gives their save order.
public sealed class DistrictOpeningInput
{
public string DistrictName { get; set; } = "Riverside Unified";
public string? FirstSchoolName { get; set; }
public string? FirstSchoolCode { get; set; }
}
public sealed record DistrictOpening(District District, School FirstSchool, SchoolOffice MainOffice)
: IBiomeAggregate
{
// Set the save order so each parent precedes its dependent rows.
public IEnumerable<object> GetEntities() => [District, FirstSchool, MainOffice];
}
public static partial class Blueprints
{
public static readonly InputBlueprint<
SchoolSeed,
DistrictOpeningInput,
DistrictOpening
> DistrictOpening = Blueprint
.FromInput<SchoolSeed, DistrictOpeningInput, DistrictOpening>(
() => new(),
(input, ctx) =>
{
var district = new District
{
Id = ctx.NewId("dist"),
Name = input.DistrictName,
TimeZoneId = ctx.Seed.TimeZoneId,
CreatedAtUtc = ctx.Now,
UpdatedAtUtc = ctx.Now,
};
var school = new School
{
Id = ctx.NewId("sch"),
DistrictId = district.Id,
Name = input.FirstSchoolName!,
Code = input.FirstSchoolCode!,
CreatedAtUtc = ctx.Now,
UpdatedAtUtc = ctx.Now,
};
var office = new SchoolOffice
{
Id = ctx.NewId("office"),
DistrictId = district.Id,
SchoolId = school.Id,
IsMain = true,
};
// Return one result so the test can use the three linked rows together.
return new(district, school, office);
}
)
.Derive(i => i.FirstSchoolName, (_, _) => "North High")
.Derive(i => i.FirstSchoolCode, (_, _) => "NH");
}
The test for South High supplies the details that identify the school. Biome saves the district and main office along with it.
await TestBiome
.Start(_db, out _)
.AddOne(
Blueprints.DistrictOpening,
out var opened,
// Choose the school's identity once. The factory wires up its main office.
input =>
{
input.FirstSchoolName = "South High";
input.FirstSchoolCode = "SH";
}
)
.BuildAsync();
var now = DateTimeOffset.UtcNow;
var district = new District
{
Id = $"dist_{Guid.CreateVersion7():N}",
Name = "Riverside Unified",
TimeZoneId = "America/Chicago",
CreatedAtUtc = now,
UpdatedAtUtc = now,
};
var school = new School
{
Id = $"sch_{Guid.CreateVersion7():N}",
DistrictId = district.Id,
Name = "South High",
Code = "SH",
CreatedAtUtc = now,
UpdatedAtUtc = now,
};
var office = new SchoolOffice
{
Id = $"office_{Guid.CreateVersion7():N}",
DistrictId = district.Id,
SchoolId = school.Id,
IsMain = true,
};
// Persist all three linked rows in the same save to complete the opening.
_db.AddRange(district, school, office);
await _db.SaveChangesAsync();
At BuildAsync, aggregates are expanded recursively into their parts. Duplicate references are saved once, and a cycle in GetEntities() throws. Any registered seed rows precede the parts, which follow the order in GetEntities().
All<T>() and Last<T>() include aggregate wrappers and transient entities, but not seed rows. The store never receives the wrapper itself. Parts are not tracked as parents, so a child of this aggregate takes DistrictOpening as its TParent. Global defaults reach the wrapper, not its parts.Variants and transients
Input blueprints, root and child, support .With, .Derive and .AsTransient() like entity blueprints. A preview can build the full district graph in memory. Marking the aggregate transient excludes all three rows from the save.
var preview = Blueprints
.DistrictOpening.With(input => input.DistrictName = "Riverside Unified (Preview)")
.With(input =>
{
input.FirstSchoolName = "South High";
input.FirstSchoolCode = "SH";
})
.AsTransient(); // Exclude all three rows from the save.
Limits to keep in mind
Derive treats an input property's default value as unset. On a plain int or bool, an explicit 0 or false looks "not chosen", so a derive will fill it. On a nullable value type such as int? or bool?, an explicit 0 or false is kept, but an explicit null is still treated as unset and refilled if a Derive targets that property. Global defaults on the output can also replace null, 0 or false, because they fill by the same rule.- Biome does not copy values from an input to the output. The factory decides how each input property becomes part of the row.
- An input blueprint is more setup than a plain blueprint. Use one when the row has init-only properties that tests vary, when one choice drives several values, or when the output is a group of rows. For a single settable entity, customizing it directly is simpler.
- The default pipeline still applies to outputs: defaults are fill-only and run after the factory.