Skip to content

AutoFixture producing different results under different scenarios #1389

Answered by aivascu
thatstatsguy asked this question in Q&A
Discussion options

You must be logged in to vote

@thatstatsguy well you've configured the customization and the attribute just well. The problem is that you're doing more than just initialization in your constructor. Your mock is not yet set up at the moment your service is created.
Basically you're doing the following, in the failing test.

[Fact]
public void ManualAutoMoq()
{
    var fixture = new Fixture().Customize(new AutoMoqCustomization());
    var configurationMock = fixture.Freeze<Mock<IConfiguration>>();
    var sut = fixture.Create<MyService>();

    configurationMock
        .Setup(x => x[It.IsAny<string>()])
        .Returns("TestKey");

    Assert.True(sut.TestMethod());
}

The solution here is to fix your design so that the…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@thatstatsguy
Comment options

Answer selected by thatstatsguy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants