mercredi 23 décembre 2020

Testing with Xunit in EmailConfirmation

I recently started testing here. And then came the test for email confirmation. There is an async method, but the test for it seems a little tricky to me. Any ideas?

public async Task SendEmailAsync(string email, string subject, string message)
       {
           var emailMessage = new MimeMessage();

           emailMessage.From.Add(new MailboxAddress("Memory", "noreply@gmail.com"));
           emailMessage.To.Add(new MailboxAddress("", email));
           emailMessage.Subject = subject;
           emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html)
           {
               Text = message
           };

           using (var client = new SmtpClient())
           {
               await client.ConnectAsync("smtp.gmail.com", 587, false);
               await client.AuthenticateAsync("noreply@gmail.com", "password");
               await client.SendAsync(emailMessage);

               await client.DisconnectAsync(true);
           }
       }

Aucun commentaire:

Enregistrer un commentaire