I am trying to check the logic from some existing classes. It is currently not possible to regroup classes because they are very complex and produced.
What I want to do is create a mock object and test a method that internally calls another method that is very difficult to make fun of.
So, I want to just set the behavior to call the secondary method.
But when I tweak the behavior of the method, the method code gets called and fails.
Am I missing something or is it just impossible to verify without re-factoring the class?
I tried all different layouts (Strick, Stub, Dynamic, Partial ect.), But all of them end up calling the method when I try to customize the behavior.
using System;
using MbUnit.Framework;
using Rhino.Mocks;
namespace MMBusinessObjects.Tests
{
[TestFixture]
public class PartialMockExampleFixture
{
[Test]
public void Simple_Partial_Mock_Test()
{
const string param = "anything";
MockRepository mocks = new MockRepository();
var mockTestClass = mocks.StrictMock<TestClass>();
Expect.Call(mockTestClass.MethodToMock(param)).Return(true);
mocks.ReplayAll();
Assert.IsTrue(mockTestClass.MethodIWantToTest(param));
}
public class TestClass
{
public bool MethodToMock(string param)
{
throw new NotImplementedException();
}
public bool MethodIWantToTest(string param)
{
if( MethodToMock(param) )
{
}
return true;
}
}
}
}