NSubstitute 擴充方法看起來不支援阿
stackoverflow 有人回答 免錢的套件是不支援擴充方法(靜態)的
看起來 付費 JustMock 可以支援擴充方法(靜態)的
public interface ICalculator
{
}
public static class ICalculatorExtension
{
public static int Clear(this ICalculator calculator, int level)
{
return level;
}
}
public class MyDemo
{
private readonly ICalculator _calculator;
public MyDemo(ICalculator calculator)
{
this._calculator = calculator;
}
public void Action1(bool clearFlag)
{
if (clearFlag == true)
{
this._calculator.Clear(7);
}
}
}
[TestMethod]
public void test1()
{
//arrange
//NSubstitute會產生一個ICalculator 假的實體出來
ICalculator calculator = Substitute.For<ICalculator>();
//calculator.Add("A").Returns("A");
var myDemo = new MyDemo(calculator);
//act
myDemo.Action1(true);
//assert 以下都不會報錯
calculator.DidNotReceive().Clear(7);
calculator.Received(5).Clear(7);
calculator.Received(1).Clear(1);
}
如果內容有誤請多鞭策謝謝