Created
April 16, 2016 23:31
-
-
Save cobysy/a7964cc8b30c3bcc72c2cb3d84567e34 to your computer and use it in GitHub Desktop.
Automocking dependencies in unit tests for C# with AutoFixture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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