RhinoMocks: how to test if method was called when using PartialMock
Posted
by epitka
on Stack Overflow
See other posts from Stack Overflow
or by epitka
Published on 2010-05-07T14:01:43Z
Indexed on
2010/05/15
23:40 UTC
Read the original article
Hit count: 256
rhino-mocks
I have a clas that is something like this
public class MyClass
{
public virtual string MethodA(Command cmd)
{ //some code here}
public void MethodB(SomeType obj)
{
// do some work
MethodA(command);
}
}
I mocked MyClass as PartialMock (mocks.PartialMock<MyClass>
) and I setup expectation for MethodA
var cmd = new Command();
//set the cmd to expected state
Expect.Call(MyClass.MethodA(cmd)).Repeat.Once();
Problem is that MethodB calls actual implementation of MethodA instead of mocking it up. I must be doing something wrong (not very experienced with RhinoMocks). How do I force it to mock MetdhodA?
Here is the actual code:
var cmd = new SetBaseProductCoInsuranceCommand();
cmd.BaseProduct = planBaseProduct;
var insuredType = mocks.DynamicMock<InsuredType>();
Expect.Call(insuredType.Code).Return(InsuredTypeCode.AllInsureds);
cmd.Values.Add(new SetBaseProductCoInsuranceCommand.CoInsuranceValues()
{
CoInsurancePercent = 0,
InsuredType = insuredType,
PolicySupplierType = ppProvider
});
Expect.Call(() => service.SetCoInsurancePercentages(cmd)).Repeat.Once();
mocks.ReplayAll();
//act
service.DefaultCoInsurancesFor(planBaseProduct);
//assert
service.AssertWasCalled(x => x.SetCoInsurancePercentages(cmd),x=>x.Repeat.Once());
© Stack Overflow or respective owner