Can I update setup of frozen mock repository instance in my fixture?
I have code like this:
private IFixture fixture;
private Asset asset;
private Mock<IAssetRepository> repository;
[SetUp]
public void SetUp()
{
fixture = new Fixture();
repository = fixture.Freeze<Mock<IAssetRepository>>();
asset = new AssetBuilder().With3ConsecutiveWorkMovements().Build();
//Default behaviour I need to provide the object I am using in my
tests
repository.Setup(r => r.Find(It.IsAny<int>())).Returns(() => asset);
}
[Test]
public void Handle_CommandPassedWithAssetId_AssetFindCalledCorrectly()
{
var command = fixture.Build<UpdateAssetMovementCommand>();
//Trying to change the behaviour of the find method configured in
Test Setup
//This doesn't replace the Find behaviour previously configured in
setup
//How can I tell AutoFixture to use a different
Mock<IAssetRepository>>()
//So I can redefine the setup of find method
repository.Setup(r => r.Find(It.Is<int>(a => a ==
command.AssetId))).Returns(() => asset).Verifiable();
var sut = fixture.Create<UpdateAssetMovementCommandHandler>();
sut.Handle(command);
repository.VerifyAll();
}
repository.VerifyAll() fails as it says can't verify It.IsAny was called
with error
Moq.MockVerificationException : The following setups were not matched:
IAssetRepository r => r.Find(It.IsAny())
What I want to do is provide a differently configured Mock in this one
test. All the other 10 tests I want to use the repository as configured in
the setup.
No comments:
Post a Comment