У меня есть следующий код в моем тесте Nunit:
[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, "from@test.com", "to@test.com", "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.