Connecting AutoData of AutoFixture with NUnit3. Currently implementations depend on NUnit 2 and is tightly coupled to specific version of NUnit.core.
AutoFixture https://github.com/AutoFixture
AutoData and AutoMoqData http://blog.ploeh.dk/2010/10/08/AutoDataTheorieswithAutoFixture/
AutoFixture.NUnit3.AutoDataConnector
This will add a folder named "AutoFixutre.AutoData.NUnit3" to the current project. Avoid rename this folder as any upgrade to the package will override (or create again) it.
The reason the package is not in dll is I can't figure out a way NOT to depend on specific versions of NUnit, Moq or AutoFixture. If you have to install the package for multiple projects, my suggestion is to put the classes in a common project, which in turn can be referenced by other projects. This way you won't have duplicated classes.
Use [Test, AutoData] to request values to parameters.
[Test, AutoData]
public void AnyRandom(DateTime anyTime, CultureInfo cultureInfo)
{
Assert.That(anyTime, Is.Not.Null);
Assert.That(cultureInfo, Is.Not.Null);
}
AutoData will not be able to generate value for interfaces. For that purpose you will need to add customizations, for example, to enable AutoMoq, add the following class to your project.
using AutoDataConnector;
using Ploeh.AutoFixture;
using Ploeh.AutoFixture.AutoMoq;
namespace TestAutoDataConnector
{
public class AutoMoqDataAttribute : AutoDataAttribute
{
public AutoMoqDataAttribute()
: base(
new ParameterValueProvider(new AutoFixtureDataProvider(new AutoMoqCustomization(),
new MultipleCustomization())))
{
}
}
}
So you can do something like
[Test, AutoMoqData]
public void CanInjectDependencies([Frozen] ISinger singer, string program, Stage stage)
{
stage.Perform(program);
Mock.Get(singer).Verify(s => s.Sing(program));
}
In the above example ISinger will be a mock object generated by Moq.
AutoMoqData is not included by default because it will require Ploeh.AutoFixture.AutoMoq which in turn dependes on Moq.
Implementations could be somewhat naive at this stage, so feel free to fork it and make improvements.