Hi! I am trying to pass a fake through some constructor injection and wire it up in each test. When I run this it doesn't seem to respect the fake when it is wrapped inside an action. Here's the test class:
[TestClass, Isolated]
public class SystemTypeServiceTests
{
SystemTypeService service;
SystemTypeRepository fakeSystemTypeRepository = Isolate.Fake.Instance<SystemTypeRepository>(Members.MustSpecifyReturnValues);
public SystemTypeServiceTests()
{
Isolate.Fake.StaticMethods(typeof(UnitOfWork));
Isolate.WhenCalled(() => UnitOfWork.Do(null)).DoInstead(context =>
{
var action = context.Parameters[0] as Action;
action.Invoke();
});
service = new SystemTypeService(fakeSystemTypeRepository);
}
[TestMethod, Isolated]
public void Retrieve_ValidCode_ReturnsObject()
{
string code = "25";
var expected = new SystemType { Id = 1L, ClientId = 25L, Code = "25", Description = "Test Type" };
Isolate.WhenCalled(() => fakeSystemTypeRepository.RetrieveByCode(code)).WillReturn(expected);
var actual = service.Retrieve(code);
Assert.AreEqual(expected, actual);
}
}
Here's the method under test:
public SystemType Retrieve(string code)
{
Check.ForPatternMismatch(code, SystemTypeRepository.CodeFormat, "code");
SystemType result = null;
UnitOfWork.Do(() =>
{
result = repository.RetrieveByCode(code);
});
return result;
}
When I comment out the UnitOfWork.Do component it returns properly with the fake, but when I put it back in it flakes.
Thoughts?