I have these mocks:
_processWrapperMock = new Mock<IProcessWrapper>(MockBehavior.Strict);
_processStartInfoMock = new Mock<IProcessStartInfo>();
and a setup for the Start() method:
_processWrapperMock.Setup(m => m.Start(_processStartInfoMock.Object))
.Returns(new Process());
and my _processWrapperMock instance is passed to the constructor for the object which contains the method I’m testing.
var wrapper = new WrapperClassImTesting(_processWrapperMock.Object);
I then execute the method which I’m testing:
byte[] output = wrapper.MethodImTesting(someParams);
Within MethodImTesting, the Start method of the _processWrapperMock is executed however my previous setup doesn’t seem to be taken into account. The error I get is at the line:
using (var process = _processWrapper.Start(processStartInfo))
throwing:
Mock Exception was unhandled by user code
IProcessWrapper.Start(GraphVizWrapper.ProcessStartInfo) invocation
failed with mock behavior Strict. All invocations on the mock must
have a corresponding setup.
What am I doing / not doing, that I need to for this to work as I expect?
Why bother creating a mock at all … can’t you just do this?
Are you sure there isn’t some other method or property that’s being accessed?