How do I use Rhino.Mocks.RhinoMocksExtensions.VoidType with lambda Expect?
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?
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() );
精彩评论