失败时我在我的NUnit测试下面的代码:起订量VerifySet使用接口的属性设置
[Test]
public void SmtpSend_UsingSystemCredentials_SetsSmtpClientCredentials()
{
const string smtppwd = "smtppwd";
const string smtpuser = "smtpuser";
const string smtphost = "smtphost";
const int smtpport = 333;
_emailManager.Setup(x => x.ValidateSmtpSettings()).Returns(true);
_emailTransportConfig.SetupGet(x => x.SmtpPassword).Returns(smtppwd);
_emailTransportConfig.SetupGet(x => x.SmtpUsername).Returns(smtpuser);
_emailTransportConfig.SetupGet(x => x.SmtpHost).Returns(smtphost);
_emailTransportConfig.SetupGet(x => x.SmtpPort).Returns(smtpport);
_smtpClient.SetupAllProperties();
_smtpHandler.Send(null, "[email protected]", "[email protected]", "subject", "body", true);
_smtpClient.VerifySet(x => x.Port = smtpport);
_smtpClient.VerifySet(x => x.Host = smtphost);
// Todo Why is this not working?
_smtpClient.VerifySet(x => x.Credentials = new NetworkCredential(smtpuser, smtppwd));
}
我可以看到代码落入这样的功能:
private void SetSystemSmtpAccountSettings()
{
_smtpClient.Credentials = new NetworkCredential
{
UserName = _emailTransportConfig.SmtpUsername,
Password = _emailTransportConfig.SmtpPassword
};
_smtpClient.Host = _emailTransportConfig.SmtpHost;
_smtpClient.Port = _emailTransportConfig.SmtpPort;
}
但我有什么不明白为什么VerifySet调用失败。
这工作完美,谢谢! – jaffa