Ah, ok I have solved my own problem within moments of posting :)
The last test should read:
[Test]
public void Test_MethodB_ShouldUseMethodA()
{
//---------------Set up test pack-------------------
const string otherReturnValue = "Hello Universe";
MockRepository mockRepository = new MockRepository();
MyClass myClass = mockRepository.PartialMock<MyClass>();
myClass.Stub(t => t.MethodA()).Return(otherReturnValue);
myClass.Replay();
//---------------Assert Precondition----------------
Assert.AreEqual(otherReturnValue, myClass.MethodA());
//---------------Execute Test ----------------------
string returnedString = myClass.MethodB();
//---------------Test Result -----------------------
string expected = string.Format("'{0}'", otherReturnValue);
Assert.AreEqual(expected, returnedString);
}
I was missing the "myclass.Replay();" call.
I think that the basis for my mistake is that I usually use the AAA
syntax and stubs, and for Partial mocks I could not use this in the
normal way.
Is there any reason why there is no 'Partial Stub'?
All I would probably have needed was a static method on MockRepository
called something like "GeneratePartial<T>":
public static T GeneratePartial<T>(params object[]
argumentsForConstructor)
where T : class
{
MockRepository repository = new MockRepository();
T obj = repository.PartialMock<T>(argumentsForConstructor);
repository.Replay(obj);
return obj;