I have the following code:
var boundArgument = new BoundArgumentOption
{
PatientId = patientId
};
var mockRepositoryFactory = A.Fake<IRepositoryFactory>();
var sut = new HtmlOutputBuilder(mockRepositoryFactory);
var patientRecord = // Some record;
var mockRepository = A.Fake<IRepository>();
A.CallTo(() => mockRepository.Get(boundArgument)).Returns(patientRecord);
A.CallTo(() => mockRepositoryFactory.Create(boundArgument)).Returns(mockRepository);
string actualResult = sut.BuildReport(boundArgument);
actualResult.Should().Be(expectedHtmlContent);
and that passes the test.
Then I tried using AutoFixture as follows:
var fixture = new Fixture().Customize(new AutoFakeItEasyCustomization());
var boundArgument = fixture.Create<BoundArgumentOption>();
var mockRepositoryFactory = A.Fake<IRepositoryFactory>();
fixture.Freeze(mockRepositoryFactory);
var sut = fixture.Create<HtmlOutputBuilder>();
var patientRecord = //Some record;
boundArgument.PatientId = patientId;
var mockRepository = A.Fake<IRepository>();
A.CallTo(() => mockRepository.Get(boundArgument)).Returns(patientRecord);
A.CallTo(() => mockRepositoryFactory.Create(boundArgument)).Returns(mockRepository);
string actualResult = sut.BuildReport(boundArgument);
actualResult.Should().Be(expectedHtmlContent);
which fails. In particular, the patientRecord
in the second instance is not getting populated properly.
What am I doing wrong here?