public async Task InvoiceEmailNotification_SentNotification()
        {
            //Arrange
            var language     = "default";
            var subject      = "Invoice for order - <strong>{{ customer_order.number }}</strong>";
            var body         = TestUtility.GetStringByPath($"Content\\{nameof(InvoiceEmailNotification)}.html");
            var notification = new InvoiceEmailNotification()
            {
                CustomerOrder = new CustomerOrder()
                {
                    Id            = "adsffads",
                    Number        = "123",
                    ShippingTotal = 123456.789m,
                    CreatedDate   = DateTime.Now,
                    Status        = "Paid",
                    Total         = 123456.789m,
                    FeeTotal      = 123456.789m,
                    SubTotal      = 123456.789m,
                    TaxTotal      = 123456.789m,
                    Currency      = "USD",
                    Items         = new[] { new LineItem
                                            {
                                                Name          = "some",
                                                Sku           = "sku",
                                                PlacedPrice   = 12345.6789m,
                                                Quantity      = 1,
                                                ExtendedPrice = 12345.6789m,
                                            } }
                },
                Templates = new List <NotificationTemplate>()
                {
                    new EmailNotificationTemplate()
                    {
                        Subject = subject,
                        Body    = body,
                    }
                }
            };
            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.SaveNotificationMessagesAsync(new NotificationMessage[] { message }));


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

            //Assert
            Assert.True(result.IsSuccess);
        }
Beispiel #2
0
        public async Task <IActionResult> GetInvoicePdf(string orderNumber)
        {
            var searchCriteria = AbstractTypeFactory <CustomerOrderSearchCriteria> .TryCreateInstance();

            searchCriteria.Number = orderNumber;
            searchCriteria.Take   = 1;

            var orders = await _searchService.SearchCustomerOrdersAsync(searchCriteria);

            var order = orders.Results.FirstOrDefault();

            if (order == null)
            {
                throw new InvalidOperationException($"Cannot find order with number {orderNumber}");
            }

            var notification = new InvoiceEmailNotification {
                CustomerOrder = order
            };
            await _notificationSender.SendNotificationAsync(notification, order.LanguageCode);

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

            message.LanguageCode = order.LanguageCode;
            var emailNotificationMessage = (EmailNotificationMessage)notification.ToMessage(message, _notificationTemplateRenderer);

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus },
                Objects        = { new ObjectSettings {
                                       PagesCount = true, HtmlContent = emailNotificationMessage.Body
                                   } }
            };
            var    converter = new SynchronizedConverter(new PdfTools());
            var    byteArray = converter.Convert(pdf);
            Stream stream    = new MemoryStream(byteArray);

            return(new FileStreamResult(stream, "application/pdf"));
        }