无返回值方法,RhinoMock的例子是这么做的:

demo.VoidThreeArgs(0, "", 0f);
LastCall.On(demo).Callback<int, string, float>(ThreeArgsAreSame);
mocks.Replay(demo);

 

无参数方法:

INameSource nameSource = (INameSource)mocks.StrictMock(typeof(INameSource));
Expect.Call(nameSource.CreateName(null,null)).IgnoreArguments().
        Do(new NameSourceDelegate(Formal));
mocks.ReplayAll();
string expected = "Hi, my name is Ayende Rahien";
string actual = new Speaker("Ayende", "Rahien", nameSource).Introduce();
Assert.Equal(expected, actual);

最需要的是忽略参数,IgnoreArguments()正可以达到目的

Do里面是委托的基类型,但是需要注意,方法的参数数目和委托的参数数目需要一致。

否则会报异常InvalidOperationException callback arguments didn`t match the method arguments.

相关文章:

  • 2022-12-23
  • 2021-08-05
  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2021-09-24
猜你喜欢
  • 2021-11-18
  • 2021-07-21
  • 2021-06-06
相关资源
相似解决方案