tags:

views:

168

answers:

1

I get the following error on this line:

session.Expect(s => s.Add("string", null)).IgnoreArguments().Return(SaveMockUser());

cannot convert from 'void' to 'Rhino.Mocks.RhinoMocksExtensions.VoidType'

SaveMockUser is defined as follows

private void SaveMockUser()
    {
    }

What am I doing wrong?

+1  A: 

It's not possible to return a void type. Probably what you want to do is have another expectation that expects that SaveMockUser() is actually called or actually perform the action via a callback - i.e., when you see this function called, then do this.

session.Expect( s => s.Add("string", null) )
       .IgnoreArguments()
       .WhenCalled( x => SaveMockUser() );

or even better - use the new inline constraints

session.Expect( s => s.Add( Arg<string>.Is.Equal( "string" ), Arg<string>.Is.Anything ) )
       .WhenCalled( x => SaveMockUser() );
tvanfosson
Thanks, it works.I'm now trying to do session.Expect(s => s["User"]).Return(CreateUser()); but it just turns s to null.
HeavyWave