标签:style blog class code java color
无返回值方法,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.
RhinoMock中有参数方法和无返回值方法的使用,布布扣,bubuko.com
标签:style blog class code java color
原文地址:http://www.cnblogs.com/FEAUOR/p/3704530.html