public async Task ShouldSendEmail() { //Arrange Moq.Mock <ISmtpClient> smtpClientMock = new Mock <ISmtpClient>(); Mock <IOptions <EmailSettings> > optionMock = new Mock <IOptions <EmailSettings> >(); EmailSettings emailSettings = new EmailSettings() { UserName = "******", Password = "******", From = "*****@*****.**", Host = "aaa", Port = 234 }; optionMock.SetupGet(x => x.Value).Returns(emailSettings); smtpClientMock.Setup(x => x.Send(It.IsAny <MailMessage>(), emailSettings)); EmailSender.EmailSender emailSender = new EmailSender.EmailSender(optionMock.Object, smtpClientMock.Object); //Act await emailSender.SendEmailAsync("*****@*****.**", "subject", "message"); //Assert smtpClientMock.Verify(x => x.Send(It.IsAny <MailMessage>(), emailSettings), Times.Once); }
public HomeController(ILogger <HomeController> logger, EmailConfiguration emailConfig) { _logger = logger; _emailSender = new EmailSender.EmailSender(emailConfig); }