ConstructorCustomization.AutoFixture
1.0.1
See the version list below for details.
dotnet add package ConstructorCustomization.AutoFixture --version 1.0.1
NuGet\Install-Package ConstructorCustomization.AutoFixture -Version 1.0.1
<PackageReference Include="ConstructorCustomization.AutoFixture" Version="1.0.1" />
<PackageVersion Include="ConstructorCustomization.AutoFixture" Version="1.0.1" />
<PackageReference Include="ConstructorCustomization.AutoFixture" />
paket add ConstructorCustomization.AutoFixture --version 1.0.1
#r "nuget: ConstructorCustomization.AutoFixture, 1.0.1"
#:package ConstructorCustomization.AutoFixture@1.0.1
#addin nuget:?package=ConstructorCustomization.AutoFixture&version=1.0.1
#tool nuget:?package=ConstructorCustomization.AutoFixture&version=1.0.1
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(...)andWithout(...). - 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
- Wiki home: Home
- Getting started: Getting Started
- Behavior customization: Customizing Behavior
- Extension points: Extensions Overview
- How it Works: Creation Pipeline
๐ ๏ธ Build and Test
dotnet restore
dotnet build --configuration Release
dotnet test --configuration Release
๐งช Examples
The repository includes three package-consumer examples:
Examples/Example.Net10(net10.0)Examples/Example.Net8(net8.0)Examples/Example.NetStandard21(netstandard2.1)
All examples reference the ConstructorCustomization.AutoFixture NuGet package via PackageReference.
Examples are intentionally isolated from the main Solution.slnx to keep PR build/test pipelines independent.
Build examples against local artifacts
Run this single command from repository root to pack the local package and build all three examples:
./scripts/rebuild-package-and-examples.ps1
- Pack the local package into the
artifactsfolder:
dotnet pack ConstructorCustomization.AutoFixture/ConstructorCustomization.AutoFixture.csproj --configuration Release --output ./artifacts
- Restore and build from repository root:
dotnet restore Examples/Examples.slnx --configfile Examples/nuget.config
dotnet build Examples/Examples.slnx --configuration Release
If you change the local package version, update ConstructorCustomization.AutoFixture in Examples/Directory.Packages.props to match.
| Product | Versions 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 is compatible. 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 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- AutoFixture (>= 4.18.1)
-
net10.0
- AutoFixture (>= 4.18.1)
-
net8.0
- AutoFixture (>= 4.18.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.