在替代配置.Add
方法删除参数。
下面的示例将编译并没有参数
为无效方法工作
var fakeService = Substitute.For<IYourService>();
fakeService.When(fake => fake.Add()).Do(call => { throw new ArgumentException(); });
Action action =() => fakeService.Add();
action.ShouldThrow<ArgumentException>(); // Pass
而且相同所示将编译用于与参数空隙方法文档
var fakeService = Substitute.For<IYourService>();
fakeService.When(fake => fake.Add(2, 2)).Do(call => { throw new ArgumentException(); });
Action action =() => fakeService.Add(2, 2);
action.ShouldThrow<ArgumentException>(); // Pass
假设该接口是
public interface IYourService
{
void Add();
void Add(int first, int second);
}
删除参数,因为你的方法不会让他们 – Fabio