在替代配置.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