VOOZH about

URL: https://www.nuget.org/packages/Maersk.Test.AutoFixtureExtensions/

⇱ NuGet Gallery | Maersk.Test.AutoFixtureExtensions 1.4.0




👁 Image
Maersk.Test.AutoFixtureExtensions 1.4.0

Prefix Reserved
dotnet add package Maersk.Test.AutoFixtureExtensions --version 1.4.0
 
 
NuGet\Install-Package Maersk.Test.AutoFixtureExtensions -Version 1.4.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="Maersk.Test.AutoFixtureExtensions" Version="1.4.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Maersk.Test.AutoFixtureExtensions" Version="1.4.0" />
 
Directory.Packages.props
<PackageReference Include="Maersk.Test.AutoFixtureExtensions" />
 
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 Maersk.Test.AutoFixtureExtensions --version 1.4.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Maersk.Test.AutoFixtureExtensions, 1.4.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 Maersk.Test.AutoFixtureExtensions@1.4.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=Maersk.Test.AutoFixtureExtensions&version=1.4.0
 
Install as a Cake Addin
#tool nuget:?package=Maersk.Test.AutoFixtureExtensions&version=1.4.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Introduction

This package contains a number of useful extension methods for AutoFixture, making working with AutoFixture simpler.

Examples

Simple scenario

For basic usage you can instrument your unit test method using the AutoDataWithCustomization attribute like this:

[Theory]
[AutoDataWithCustomization(typeof(AutoMoqCustomization))]
public void Given_some_input_When_mapping_Then_it_maps(
 Vessel vessel,
 VesselMapper sut)
{
 // ...
}

ConfigureMembers = true

If you need to set ConfigureMembers to true, then do like this instead (this will instruct AutoFixture that members of a mock will be automatically setup to retrieve the return values from the fixture):

[Theory]
[AutoDataWithCustomization(typeof(AutoMoqWithMembersCustomization))]
public void Given_some_input_When_mapping_Then_it_maps(
 Vessel vessel,
 VesselMapper sut)
{
 // ...
}

Providing a customization

A common pattern is to move some of the test customization to a separate class. You can do that like this:

[Theory]
[AutoDataWithCustomization(typeof(AutoMoqCustomization), typeof(VesselMapperCustomization))]
public void Given_some_input_When_mapping_Then_it_maps(
 Vessel vessel,
 VesselMapper sut)
{
 // ...
}

private class VesselMapperCustomization : ICustomization
{
 public void Customize(IFixture fixture)
 {
 // ...
 }
}

The code placed in the VesselMapperCustomization will get executed before the test.

Provide inline parameters to customization

It can be useful to pass inline parameters to the customization and to the test method - this allows re-using the same test in multiple scenarios. You can do this using the InlineAutoDataWithCustomization attribute:

[Theory]
[InlineAutoDataWithCustomization(typeof(VesselMapperCustomization), "vessel code 1", "vessel name 1")]
[InlineAutoDataWithCustomization(typeof(VesselMapperCustomization), "vessel code 2", "vessel name 2")]
[InlineAutoDataWithCustomization(typeof(VesselMapperCustomization), "vessel code 3", "vessel name 3")]
public void Given_some_input_and_a_specific_vessel_code_When_mapping_Then_it_maps(
 string vesselCode,
 string vesselName,
 Vessel vessel,
 VesselMapper sut)
{
 // ...
}

private class VesselMapperCustomization : CompositeCustomization
{
 public VesselMapperCustomization(
 string vesselCode,
 string vesselName)
 : base(new AutoMoqCustomization { ConfigureMembers = true }, new AutoMoqWithMembersCustomization())
 {
 // ...
 }
}

vessel code 1 will get assigned to string vesselCode, because it is the first parameter to match the type (string). Likewise, vessel name 1 will get assigned to string vesselName, because it is the second parameter to match the type (string). It is of course possible to use different types.

Note that the customization is inheriting from CompositeCustomization, and providing some additional values for that types constructor.

Only pass parameters to the customization

If you don't need to pass the inline parameters to the test method, then use the InlineCustomizationData attribute.

Specifying a value for a test parameter

The ParameterNameSpecimenBuilder can be used to set a value for a specific parameter in the test method:

[Theory]
[AutoDataWithCustomization(typeof(AutoMoqCustomization), typeof(VesselMapperCustomization))]
public void Given_some_input_When_mapping_Then_it_maps(
 DateTime scheduleArrivalTimeUtc,
 Vessel vessel,
 VesselMapper sut)
{
 // ...
}

private class VesselMapperCustomization : ICustomization
{
 public void Customize(IFixture fixture)
 {
 DateTime scheduleArrivalTimeUtc = // ...

 fixture.Customizations.Add(new ParameterNameSpecimenBuilder<DateTimeOffset>(nameof(scheduleArrivalTimeUtc), scheduleArrivalTimeUtc));
 }
}

Contribute

Read the file.

Changes

Credits

This library was originally written by:

Unit tests and documentation added by:

Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows 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.4.0 329,006 11/17/2023
1.3.1 33,234 9/5/2023
1.2.0 61,879 11/17/2022