Hallett.AutoFixture.NUnit4 1.0.4

dotnet add package Hallett.AutoFixture.NUnit4 --version 1.0.4
                    
NuGet\Install-Package Hallett.AutoFixture.NUnit4 -Version 1.0.4
                    
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="Hallett.AutoFixture.NUnit4" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hallett.AutoFixture.NUnit4" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="Hallett.AutoFixture.NUnit4" />
                    
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 Hallett.AutoFixture.NUnit4 --version 1.0.4
                    
#r "nuget: Hallett.AutoFixture.NUnit4, 1.0.4"
                    
#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 Hallett.AutoFixture.NUnit4@1.0.4
                    
#: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=Hallett.AutoFixture.NUnit4&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=Hallett.AutoFixture.NUnit4&version=1.0.4
                    
Install as a Cake Tool

Hallett.AutoFixture.NUnit4

Custom frozen attributes

The NUnit FrozenAttribute is reliant upon test method parameter names when Matching.PropertyName, Matching.FieldName, Matching.ParameterName.

The FrozenNamedAttribute allows for nameof.

The FrozenParameterIndexAttribute cannot use nameof so instead you specify a Type that has a method that will be found by an IMethodQuery ( default ModestConstructorQuery) containing a parameter that is a base type of the attributed test method parameter type.

If there is more than one parameter then you can specify which one with the index constructor parameter. If you want the second then the index is 1, the parameter position is irrelevant.

To change from ModestConstructorQuery set the MethodQueryType property

NUnit parameterized tests with CancelAfterAttribute

Of the NUnit parameterized tests only TestCaseAttribute has an AutoFixture version, InlineAutoDataAttribute.

AutoFixture.xUnit3 on the other hand has MemberAutoDataAttribute and ClassAutoDataAttribute that together work similar to TestCaseSourceAttribute.

These two are on the Version 5 roadmap for NUnit

The existing AutoFixture attributes for NUnit, AutoDataAttribute and InlineAutoDataAttribute, do not support the CancelAfterAttribute.

These can be replaced with AutoTestAttribute and AutoTestCaseAttribute which support the CancelAfterAttribute.

There is also a generic version of these, so that the IFixture does not have to come from Func<IFixture>.

e.g

    public class AutoTestAttribute<TFixtureFactory>()
        : AutoTestAttribute(new TFixtureFactory().Create) where TFixtureFactory : IFixtureFactory, new()
    {
    }

The remaining parameterized tests are supported with :

A new AutoFixture, CancelAfterAttribute aware, version of TestCaseSourceAttribute - AutoTestCaseSourceAttribute

For the following NUnit attributes ( IParameterDataSource )

The RandomAttribute

The RangeAttribute

The ValuesAttribute

The ValueSourceAttribute

Their functionality comes from the abstract CombiningStrategyAttribute with derivations supplying

protected CombiningStrategyAttribute(ICombiningStrategy strategy, IParameterDataProvider provider)

The derivations CombinatorialAttribute, PairwiseAttribute, SequentialAttribute all provide ParameterDataSourceProvider that work with the IParameterDataSource attributes above.

Each provide a corresponding stategy - CombinatorialStrategy, PairwiseStrategy and SequentialStrategy.

The final NUnit parameterization is the TheoryAttribute, whose DatapointProvider looks for [DatapointAttribute] and [DatapointSourceAttribute] on fields, properties and non void methods.

public TheoryAttribute(bool searchInDeclaringTypes = false) : base(
    new CombinatorialStrategy(),
    new ParameterDataProvider(new DatapointProvider(searchInDeclaringTypes), new ParameterDataSourceProvider()))
{
}

There are "Auto" versions of CombiningStrategyAttribute and derivations.

If you have your own IParameterDataProvider derivation note that the AutoCombiningStrategyAttribute accepts IAutoParameterDataProvider.

    public abstract class AutoCombiningStrategyAttribute(
        ICombiningStrategy strategy, 
        IAutoParameterDataProvider provider, 
        Func<IFixture>? fixtureFactory = null)
        : Attribute, ITestBuilder, IApplyToTest
    {

The difference being int NumberOfParameters(IMethodInfo method); instead of public bool HasDataFor(IParameterInfo parameter).

There is a provided implementation where the presence of [Auto] marks the cut off point where AutoFixture provides the remaining parameters. It is only necessary to mark if useDataFor is false.

    public class AutoParameterDataProvider(IParameterDataProvider nunitParameterDataProvider, bool useHasDataFor = true) : IAutoParameterDataProvider
    {
        public IEnumerable GetDataFor(IParameterInfo parameter) => nunitParameterDataProvider.GetDataFor(parameter);

        public int NumberOfParameters(IMethodInfo method)
        {
            var parameters = method.GetParameters();
            for(var i=0;i<parameters.Length; i++)
            {
                var parameter = parameters[i];
                if (parameter.IsAutoParameter() || (useHasDataFor && !nunitParameterDataProvider.HasDataFor(parameter)))
                {
                    return i;
                }
            }

            return parameters.Length;
        }
    }

Note that with NUnit and IParameterDataSource attributes it is not necessary to apply the CombinatorialAttribute to the test method as it is the default. This is not true with AutoCombinatorialAttribute.

For AutoTheoryAttribute to work you need to apply [Auto] on the first parameter to be supplied by AutoFixture. ( as internally the NUnit DatapointProvider is used and HasDataFor only applied when used by an NUnit TheoryAttribute )

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  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.0.4 50 6/29/2026
1.0.3 57 6/29/2026
1.0.2 52 6/29/2026
1.0.1 52 6/29/2026
1.0.0 59 6/28/2026