AutoFixture.Community.Customizations 1.0.0

dotnet add package AutoFixture.Community.Customizations --version 1.0.0
NuGet\Install-Package AutoFixture.Community.Customizations -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="AutoFixture.Community.Customizations" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AutoFixture.Community.Customizations --version 1.0.0
#r "nuget: AutoFixture.Community.Customizations, 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.
// Install AutoFixture.Community.Customizations as a Cake Addin
#addin nuget:?package=AutoFixture.Community.Customizations&version=1.0.0

// Install AutoFixture.Community.Customizations as a Cake Tool
#tool nuget:?package=AutoFixture.Community.Customizations&version=1.0.0

AutoFixture Community Customizations

.NET

IgnoreAutoFixture Attribute

The IgnoreAutoFixture attribute can be added to properties in a model to instruct AutoFixture to ignore/omit the property during building, unless explicitly instructed to be created.

This is especially useful for standing up models used by Entity Framework. Most of these models utilize circular dependencies, which would cause an exception to be raised by AutoFixture normally.

An example of this can be found below:

public class TestModel
{
    public InnerModel? IncludedModel { get; set; } // Will be instantiated by AutoFixture

    [IgnoreAutoFixture]
    public InnerModel? OmittedModel { get; set; } // Will be omitted by AutoFixture
    
    [IgnoreAutoFixture]
    public InnerModel? ExplicitlyIncludedModel { get; set; } // Will also be omitted by AutoFixture, but will be explicitly included (see below)
}

public class Tests
{
    [Test]
    public void AutoFixtureTests()
    {
        var fixture = new Fixture();
        fixture.AddIgnorePropertiesCustomization();
        
        var model = fixture.Build<TestModel>()
            .With(x => x.ExplicitlyIncludedModel, new InnerModel()) // Tells AutoFixture to set this property, instead of ignoring it.
            .Create();
        
        Assert.That(model.IncludedModel, Is.Not.Null);
        Assert.That(model.OmittedModel, Is.Null);
        Assert.That(model.ExplicitlyIncludedModel, Is.Not.Null);
    }
}

DateOnly/TimeOnly Customization

AutoFixture customizations are provided to handle DateOnly and TimeOnly properties. By default, AutoFixture doesn't handle these types and will throw exceptions.

An example of this can be found below:

public class TestModel
{
    public DateOnly? Date { get; set; }

    public TimeOnly? Time { get; set; }
    
}

public class Tests
{
    [Test]
    public void AutoFixtureTests()
    {
        var fixture = new Fixture();
        fixture
            .AddDateOnlyCustomization()
            .AddTimeOnlyCustomization();
        
        var model = fixture.Create<TestModel>();
        
        Assert.That(model.Date, Is.Not.Null);
        Assert.That(model.Time, Is.Not.Null);
    }
}

AutoFixture Extension Methods

To use any of these customizations, you can use the following extension methods:

var fixture = new Fixture();
fixture.AddIgnorePropertiesCustomization(); // Ignore properties
fixture.AddDateOnlyCustomization(); // DateOnly
fixture.AddTimeOnlyCustomization(); // TimeOnly

You can also chain any of these extensions together:

var fixture = new Fixture();
fixture
    .AddIgnorePropertiesCustomization()
    .AddDateOnlyCustomization()
    .AddTimeOnlyCustomization();

If you'd rather, you can ignore these extension methods and add the customizations yourself manually:

var fixture = new Fixture();
fixture.Customizations.Add(new IgnorePropertiesSpecimenBuilder()); // Ignore properties
fixture.Customize(new DateOnlyCustomization()); // DateOnly
fixture.Customize(new TimeOnlyCustomization()); // TimeOnly
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
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.0.0 65 6/12/2024