Here's the class that I want to mock, massively truncated.
public class FooHandler
{
private FooInstance foo;
public void ConstructInstance(string fooSpecs)
{
foo = SomeMethod(fooSpecs);
}
public string GetSomeProperty()
{
return foo.SomeProperty();
}
}
In reality every method has a lot of internal logic. This is just the idea.
The code that I want to test requires a FooHandler, and it calls both methods, one after the other.
I want to mock my FooHandler to test whether my code calls it correctly.
var mockedFooHandler = new Mock<FooHandler>();
mockedFooHandler.Setup(x => x.ConstructInstance(EXAMPLE_FOO_SPEC));
mockedFooHandler.Setup(x => x.GetSomeProperty()).Returns(EXPECTED_PROPERTY);
Now, I want to tie these two setups together. I want to return different EXPECTED_PROPERTY's if the first method has been called with a different EXAMPLE_FOO_SPEC. The first method is void, and the second one takes no parameters. So I kind of want to set the internal state of the mocked object, the way the real one does. But the state is private.
Making several different mockedFooHandlers with their own programmed responses, to inject at different places, is not possible.
How should I go about that?