开发者

How do I use Rhino.Mocks.RhinoMocksExtensions.VoidType with lambda Expect?

开发者 https://www.devze.com 2022-12-08 09:48 出处:网络
I get the following error on this line: session.Expect(s => s.Add(\"string\", null)).IgnoreArguments().Return(SaveMockUser());

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() );
0

精彩评论

暂无评论...
验证码 换一张
取 消