AutoFixture producing different results under different scenarios #1389
-
Hi all Posting this here as I'm not sure if what I'm seeing is a bug or me just being an Autofixture noob. I used the quickstart found in the link below as a starting point to setup some tests for an example class. To produce a minimal working example, I create a new application with In it, I've defined a test class called
What I'm wanting to do is test Using the aforementioned link, I set up two tests, one using a custom attribute and the other without it.
The first test fails in the constructor due since no key is found for I'm attaching the details of my .csproj file below - any advice on the above situation? Many thanks for any and all help!
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@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. [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 configuration is not resolved in the constructor but at the moment it is actually used. |
Beta Was this translation helpful? Give feedback.
@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.
The solution here is to fix your design so that the…