AutoFixture with ASP.NET Core

Until the (imminent) release of AutoFixture 4, there is currently no support for AutoFixture within .NET Core.

Update - January 10th 2018

AutoFixture 4 is now available on the official NuGet feed, however the rest of this article is useful if you ever need to use a package on a different feed.

However, we can solve the issue in the short term by using a vNext feed of AutoFixture hosted on MyGet.

You can create a nuget.config file as a sibling to your Visual Studio Solution (.sln) file with the AutoFixture MyGet package feed configured:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
    <add key="AspNetCoreTools" value="https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json" />
    <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
    <add key="AutoFixture MyGet" value="https://www.myget.org/F/autofixture/api/v3/index.json" />
  </packageSources>
</configuration>

With the AutoFixture feed configured, you can create an xUnit.net Test Project (.NET Core) within Visual Studio 2017.

Install the following packages from the AutoFixture MyGet feed:

  • AutoFixture.Xunit2
  • AutoFixture.AutoMoq

Ensure to include pre-release versions to view these packages

Install the following from the standard NuGet feed:

  • Moq (this ensures you’re using a later version of Moq than that included with AutoFixture.AutoMoq)

Then an appropriate assertion package, depending on your preference, e.g:

  • xunit.assert
  • FluentAssertions
  • Shouldly

This should give you everything you need to start testing.