public void SendAdminEmails_When_executed_x_emails_sent(bool isAthlete, bool isVolunteer, int expected) { LoadEmails(); _mockIOrganizationRepository = new Mock <IOrganizationRepository>(); _worker = new EmailWorker(_mockIOrganizationRepository.Object, _mockEmailRepository.Object); _mockIOrganizationRepository.Setup(repository => repository.GetEmails(true, false)).ReturnsAsync(_volunteerList); _mockIOrganizationRepository.Setup(repository => repository.GetEmails(false, true)).ReturnsAsync(_athleteList); _mockIOrganizationRepository.Setup(repository => repository.GetEmails(true, true)).ReturnsAsync(_jointList); const string fromEmail = "*****@*****.**"; const string subject = "Sending with SendGrid is Fun"; const string plainTextContent = "and easy to do anywhere, even with C#"; const string htmlContent = "<br>Hi {{deacon}}<br><br> Just a reminder you are the Deacon on Duty for {{month}},<br><br> You will responsible to lock up the church on Sundays after worship. If you are not going to be there then it is your responsibility to get another Deacon to close up for you. You are responsible for taking out the trash. Also make sure the offering baskets are out for the next week.<br><br> If you are going to miss more than one Sunday in {{month}} please change with another deacon"; OrganizationEmailDto message = new OrganizationEmailDto { From = fromEmail, HtmlContent = htmlContent, PlainTextContent = plainTextContent, Subject = subject, IsVolunteer = isVolunteer, IsAthlete = isAthlete, }; var actual = _worker.SendAdminEmails(message); _mockEmailRepository.Verify(mock => mock.SendEmailString(fromEmail, It.IsAny <string>(), subject, plainTextContent, htmlContent), Times.Exactly(expected)); Assert.Equal(expected, actual.Result); }
public async Task <int> SendAdminEmails(OrganizationEmailDto message) { var emailList = await GetEmailsForOrganization(message.IsVolunteer, message.IsAthlete); if (message.IsTesting) { var testEmails = new List <string> { "*****@*****.**", "*****@*****.**", "*****@*****.**" }; emailList = testEmails; } emailList.Add(message.From); emailList = emailList.ConvertAll(d => d.ToLower()); emailList = emailList.Distinct().ToList(); await SendEmailsAsync(emailList, message.From, message.Subject, message.PlainTextContent, message.HtmlContent); return(emailList.Count); }