How to raise event value with Rhino Mocks with ref bool parameter

I am trying to write a test that covers my error handling in a specific class. This class listens for the Error event with the following signature:

OnError(int ErrorNumber, string ErrorText, ref bool retry) 

The problem is the ref bool variable at the end. I use Rhino Mocks to create a mock interface for testing, and when I try to raise an error using the following:

 bool retry = false; AdapterMock.Raise(x => x.Error += null, 0, "0", ref retry); 

It will not even compile, telling me that it cannot convert from ref bool to Object.

If I changed my signature to:

 bool retry = false; AdapterMock.Raise(x => x.Error += null, 0, "0", retry); 

I compile fine, but the test does not work with System.InvalidOperationException: parameter # 3 is System.Boolean, but should be System.Boolean &

I am pulling my hair on it, how to properly raise this event in my layout?

+4
source share
1 answer

Try:

 AdapterMock.Raise( x=> x.Error += null, Arg<int>.Is.Equal(0), Arg<string>.Is.Equal("0"), Arg.Ref(ref Is.Equal(retry))); 
0
source

All Articles