I've got a function that returns a value that is computed by several private functions in the same class (obviously). I'd like to mock the return values of the private functions so that they don't get called for real.
FirstlyHow might I use Reflective Mocks to do this? The obvious way:
Mock m = MockManager.Mock(typeof(MyClass));
m.ExpectAndReturn("PrivateFunction", host);
m.ExpectGet("PrivateProperty", port);
MyClass g = new MyClass();
g.FooBar();
results in a call to "MyClass.Foo()", which kills the test because it throws an exception under these conditions (which is why I want to Mock it).
Secondly, How might I use Natural Mocks to do this? If I do this:
MyClass g = new MyClass();
using (RecordExpectations r = RecorderManager.StartRecording())
{
g.PrivateFunction();
}
it won't compile because PrivateFunction is a private function. If, instead of "g" I use a private accessor, TypeMock looks for the private accessor type, not the MyClass type (at least according to the Trace).
Thirdly, Is there a way to use private accessors to Mock the accessed-class's private members?
Thanks!
________
Ultimate fighter