I have a really simple class with two methods; One that will be called, and another that he will call. The idea is to call the OuterMockMethod method, but mock InnerMockMethod. Right now, I can only make fun of the OuterMockMethod method.
public class MockClass : IMockInterface { public virtual MockClass InnerMockMethod() { MockClass returnValue; returnValue = new MockClass(); returnValue.SomeMessage = "Not mocked"; return returnValue; } public virtual MockClass OuterMockMethod() { MockClass mock; mock = new MockClass(); return mock.MockedMethod(); } }
Now this works, but this is not the method I want to make fun of:
public void MockTest_Internal() { MockClass returnedClass; MockClass mockProvider; mockProvider = repository.StrictMock<MockClass>(); mockProvider.Expect(item => item.OuterMockMethod()) .Return(new MockClass { SomeMessage = "Mocked" }); repository.Replay(mockProvider); returnedClass = mockProvider.OuterMockMethod(); Assert.IsTrue(returnedClass.SomeMessage == "Mocked"); }
As you can see, it calls OuterMockMethod, which he likes, but I don't want that. I want to mock InnerMockMethod so that when I call OuterMockMethod, it returns what I want.
public void MockTest_Internal() { MockClass returnedClass; MockClass mockProvider; mockProvider = repository.StrictMock<MockClass>(); mockProvider.Expect(item => item.InnerMockMethod()) .Return(new MockClass { SomeMessage = "Mocked" }); repository.Replay(mockProvider); returnedClass = mockProvider.OuterMockMethod();
source share