Mock a void method which change the input value

Posted by Kar on Stack Overflow See other posts from Stack Overflow or by Kar
Published on 2010-04-19T11:29:34Z Indexed on 2010/04/19 11:33 UTC
Read the original article Hit count: 252

Hi,

How could I mock a void method with parameters and change the value parameters?

My void method looks like this:

public interface IFoo 
{
void GetValue(int x, object y)     
// takes x and do something then access another class to get the value of y
}

I prepared a delegate class:

private delegate void GetValueDelegate(int x, object y);
private void GetValue(int x, object y)
{ // process x
  // prepare a new object obj
  if (y == null) y = new Object();
  if (//some checks) 
     y = obj;
}

I wrote something like this:

Expect.Call(delegate {x.GetValue(5, null);}).Do (new GetValueDelegate(GetValue)).IgnoreArguments().Repeat.Any();

But seems like it's not working. Any clue on what could be wrong?

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about rhino-mocks