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
<PackageReference Include="AutoFixture.Community.Customizations" Version="1.0.0" />
paket add AutoFixture.Community.Customizations --version 1.0.0
#r "nuget: AutoFixture.Community.Customizations, 1.0.0"
// 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
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 | Versions 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. |
-
net6.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.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 99 | 6/12/2024 |