我知道测试非公共成员被认为是不好的,但为什么这不起作用?它抛出ArgumentException
消息:成员Connect
不存在
public class FtpHelper : IFtpHelper
{
public FtpHelper(ISignalRLogger signalRLogger, IDirectoryWrap directoryWrap = null) {
... some code
}
protected virtual IFtpClient Connect(string ftpPath) {
... some code
}
}
public class TestFtpHelper
{
[Fact]
public void Calls_connect(){
var signalrMq = new Mock<ISignalRLogger>();
var clientMq = new Mock<FtpHelper>(
MockBehavior.Strict, new { signalRLogger = signalrMq.Object });
clientMq.Protected().Setup<IFtpClient>("Connect",new { ftpPath = ""})
.Returns(It.IsAny<IFtpClient>()); // That doesn't work
}
}
UPD:哦,我注意到,即使在它初始化的最后一行之前clientMq
,我尝试使用clientMq.Object
它也会抛出异常,并显示以下消息:在模拟类型上找不到给定参数的匹配构造函数。我想这与那个带有默认值的奇怪构造函数有关