Exemple #1
0
        public async Task OrderSendEmailNotification_SentNotification()
        {
            //Arrange
            var language = "en-US";
            var subject  = "Your order was sent";
            var body     = "Your order <strong>{{ customer_order.number}}</strong> was sent.<br> Number of sent parcels - " +
                           "<strong>{{ customer_order.shipments | size}}</strong>.<br> Parcels tracking numbers:<br> {% for shipment in customer_order.shipments %} " +
                           "<br><strong>{{ shipment.number}}</strong> {% endfor %}<br><br>Sent date - <strong>{{ customer_order.modified_date }}</strong>.";
            var notification = new OrderSentEmailNotification()
            {
                CustomerOrder = new CustomerOrder()
                {
                    Number = "123"
                    ,
                    Shipments = new[] { new Shipment()
                                        {
                                            Number = "some_number"
                                        } }
                    ,
                    ModifiedDate = DateTime.Now
                },
                Templates = new List <NotificationTemplate>()
                {
                    new EmailNotificationTemplate()
                    {
                        Subject      = subject,
                        Body         = body,
                        LanguageCode = "en-US"
                    }
                },
                LanguageCode = language,
                IsActive     = true
            };
            var date    = new DateTime(2018, 02, 20, 10, 00, 00);
            var message = new EmailNotificationMessage()
            {
                Id       = "1",
                From     = "*****@*****.**",
                To       = "*****@*****.**",
                Subject  = subject,
                Body     = body,
                SendDate = date
            };

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

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

            //Assert
            Assert.True(result.IsSuccess);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }