fsharp/fsfoundation — pull request #363 by moodmosaic (2014-11-18 18:36:47+00:00)
Title: Add AutoFixture.AutoFoq project to Testing Tools

This pull request originates from [this](https://github.com/fsprojects/fsprojects.github.io/issues/5#issuecomment-62634180) comment – it adds [AutoFixture.AutoFoq](http://www.nuget.org/packages/AutoFixture.AutoFoq) to the Testing Tools section.

-----

AutoFixture.AutoFoq turns [AutoFixture](http://www.nuget.org/packages/AutoFixture) into an [Auto-mocking Container](http://blog.ploeh.dk/2013/03/11/auto-mocking-container/) where the mock instances are created by [Foq](https://github.com/fsprojects/Foq).

**Typical usage**

In the test below the mocked instance is created automatically by Foq:

```f#
[]
let AutoMockInterfaceAndSetupExpectations() =
// Fixture setup
let fixture = Fixture().Customize(AutoFoqCustomization())
let dummy = obj()
// Exercise system
let sut = fixture.Create()
sut.MakeIt(dummy) |> ignore
// Verify outcome
Mock.Verify(<@ sut.MakeIt(dummy) @>, Times.Once)
// Teardown
```

**Integration with xUnit.net**

The above test can be written declaratively using xUnit.net's data theories:

```f#
[][]
let AutoMockInterfaceAndSetupExpectationsDeclaratively
(sut : IInterface, dummy : obj) =
sut.MakeIt(dummy) |> ignore
Mock.Verify(<@ sut.MakeIt(dummy) @>, Times.Once)
```

The `[AutoFoqData]` attribute is defined as:

```f#
type AutoFoqDataAttribute() =
inherit AutoDataAttribute(
Fixture().Customize(AutoFoqCustomization()))
```