ConstructorCustomization.AutoFixture 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ConstructorCustomization.AutoFixture --version 1.0.0
                    
NuGet\Install-Package ConstructorCustomization.AutoFixture -Version 1.0.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="ConstructorCustomization.AutoFixture" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConstructorCustomization.AutoFixture" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ConstructorCustomization.AutoFixture" />
                    
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 ConstructorCustomization.AutoFixture --version 1.0.0
                    
#r "nuget: ConstructorCustomization.AutoFixture, 1.0.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 ConstructorCustomization.AutoFixture@1.0.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=ConstructorCustomization.AutoFixture&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ConstructorCustomization.AutoFixture&version=1.0.0
                    
Install as a Cake Tool

ConstructorCustomization.AutoFixture

Constructor-first customization for AutoFixture with clean defaults, per-test overrides, and extension points for advanced object creation.

Why This Package?

AutoFixture provides powerful Fixture creation and customization capabilities. But it creates objects by setting properties after the constructor is called.

But what if you have Guards and follow the Always-Valid-Model principle?

ConstructorCustomization.AutoFixture provides a constructor-first customization model for AutoFixture. This is a package only built on AutoFixture and provides an ICustomization implementation with minimal effort to get started but highly extensible for advanced scenarios.

✨ Features

  • Create simple objects in a one-liner.
  • Use Fluent API to override defaults on a per-test basis.
  • Explicitly map constructor parameters to properties.
  • Pluggable extension model for matching and specimen/value creation behavior.
  • Fully compatible with AutoFixture ecosystem and existing customizations.

🔧 How it works

Under the hood, ConstructorCustomization uses reflection to retrieve a constructor and matches property names to parameter names. Values are created using AutoFixture's existing value creation.

Constructor selection, parameter matching and value creation can all be customized using the provided extension models.

📦 Install

dotnet add package ConstructorCustomization.AutoFixture

⚡ Quick Entry

Use this when you want a fast start in a test.

using AutoFixture;
using ConstructorCustomization.AutoFixture;

var fixture = new Fixture();

fixture.Customize(new ConstructorCustomization<Person>()
	.With(x => x.FirstName, "Ada")
	.With(x => x.LastName, "Lovelace")
	.Without(x => x.MiddleName));

var person = fixture.Create<Person>();

🧩 Simple Usage Pattern

For reusable test behavior, create a typed customization once and use it across many tests.

using AutoFixture;
using ConstructorCustomization.AutoFixture;

public class PersonCustomization : ConstructorCustomization<Person, PersonCustomization>
{
	protected override Person CreateInstance(IFixture fixture)
	{
		SetDefault(x => x.FirstName, "Ada");
		SetDefault(x => x.LastName, "Lovelace");
		SetDefault(x => x.Age, 36);
		return base.CreateInstance(fixture);
	}
}

var fixture = new Fixture();
var customization = new PersonCustomization();
fixture.Customize(customization);

var defaultPerson = fixture.Create<Person>();

customization.With(x => x.Age, 18);
var youngPerson = fixture.Create<Person>();

customization.Clear();

✅ Capabilities at a Glance

  • Constructor-first object creation for test models.
  • Stable defaults with SetDefault(...).
  • Per-test overrides with With(...) and Without(...).
  • Explicit parameter-to-property mapping with MatchParameterToProperty(...).
  • Deferred value generation with factory delegates.
  • Pluggable extension model for matching and specimen/value creation behavior.

📚 Documentation and Wiki

🛠️ Build and Test

dotnet restore
dotnet build --configuration Release
dotnet test --configuration Release
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.1.1 87 3/15/2026
1.1.0 84 3/14/2026
1.0.1 74 3/14/2026
1.0.0 82 3/14/2026