Fabricate 0.1.0

dotnet add package Fabricate --version 0.1.0
                    
NuGet\Install-Package Fabricate -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fabricate" Version="0.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fabricate" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Fabricate">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fabricate --version 0.1.0
                    
#r "nuget: Fabricate, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Fabricate@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Fabricate&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Fabricate&version=0.1.0
                    
Install as a Cake Tool

Fabricate

NuGet version Build status Mutation testing License

A .NET source generator that creates builder pattern classes for test projects. Define what a valid object looks like once, get fluent With methods for free.

Why?

Test setup is verbose. You create objects, set properties, and repeat. Fabricate lets you define a valid instance of your domain object once, then override only what matters per test — surfacing intent and reducing noise.

Installation

dotnet add package Fabricate

Note: Add this only to your test project. Use PrivateAssets="all" to prevent it leaking to production.

Quick Start

Given a domain model:

public class Patient
{
    public string Name { get; set; }
    public int Age { get; set; }
    public string? MiddleName { get; set; }
}

Create a builder:

using Fabricate;

[Fabricate<Patient>]
public partial class PatientBuilder
{
    private static partial Patient ValidInstance() => new()
    {
        Name = "John Doe",
        Age = 30,
        MiddleName = null
    };
}

Use it in tests:

// Default valid instance
Patient patient = new PatientBuilder().Build();

// Override specific values
Patient child = new PatientBuilder().WithAge(5).Build();

// Implicit conversion
Patient patient = new PatientBuilder().WithName("Jane");

// Factory shorthand (auto-generated)
Patient patient = A.Patient.WithName("Quick").Build();

Features

Supported Types

  • Classes, records, structs, readonly structs, record structs
  • Constructor parameters (auto-detected)
  • Init-only properties
  • Nullable properties (generates Without methods)
  • Collections (params arrays)
  • Inherited properties (flattened)

Smart With Method Naming

  • BCL types (string, int, DateTime, etc.) → WithPropertyName(T value)
  • Custom types (unique) → With(T value) — the type is self-describing
  • Custom types (duplicated) → WithPropertyName(T value) — disambiguate

Factory Class

A static A class is auto-generated with properties for each builder:

A.Patient           // → new PatientBuilder()
A.Appointment       // → new AppointmentBuilder()

Customize the name with an assembly attribute:

[assembly: FabricateFactory("Given")]
// Now use: Given.Patient.WithName("test")

Nullable Support

// Set a nullable value
builder.WithMiddleName("Marie")

// Clear a nullable value
builder.WithoutMiddleName()

Collections

// Set multiple values
builder.WithAllergies("Peanuts", "Shellfish")

// Set single value
builder.WithAllergies("Dust")

Diagnostics

ID Severity Description
FAB001 Error ValidInstance() method not implemented
FAB002 Warning Builder class name doesn't end with "Builder"
FAB003 Error Cannot resolve a constructor for the target type
FAB004 Warning Duplicate factory property for the same target type (only the first builder is exposed)

Extending the Factory

Since A is a partial class, extend it in your test project:

public static partial class A
{
    public static PatientBuilder AdultPatient => Patient.WithAge(30);
    public static PatientBuilder ChildPatient => Patient.WithAge(5);
}

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 48 5/29/2026
0.0.1-alpha 57 5/22/2026