Customizations catalog

Package reusable fixture setup with ICustomization, CompositeCustomization, and team profiles.

When several tests share the same fixture setup — AutoMoq, string prefixes, behaviors — package that setup as ICustomization types instead of repeating Register and Customize calls in every test.

Example scenario

Your team uses AutoMoq for mocks and a string prefix rule for readable test output. You want both customizations applied whenever a test creates a new fixture.

ICustomization

The interface has one method — apply your setup to a fixture:

public interface ICustomization
{
    void Customize(IFixture fixture);
}

Implement it with the same APIs you use inline: Register, Customize<T>, Behaviors.Add, and so on.

public sealed class StringPrefixCustomization : ICustomization
{
    public void Customize(IFixture fixture)
    {
        fixture.Customize<string>(composer => composer
            .FromSeed(seed => $"doc-{seed}"));
    }
}
var fixture = new Fixture().Customize(new StringPrefixCustomization());

var text = fixture.Create<string>();

Assert.StartsWith("doc-", text);

See Customizations for Register, With, FromFactory, and FromSeed.

Built-in packages ship their own implementations — for example AutoMoqCustomization and NoAutoPropertiesCustomization.

CompositeCustomization

Run several customizations in one call. Each child runs in order on the same fixture:

var fixture = new Fixture().Customize(
    new CompositeCustomization(
        new AutoMoqCustomization(),
        new StringPrefixCustomization()));

var text = fixture.Create<string>();
var service = fixture.Create<OrderService>();

Assert.StartsWith("doc-", text);
Assert.NotNull(service);

Order matters when later customizations override earlier ones.

Subclass CompositeCustomization

For a fixed team profile, subclass and pass the bundle to the base constructor:

public sealed class TeamFixtureCustomization : CompositeCustomization
{
    public TeamFixtureCustomization()
        : base(
            new AutoMoqCustomization(),
            new StringPrefixCustomization())
    {
    }
}
var fixture = new Fixture().Customize(new TeamFixtureCustomization());

var service = fixture.Create<OrderService>();

Assert.NotNull(service);
Assert.StartsWith("doc-", fixture.Create<string>());

One type name documents the standard test fixture for your project. Reuse it from a custom AutoData attribute.

How it works

  • ICustomization — encapsulates fixture setup in Customize(IFixture fixture)
  • CompositeCustomization — runs multiple ICustomization instances in order; it is itself an ICustomization
  • Subclassing CompositeCustomization — names a fixed bundle of customizations for reuse across tests and test attributes

Next steps

API