AutoFixture with ASP.NET Core

October 15th 2017

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"?>
<add key="AspNetCore" value="" />
<add key="AspNetCoreTools" value="" />
<add key="NuGet" value="" />
<add key="AutoFixture MyGet" value="" />

With the AutoFixture feed configured, you can create an 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.