Ejemplo n.º 1
0
        [Fact]//(Skip = "Test to see if mail is inboxed")]
        public async Task EmailSenderShouldSendWithTemplate()
        {
            var factory = new SendGridMailFactory(new OptionsWrapper <MailOptions>(new MailOptions()
            {
                FromAddress     = "*****@*****.**",
                FromDisplayName = "Test",
                Templates       = new List <TemplateItem>()
                {
                    new TemplateItem()
                    {
                        Id   = "7cc262f1-48eb-4948-a22c-16cb844d4540",
                        Type = NotificationType.ResetPassword
                    }
                }
            }));
            var sender = new SimpleSendGridEmailSender(new OptionsWrapper <MailOptions>(new MailOptions()
            {
                ApiKey          = "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",
                FromAddress     = "*****@*****.**",
                FromDisplayName = "Integration Test"
            }), factory);

            var message = NotificationRequestModel.Email("*****@*****.**", "subject", "message");

            message.AddToken("-name-", "John Doe");
            message.AddToken("-city-", "Denver");
            message.AddToken("subject", "SendGrid Subject");

            await sender.SendEmailAsync(message, NotificationType.ResetPassword);
        }
Ejemplo n.º 2
0
        public void EmailSenderShouldFailWithInvalidApiKey()
        {
            var factory = Substitute.For <ISendGridMalFactory>();
            var sender  = new SimpleSendGridEmailSender(new OptionsWrapper <MailOptions>(new MailOptions()
            {
                ApiKey          = "xxx",
                FromAddress     = "*****@*****.**",
                FromDisplayName = "Integration Test"
            }), factory);

            factory.CreateMessage(Arg.Any <NotificationType>(), Arg.Any <NotificationRequestModel>()).Returns(c =>
            {
                var mailMessage = new SendGridMessage();
                mailMessage.AddTo("*****@*****.**");
                mailMessage.From        = new EmailAddress("*****@*****.**", "Integration Test");
                mailMessage.Subject     = "Test Subject";
                mailMessage.HtmlContent = "Test Body";
                return(mailMessage);
            });

            Func <Task> act = async() =>
            {
                await sender.SendEmailAsync(NotificationRequestModel.Email("*****@*****.**", "test subject", "test body"));
            };

            act.Should().Throw <InvalidOperationException>();
        }
Ejemplo n.º 3
0
        public void EmailSenderShouldThrowWhenOptionsNotConfigured()
        {
            Func <Task> act = async() =>
            {
                var sender = new SimpleSendGridEmailSender(new OptionsWrapper <MailOptions>(new MailOptions()), Substitute.For <ISendGridMalFactory>());
                await sender.SendEmailAsync(NotificationRequestModel.Email("*****@*****.**", "test subject", "test body"));
            };

            act.Should().Throw <ArgumentException>();
        }
Ejemplo n.º 4
0
        [Fact]//(Skip = "Test to see if mail is inboxed")]
        public async Task EmailSenderShouldSendNotificationWithSendGrid()
        {
            var factory = Substitute.For <ISendGridMalFactory>();
            var sender  = new SimpleSendGridEmailSender(new OptionsWrapper <MailOptions>(new MailOptions()
            {
                ApiKey          = "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",
                FromAddress     = "*****@*****.**",
                FromDisplayName = "Integration Test"
            }), factory);

            factory.CreateMessage(Arg.Any <NotificationType>(), Arg.Any <NotificationRequestModel>()).Returns(c =>
            {
                var mailMessage = new SendGridMessage();
                mailMessage.AddTo("*****@*****.**");
                mailMessage.From        = new EmailAddress("*****@*****.**", "Integration Test");
                mailMessage.Subject     = "Test Without Template";
                mailMessage.HtmlContent = "Test Body";
                return(mailMessage);
            });
            await sender.SendEmailAsync(NotificationRequestModel.Email("*****@*****.**", "test subject", "test body"));
        }