public void Smtp_All_Credentials_IsOverwritten_ButNoOther_WhenSet() { // ARRANGE var queueMock = new Mock<IMailQueue>(); queueMock.Setup(m => m.Enqueue(It.IsAny<Models.Mail>(), It.IsAny<object>())); var configMock = new Mock<IConfiguration>(); configMock.Setup(m => m.GetValue(MailSenderService.APP_KEY_OVERRIDE_SMTP_USER)) .Returns("a"); configMock.Setup(m => m.GetValue(MailSenderService.APP_KEY_OVERRIDE_SMTP_PASSWORD)) .Returns("c"); var smtpMock = new Mock<ISmtpClient>(); var subject = new MailSenderService(queueMock.Object, configMock.Object); var renderedMail = new RenderedMail(); renderedMail.Sender = new MailAddress("*****@*****.**"); renderedMail.Receiver = new MailAddress("*****@*****.**"); renderedMail.Subject = "foo"; renderedMail.Body = "htmlbody"; renderedMail.TextBody = "textbody"; // ACT var mailMessage = subject.ProcessInternal(renderedMail, smtpMock.Object); // ASSERT smtpMock.Verify(c => c.SetHost("example.org"), Times.Never); smtpMock.Verify(c => c.SetPort(1234), Times.Never); smtpMock.Verify(c => c.SetCredentials(null, "a", "c"), Times.Once); smtpMock.Verify(c => c.SetEnableSsl(It.IsAny<bool>()), Times.Never); }
public void Recipient_is_overridden_if_set() { // ARRANGE var queueMock = new Mock<IMailQueue>(); queueMock.Setup(m => m.Enqueue(It.IsAny<Models.Mail>(), It.IsAny<object>())); var configMock = new Mock<IConfiguration>(); configMock.Setup(m => m.GetValue(MailSenderService.APP_KEY_OVERRIDE_RECIPIENT)) .Returns("*****@*****.**"); var smtpMock = new Mock<ISmtpClient>(); var subject = new MailSenderService(queueMock.Object, configMock.Object); var renderedMail = new RenderedMail(); renderedMail.Sender = new MailAddress("*****@*****.**"); renderedMail.Receiver = new MailAddress("*****@*****.**"); renderedMail.Subject = "foo"; renderedMail.Body = "htmlbody"; renderedMail.TextBody = "textbody"; // ACT var mailMessage = subject.ProcessInternal(renderedMail, smtpMock.Object); // ASSERT smtpMock.Verify(c => c.Send( It.Is<MailMessage>(m => m.To.Count == 1 && m.To.First().Address == "*****@*****.**")), Times.Once); }