コード例 #1
0
        /// <summary>
        /// Trigger call to notifify the monitor of a change
        /// </summary>
        /// <param name="value">
        /// The model to be used by the monitor
        /// </param>
        public override void OnNext(IShipment value)
        {
            if (!Messages.Any())
            {
                return;
            }

            var formatter = PatternReplaceFormatter.GetPatternReplaceFormatter();

            // Add the replaceable patterns from the invoice
            formatter.AddOrUpdateReplaceablePattern(value.ReplaceablePatterns());

            foreach (var message in Messages)
            {
                if (message.SendToCustomer)
                {
                    // add the additional contacts to the recipients list
                    if (!message.Recipients.EndsWith(";"))
                    {
                        message.Recipients += ";";
                    }

                    if (message.Recipients[0] == ';')
                    {
                        message.Recipients = message.Recipients.TrimStart(';');
                    }

                    message.Recipients = string.Format("{0}{1}", message.Recipients, string.Join(";", value.Email));
                }

                // send the message
                NotificationContext.Send(message, formatter);
            }
        }
コード例 #2
0
        public void Can_Get_A_PatternReplaceFormatter_Populated_With_Configuration_Patterns()
        {
            //// Arrange

            //// Act
            var formatter = (PatternReplaceFormatter)PatternReplaceFormatter.GetPatternReplaceFormatter();

            //// Assert
            Assert.IsTrue(formatter.Patterns.Any());
        }
コード例 #3
0
        /// <summary>
        /// Trigger call to notify the monitor of a change
        /// </summary>
        /// <param name="value">
        /// The model to be used by the monitor
        /// </param>
        public override void OnNext(IPaymentResultMonitorModel value)
        {
            if (!value.PaymentSuccess)
            {
                return;
            }

            if (!Messages.Any())
            {
                return;
            }

            var formatter = PatternReplaceFormatter.GetPatternReplaceFormatter();

            // Add the replaceable patterns from the invoice
            formatter.AddOrUpdateReplaceablePattern(value.Invoice.ReplaceablePatterns(value.CurrencySymbol));

            if (value.Payment != null)
            {
                formatter.AddOrUpdateReplaceablePattern(value.Payment.ReplaceablePatterns(value.CurrencySymbol));
            }

            if (value.Shipment != null)
            {
                formatter.AddOrUpdateReplaceablePattern(value.Shipment.ReplaceablePatterns(value.CurrencySymbol));
            }

            if (value.ShipMethod != null)
            {
                formatter.AddOrUpdateReplaceablePattern(value.ShipMethod.ReplaceablePatterns());
            }

            foreach (var message in Messages)
            {
                if (value.Contacts.Any() && message.SendToCustomer)
                {
                    // add the additional contacts to the recipients list
                    if (!message.Recipients.EndsWith(";"))
                    {
                        message.Recipients += ";";
                    }

                    if (message.Recipients[0] == ';')
                    {
                        message.Recipients = message.Recipients.TrimStart(';');
                    }

                    message.Recipients = string.Format("{0}{1}", message.Recipients, string.Join(";", value.Contacts));
                }

                // send the message
                NotificationContext.Send(message, formatter);
            }
        }
コード例 #4
0
        public void Can_Format_A_Message()
        {
            //// Arrange
            var formatter = PatternReplaceFormatter.GetPatternReplaceFormatter();

            formatter.AddOrUpdateReplaceablePattern(_invoice.ReplaceablePatterns());

            //// Act

            var text = formatter.Format(_message);

            Console.Write(text);

            //// Assert
            Assert.IsTrue(text.Contains("Mindfly"));
        }
コード例 #5
0
        public void Can_Update_PatternReplaceFormatter_Default_Data_With_Invoice_Data()
        {
            //// Arrange
            var formatter = (PatternReplaceFormatter)PatternReplaceFormatter.GetPatternReplaceFormatter();

            //// Act
            formatter.AddOrUpdateReplaceablePattern(_invoice.ReplaceablePatterns());

            //// Assert
            Assert.AreEqual(formatter.Patterns["InvoiceNumber"].Replacement, "123", "InvoiceNumber does not match");
            Assert.AreEqual(formatter.Patterns["BillToName"].Replacement, "Mindfly", "BillToname does not match");
            Assert.AreEqual(formatter.Patterns["BillToAddress1"].Replacement, "114 W. Magnolia St.", "BillToAddress1 does not match");
            Assert.AreEqual(formatter.Patterns["BillToAddress2"].Replacement, "Suite 300", "BillToAddress2 does not match");
            Assert.AreEqual(formatter.Patterns["BillToLocality"].Replacement, "Bellingham", "BillToLocality does not match");
            Assert.AreEqual(formatter.Patterns["BillToRegion"].Replacement, "WA", "BillToRegion does not match");
            Assert.AreEqual(formatter.Patterns["BillToPostalCode"].Replacement, "98225", "BillToPostalCode does not match");
            Assert.AreEqual(formatter.Patterns["BillToEmail"].Replacement, "*****@*****.**", "BillToEmail does not match");
            Assert.AreEqual(formatter.Patterns["BillToPhone"].Replacement, "555-555-5555", "BillToPhone does not match");
        }