Here is a type with a private constructor:
In order to create an instance of that type we have to call one of it's static factory methods, for example:
Using the latest version from trunk (and on the next public release) the above code will work. It will successfully return an instance of the type by using a set of heuristics that enable AutoFixture to search for static factory methods.
The latest build (including strong names) can be downloaded from here.
xUnit.net supports parameterized tests via data theories which are types deriving from the Xunit.Extensions.DataAttribute type. Some popular attributes include:
InlineDataAttribute, PropertyDataAttribute and ClassDataAttribute.
AutoFixture.Xunit extension includes a very useful type, for providing auto-data theories, called AutoMoqDataAttribute.
Imagine a Scenario where we have a unit test method with 3 parameters. We want the first parameters to be supplied by InlineData and the rest by AutoFixture using AutoMoqData.
This is now possible using the InlineAutoDataAttribute type which is now on the trunk and will be available on next public release (after version 2.1). It provides a data source for a data theory, with the data coming from inline values combined with auto-generated data specimens generated by AutoFixture.
InlineAutoDataAttribute derives from CompositeDataAttribute, an implementation of DataAttribute that composes other DataAttribute instances.
Here is how it works:
- Delegate the GetData method call to the first attribute.
- Loop through the results from the first attribute and check if the length of each object array matches the number of arguments required by the method.
- If so, yield the object array.
- If not, invoke GetData on the next attribute.
- Throw away the first objects from the result in order to continue from where it ran out of objects from the first result set and concatenate the rest to the previous array.
- Recursively repeat this process until all object arrays have the required length.
subscribe via RSS