Ejemplo n.º 1
0
        public async Task SendGridNotificationMessageSender_SuccessSentMessage()
        {
            //Arrange
            var notification = GetNotification();

            var message = AbstractTypeFactory <NotificationMessage> .TryCreateInstance($"{notification.Kind}Message") as EmailNotificationMessage;

            message.From    = Configuration["SendgridSender"];
            message.To      = Configuration["SendgridSender"];
            message.Subject = "subject";
            message.Body    = "Message";

            _messageServiceMock.Setup(x => x.GetNotificationsMessageByIds(It.IsAny <string[]>()))
            .ReturnsAsync(new[] { message });

            var sendGridSendingOptionsMock = new Mock <IOptions <SendGridSenderOptions> >();

            sendGridSendingOptionsMock.Setup(opt => opt.Value).Returns(new SendGridSenderOptions {
                ApiKey = Configuration["SendgridApiKey"]
            });
            _messageSender = new SendGridEmailNotificationMessageSender(sendGridSendingOptionsMock.Object);

            var notificationSender = GetNotificationSender();

            //Act
            var result = await notificationSender.SendNotificationAsync(notification);

            //Assert
            Assert.True(result.IsSuccess);
        }
Ejemplo n.º 2
0
        public async Task SmtpEmailNotificationMessageSender_FailSendMessage()
        {
            //Arrange
            var notification = GetNotification();

            _emailSendingOptions.Password = "******";
            _emailSendingOptionsMock.Setup(opt => opt.Value).Returns(_emailSendingOptions);
            _messageSender = new SmtpEmailNotificationMessageSender(_emailSendingOptionsMock.Object);

            var notificationSender = GetNotificationSender();

            //Act
            var result = await notificationSender.SendNotificationAsync(notification);

            //Assert
            Assert.False(result.IsSuccess);
        }
Ejemplo n.º 3
0
        public async Task SmtpEmailNotificationMessageSender_SuccessSentMessage()
        {
            //Arrange
            string number       = Guid.NewGuid().ToString();
            string subject      = "Order #{{customer_order.number}}";
            string body         = "You have order #{{customer_order.number}}";
            var    notification = new OrderSentEmailNotification()
            {
                CustomerOrder = new CustomerOrder()
                {
                    Number = number
                },
                From      = "*****@*****.**",
                To        = "*****@*****.**",
                Templates = new List <NotificationTemplate>()
                {
                    new EmailNotificationTemplate()
                    {
                        Subject = subject,
                        Body    = body,
                    }
                },
                TenantIdentity = new TenantIdentity(null, null)
            };

            _serviceMock.Setup(serv => serv.GetByTypeAsync(nameof(OrderSentEmailNotification), null, null, null)).ReturnsAsync(notification);


            _emailSendingOptionsMock.Setup(opt => opt.Value).Returns(_emailSendingOptions);
            _messageSender = new SmtpEmailNotificationMessageSender(_emailSendingOptionsMock.Object);
            _notificationMessageSenderProviderFactory = new NotificationMessageSenderProviderFactory(new List <INotificationMessageSender>()
            {
                _messageSender
            });
            _notificationMessageSenderProviderFactory.RegisterSenderForType <EmailNotification, SmtpEmailNotificationMessageSender>();
            _notificationSender = new NotificationSender(_templateRender, _messageServiceMock.Object, _logNotificationSenderMock.Object, _notificationMessageSenderProviderFactory);

            //Act
            var result = await _notificationSender.SendNotificationAsync(notification, null);

            //Assert
            Assert.True(result.IsSuccess);
        }
Ejemplo n.º 4
0
        public async Task SmtpEmailNotificationMessageSender_FailSendMessage()
        {
            //Arrange
            string language     = null;
            var    number       = Guid.NewGuid().ToString();
            var    subject      = "Order #{{customer_order.number}}";
            var    body         = "You have order #{{customer_order.number}}";
            var    notification = new OrderSentEmailNotification()
            {
                CustomerOrder = new CustomerOrder()
                {
                    Number = number
                },
                From      = "*****@*****.**",
                To        = "*****@*****.**",
                Templates = new List <NotificationTemplate>()
                {
                    new EmailNotificationTemplate()
                    {
                        Subject = subject,
                        Body    = body,
                    }
                }
            };

            _serviceMock.Setup(serv => serv.GetByTypeAsync(nameof(OrderSentEmailNotification), null, null, null)).ReturnsAsync(notification);

            _emailSendingOptions.Password = "******";
            _emailSendingOptionsMock.Setup(opt => opt.Value).Returns(_emailSendingOptions);
            _messageSender      = new SmtpEmailNotificationMessageSender(_emailSendingOptionsMock.Object);
            _notificationSender = new NotificationSender(_templateRender, _messageServiceMock.Object, _logNotificationSenderMock.Object,
                                                         _notificationMessageSenderProviderFactory);

            //Act
            var result = await _notificationSender.SendNotificationAsync(notification, language);

            //Assert
            Assert.False(result.IsSuccess);
        }
Ejemplo n.º 5
0
        public async Task SmtpEmailNotificationMessageSender_SuccessSentMessage()
        {
            //Arrange
            var notification = GetNotification();

            var message = AbstractTypeFactory <NotificationMessage> .TryCreateInstance($"{notification.Kind}Message") as EmailNotificationMessage;

            message.From = Configuration["SenderEmail"];
            message.To   = Configuration["SenderEmail"];

            _messageServiceMock.Setup(x => x.GetNotificationsMessageByIds(It.IsAny <string[]>()))
            .ReturnsAsync(new[] { message });

            _messageSender = new SmtpEmailNotificationMessageSender(_emailSendingOptionsMock.Object);

            var notificationSender = GetNotificationSender();

            //Act
            var result = await notificationSender.SendNotificationAsync(notification);

            //Assert
            Assert.True(result.IsSuccess);
        }
Ejemplo n.º 6
0
        public async Task TwilioNotificationMessageSender_SuccessSentMessage()
        {
            //Arrange
            var notification = GetSmsNotification();
            var message      = AbstractTypeFactory <NotificationMessage> .TryCreateInstance($"{notification.Kind}Message") as SmsNotificationMessage;

            await notification.ToMessageAsync(message, _templateRender);

            message.Number = Configuration["WwilioReciever"];

            var accountId       = Configuration["TwilioAccountSID"];
            var accountPassword = Configuration["TwilioAuthToken"];
            var defaultSender   = Configuration["TwilioDefaultSender"];

            var twilioSendingOptionsMock = new Mock <IOptions <TwilioSenderOptions> >();

            twilioSendingOptionsMock.Setup(opt => opt.Value).Returns(new TwilioSenderOptions {
                AccountId = accountId, AccountPassword = accountPassword
            });
            var smsSendingOptions = new Mock <IOptions <SmsSendingOptions> >();

            smsSendingOptions.Setup(opt => opt.Value).Returns(new SmsSendingOptions {
                SmsDefaultSender = defaultSender
            });
            _messageSender = new TwilioSmsNotificationMessageSender(twilioSendingOptionsMock.Object, smsSendingOptions.Object);
            _messageServiceMock.Setup(x => x.GetNotificationsMessageByIds(It.IsAny <string[]>()))
            .ReturnsAsync(new[] { message });

            var notificationSender = GetNotificationSender();

            //Act
            var result = await notificationSender.SendNotificationAsync(notification);

            //Assert
            Assert.True(result.IsSuccess);
        }