NUnit.AutoFixture.Composition 1.0.1

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

// Install NUnit.AutoFixture.Composition as a Cake Tool
#tool nuget:?package=NUnit.AutoFixture.Composition&version=1.0.1

NUnit.AutoFixture.Composition

This is a micro-framework for composable CustomizeAttribute in AutoFixture.NUnit. It originated with this StackOverflow question/answer.

What this library does

If you are using NUnit 3, AutoFixture and the integration between these frameworks then it is likely that you are also writing your own CustomiseAttribute implementations to configure how the AutoFixture specimen is created.

What's slightly more difficult with just the libraries above is writing customize attributes which may be composed. Customizations written using the following syntax cannot be easily split into separate classes and then composed.

fixture.Customize<MyType>(c => c.With(x => x.SomeProperty, "Some value"));

The technique shown above controls the initial creation of the specimen. Obviously, only one such customisation can be used: an object may only be created once. This micro-framework provides a shorthand syntax for writing AutoFixture behaviours, which can post-process an object after creation, and are thus suitable for composition.

Using this library

Write your CustomiseAttribute types like the following example; do not write an ICustomization class directly.

public class WithMyPropertyAttribute : CustomizeAttribute
{
    public override ICustomization GetCustomization(ParameterInfo parameter)
        => GetParameterTranformer.Customization.ForType<SampleObject>(parameter, x => x.MyProperty = "My value");
}

In this example, we customize an instance of SampleObject to have its MyProperty value set to the value "My value". The example above is also configured to only apply this behaviour when the specimen is requested via a matching parameter, useful where the specimen is to be parameter-injection into a test. As with any other attributes, this could be parameterized by accepting constructor parameters and/or property setters in the attribute definition.

Technical info

The core of the library is the GetParameterTranformer static class. It gets an ICustomization instance for post-processing a specimen.

For advanced uses, use the methods which gets only an ISpecimenBuilderTransformation, which may then be manipulated as desired.

Another advanced technique is to use the overloads of ForType<T> which provide access to an ISpecimenContext in the customization callback. That specimen context provides access back to Autofixture's functionality. This could be useful to re-invoke AutoFixture functionality in order to create further specimens where needed.

Product 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 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. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.5 is compatible.  netstandard1.6 was computed.  netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.1 98 5/19/2024
1.0.0 83 5/19/2024