Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cobysy/a7964cc8b30c3bcc72c2cb3d84567e34 to your computer and use it in GitHub Desktop.
Save cobysy/a7964cc8b30c3bcc72c2cb3d84567e34 to your computer and use it in GitHub Desktop.
Automocking dependencies in unit tests for C# with AutoFixture
[Fact]
public void WithAutoFixture()
{
var fixture = new Fixture();
fixture.Customize(new AutoMoqCustomization()); // set up automocking
var dependency1stub = fixture.Freeze<Mock<IDependecy1>>();
var dependency2mock = fixture.Freeze<Mock<IDependecy2>>();
dependency1stub.Setup(x => x.SomeQuery()).Returns(2);
var sut = fixture.Create<SUT>(); // initialise object with mocked dependencies
Assert.Equal(4, sut.GetDoubleValue(2));
dependency2mock.Verify(x => x.SomeComand());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment