失敗時我在我的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