public void SerializeTest()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(EmailBroadcast));
            Order order = new EmailBroadcast()
            {
                DisplayName = "jt",
                EmailSubject = "test email message",
                SendTimeUTC = DateTime.UtcNow,
                TextBody = TextBody.FromText("This is a test email")
            };

            StringBuilder sb = new StringBuilder();
            TextWriter writer = new StringWriter(sb);
            serializer.Serialize(writer, order);
            writer.Close();

            Assert.IsNotNull(sb);
            Assert.IsTrue(!string.IsNullOrEmpty(sb.ToString()));

            TextReader tr = new StringReader(sb.ToString());
            object obj = serializer.Deserialize(tr);
            var deserializedMessage = obj as EmailBroadcast;
            Assert.IsTrue(deserializedMessage.DisplayName == "jt");
            Assert.IsTrue(deserializedMessage.EmailSubject == "test email message");
            var xml = deserializedMessage.ToXml();
        }
 public XDocument Parse(EmailBroadcast eb)
 {
     var xml = eb.ToXml();
     Assert.IsNotNull(xml);
     XDocument xDoc = XDocument.Parse(xml);
     Assert.IsNotNull(xDoc);
     return xDoc;
 }
        public void BuildXmlWithRequiredInput()
        {
            var eb = new EmailBroadcast();
            eb.TextBody = TextBody.FromText("Required content");
            eb.List = ContactList.FromText("requiredList.csv", "email\r\[email protected]");

            Parse(eb);
        }
Beispiel #4
0
        public static void Execute()
        {
            Console.WriteLine("Alert Solutions API Client SimpleDemo\n");

            var attachments = new List<Attachment>();
            attachments.Add(Attachment.FromFile("Files\\Attachment.txt"));

            var proofs = new List<string>();
            proofs.Add("*****@*****.**");

            // create an email broadcast and give it the desired values
            var eb = new EmailBroadcast();
            eb.BillCode = "APIClient Demo";
            eb.ProjectCode = "APIClient Demo";
            eb.DisplayName = "AlertSolutions";
            eb.EmailSubject = "Alert Solutions API Client Demo";
            eb.EmailFrom = "*****@*****.**";
            eb.EmailReplyTo = "*****@*****.**";
            eb.TextBody = TextBody.FromFile("Files\\Email.txt");
            // be sure to modify the ContactList.csv file so the email goes to your intended destinations
            eb.List = ContactList.FromFile("Files\\ContactList.csv");
            eb.EmailHeader = "email";
            eb.Attachments = attachments;
            eb.Proofs = proofs;

            // change these values to your API login
            var user = "";
            var password = "";
            var url = "http://weblaunch.blifax.com/postapi";

            // create the client
            var client = new ApiClient(url, user, password);

            Console.WriteLine("\nPress any key to launch broadcast.");
            Console.ReadLine();

            // launch the broadcast
            var response = client.LaunchBroadcast(eb);

            // test the response status (in case it could not connect or something went wrong while submitting)
            Console.WriteLine("Response Status: " + response.RequestResult);
            if (response.RequestResult == RequestResultType.Error)
                Console.WriteLine("Error: " + response.RequestErrorMessage);
            else
                Console.WriteLine("OrderID: " + response.OrderID);

            Console.WriteLine("\nPress any key to retrieve report... (best to wait a few seconds)");
            Console.ReadLine();

            // get more information about the order by asking for a report
            var report = client.GetOrderReport(response, ReportReturnType.XML);

            Console.WriteLine("Report: " + report.ReportData);

            Console.WriteLine("\nPress any key to exit...");
            Console.ReadLine();
        }
 public void BuildXmlWithoutRequiredInput()
 {
     try
     {
         var eb = new EmailBroadcast();
         var xml = eb.ToXml();
     }
     catch (FormatException)
     {
         Assert.IsTrue(true);
     }
 }
Beispiel #6
0
        public static void Execute()
        {
            Console.WriteLine("Alert Solutions API Client SimpleDemo\n");

            var attachments = new List<Attachment>();
            attachments.Add(Attachment.FromFile("Files\\Attachment.txt"));

            var proofs = new List<string>();
            proofs.Add("*****@*****.**");

            // create an email broadcast and give it the desired values
            var eb = new EmailBroadcast();
            eb.BillCode = "APIClient Demo";
            eb.ProjectCode = "APIClient Demo";
            eb.DisplayName = "AlertSolutions";
            eb.EmailSubject = "Alert Solutions API Client Demo";
            eb.EmailFrom = "*****@*****.**";
            eb.EmailReplyTo = "*****@*****.**";
            eb.TextBody = TextBody.FromFile("Files\\Email.txt");
            // be sure to modify the ContactList.csv file so the email goes to your intended destinations
            eb.List = ContactList.FromFile("Files\\ContactList.csv");
            eb.EmailHeader = "email";
            eb.Attachments = attachments;
            eb.Proofs = proofs;

            // change these values to your API login
            var user = "******";
            var password = "******";
            var url = "http://weblaunch.blifax.com/postapi";

            // create the client
            var client = new ApiClient(url, user, password);

            Console.WriteLine("\nPress any key to launch broadcast.");
            Console.ReadLine();

            // launch the broadcast
            var response = client.LaunchBroadcast(eb);
            Console.WriteLine("Response Status: " + response.RequestResult);
            if (response.RequestResult == RequestResultType.Error)
                Console.WriteLine("Error: " + response.RequestErrorMessage);
            else
                Console.WriteLine("OrderID: " + response.OrderID);

            Console.WriteLine("\nPress any key to cancel broadcast.");
            Console.ReadLine();

            var cancelResponse = client.CancelOrder(response);
            Console.WriteLine("\n\n"+ cancelResponse);
        }
Beispiel #7
0
        public static IOrder CreateEB()
        {
            var f = System.IO.File.ReadAllBytes("testfiles\\report-card-sample.pdf");
            var b = Convert.ToBase64String(f);
            var eb = new EmailBroadcast();

            eb.BillCode = "PostAPIClient Refactor Test";
            eb.ProjectCode = "PostAPIClient Refactor Test";
            eb.EmailSubject = "PostAPIClient Refactor Test (EB)";
            eb.EmailReplyTo = "*****@*****.**";
            eb.EmailFrom = "*****@*****.**";
            eb.DisplayName = "JThomas from AlertSolutions";
            //eb.Attachments = new List<Attachment>() { Attachment.FromBase64String("file.pdf",b) };
            eb.Attachments = new List<Attachment>() { Attachment.FromText("file.txt", "This is a test message attachment.") };
            eb.TextBody = TextBody.FromFile("TestFiles\\Email.txt");
            eb.HtmlBody = HtmlBody.FromFile("TestFiles\\Email.html");
            eb.List = ContactList.FromFile("TestFiles\\ContactList.csv");
            eb.EmailHeader = "email";
            eb.Proofs = new List<string>() { "*****@*****.**" };
            return eb;
        }
Beispiel #8
0
        public static void Execute()
        {
            Console.WriteLine("Alert Solutions API Client FullDemo\n");

            // ===========================================
            //              BROADCASTS
            // ===========================================

            List<IBroadcast> broadcasts = new List<IBroadcast>();

            // EMAIL BROADCAST
            var eb = new EmailBroadcast();
            eb.BillCode = "APIClient Demo";
            eb.ProjectCode = "APIClient Demo";
            eb.DisplayName = "AlertSolutions";
            eb.EmailSubject = "Alert Solutions API Client Demo";
            eb.EmailFrom = "*****@*****.**";
            eb.EmailReplyTo = "*****@*****.**";
            eb.Attachments = new List<Attachment>() { Attachment.FromFile("Files\\Attachment.txt") };
            eb.List = ContactList.FromFile("Files\\ContactList.csv");
            eb.EmailHeader = "email";
            eb.Proofs = new List<string>() { "*****@*****.**" };
            // can use either Text or HTML
            eb.HtmlBody = HtmlBody.FromFile("Files\\Email.html");
            eb.TextBody = TextBody.FromFile("Files\\Email.txt");

            broadcasts.Add(eb);

            // SMS BROADCAST
            var sb = new SMSBroadcast();
            sb.BillCode = "APIClient Demo";
            sb.ProjectCode = "APIClient Demo";
            sb.ShortCode = "77811";
            sb.TextMessage = TextMessage.FromFile("Files\\TextMessage.txt");
            sb.List = ContactList.FromFile("Files\\ContactList.csv");
            sb.SMSHeader = "phone";
            sb.Proofs = new List<string>() { "5555555555" };

            broadcasts.Add(sb);

            // VOICE BROADCAST
            var vb = new VoiceBroadcast();
            vb.BillCode = "APIClient Demo";
            vb.ProjectCode = "APIClient Demo";
            vb.CallerID = "5555555555";
            vb.List = ContactList.FromFile("Files\\ContactList.csv");
            vb.VoiceHeader = "phone";
            vb.ThrottleType = VoiceBroadcast.VoiceThrottleType.MaximumCalls;
            vb.ThrottleNumber = 2;
            // can be told to load an xml file, or be given the xml as text
            //vt.CallScript = CallScript.FromString("");
            //vt.CallScript = CallScript.FromFile("");
            vb.Documents = new List<Document>()
            {
                //VoiceDocument.FromFile("Files\\VoiceMessage.txt", VoiceDocumentType.Live),
                VoiceDocument.FromFile("Files\\VoiceMessage.txt", VoiceDocumentType.Message),
            };

            broadcasts.Add(vb);

            // FAX BROADCAST
            var fb = new FaxBroadcast();
            fb.BillCode = "APIClient Demo";
            fb.ProjectCode = "APIClient Demo";
            fb.FaxFrom = "john doe";
            fb.List = ContactList.FromFile("Files\\FaxList.csv");
            fb.FaxHeader = "faxnumber";
            fb.Dedup = true;
            fb.DocumentStyle = "Letter";
            fb.Documents = new List<Document>()
            {
                Document.FromFile("Files\\FaxText.txt"),
            };

            broadcasts.Add(fb);

            // ===========================================
            //             MESSAGES
            // ===========================================

            List<IMessage> messages = new List<IMessage>();

            // EMAIL MESSAGE
            var em = new EmailMessage();
            em.EmailTo = "*****@*****.**";
            em.DisplayName = "AlertSolutions";
            em.EmailSubject = "Alert Solutions API Client Demo";
            em.EmailFrom = "*****@*****.**";
            em.EmailReplyTo = "*****@*****.**";
            em.Attachments = new List<Attachment>() { Attachment.FromFile("Files\\Attachment.txt") };
            // can use either Text or HTML
            em.TextBody = TextBody.FromFile("Files\\Email.txt");
            //em.EmailBody = HtmlBody.FromFile("Files\\Email.html");

            messages.Add(em);

            // SMS MESSAGE
            var sm = new SMSMessage();
            sm.Number = "5555555555";
            sm.ShortCode = "77811"; // shared Alert Solutions Shortcode
            sm.TextMessage = TextMessage.FromFile("Files\\TextMessage.txt");

            messages.Add(sm);

            // VOICE MESSAGE
            var vm = new VoiceMessage();
            //vt.CallScript = CallScript.FromString("");
            //vt.CallScript = CallScript.FromFile("");
            vm.Phone = "5555555555";
            vm.CallerID = "5555555555";
            vm.Documents = new List<Document>()
            {
                VoiceDocument.FromFile("Files\\VoiceMessage.txt", VoiceDocumentType.Live),
                VoiceDocument.FromFile("Files\\VoiceMessage.txt", VoiceDocumentType.Message),
            };

            messages.Add(vm);

            // FAX MESSAGE
            var fm = new FaxMessage();
            fm.FaxFrom = "john doe";
            fm.FaxNumber = "4014271405";
            fm.DocumentStyle = "Letter";
            fm.Documents = new List<Document>()
            {
                Document.FromFile("Files\\FaxText.txt"),
            };

            messages.Add(fm);

            // ===========================================
            //             LAUNCH
            // ===========================================

            // change these values to your API login
            var user = "******";
            var password = "******";
            var url = "http://weblaunch.blifax.com/postapi";

            // create the client
            var client = new ApiClient(url, user, password);
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("There is a pause of about 10 seconds before getting a report.");
            Console.ForegroundColor = ConsoleColor.Gray;

            // launch the broadcasts
            foreach (var broadcast in broadcasts)
            {
                Console.Write("\n\nSending " + broadcast.TypeOfOrder + ": ");

                var response = client.LaunchBroadcast(broadcast);

                Console.Write("** " + response.RequestResult + " **");
                Console.Write(response.RequestResult != RequestResultType.Error ?
                    " OrderID: " + response.OrderID : "Error: " + response.RequestErrorMessage);

                // wait for broadcast before request report
                System.Threading.Thread.Sleep(12000);
                var report = client.GetOrderReport(response, ReportReturnType.XML);

                Console.Write("\nReport:\n" + report.ReportData);
            }

            // launch the messages
            foreach (var message in messages)
            {
                Console.Write("\n\nSending " + message.TypeOfOrder + ": ");

                var response = client.LaunchMessage(message);

                Console.Write("** " + response.RequestResult + " **");
                Console.Write(response.RequestResult != RequestResultType.Error ?
                    " OrderID: " + response.OrderID  + " TransID: " + response.Unqid : "Error: " + response.RequestErrorMessage);

                // wait for message before request report
                System.Threading.Thread.Sleep(10000);
                var report = client.GetOrderReport(response, ReportReturnType.XML);

                Console.Write("\nReport:\n" + report.ReportData);
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
        }
 public void ConstructorTest()
 {
     var emailBroadcast = new EmailBroadcast();
     Assert.IsNotNull(emailBroadcast);
 }
        public void XmlOutputSetValuesTest()
        {
            var eb = new EmailBroadcast();
            eb.AutoLaunch = false;
            eb.BillCode = "BC";
            eb.DisplayName = "DN";
            eb.EmailFrom = "EF";
            eb.EmailHeader = "email";
            eb.EmailReplyTo = "ERT";
            eb.EmailSubject = "ES";
            eb.HtmlBody = HtmlBody.FromText("Required content <b>html</b>");
            eb.IsForward = true;
            eb.IsReplaceLink = true;
            eb.IsUnsubscribe = true;
            eb.LanguageHeader = "Dutch";
            eb.List = ContactList.FromText("requiredList.csv", "email\r\[email protected]");
            eb.NumberOfRedials = 3;
            eb.NumberOfResends = 2;
            eb.ProjectCode = "PC";
            eb.Proofs = new List<string>();
            eb.ResendInterval = "4";
            eb.SendTimeUTC = new DateTime(2010, 10, 12, 16, 15, 35);
            eb.TextBody = TextBody.FromText("Required content plaintext");

            var xDoc = Parse(eb);
            VerifyFieldsExist(xDoc);

            // make sure the VALUES match what was set above
            var orderTag = xDoc.Root.Elements("Order").FirstOrDefault();
            Assert.IsTrue(orderTag.FirstAttribute.Value == "EB");
            Assert.IsTrue(orderTag.Element("AutoLaunch").Value == "No");
            Assert.IsTrue(orderTag.Element("BillCode").Value == "BC");
            Assert.IsTrue(orderTag.Element("Project").Value == "PC");
            Assert.IsTrue(orderTag.Element("DisplayName").Value == "DN");
            Assert.IsTrue(orderTag.Element("Date").Value == "2010-10-12");
            Assert.IsTrue(orderTag.Element("Time").Value == "16:15");
            Assert.IsTrue(orderTag.Element("From").Value == "EF");
            Assert.IsTrue(orderTag.Element("ReplyTo").Value == "ERT");
            Assert.IsTrue(orderTag.Element("Subject").Value == "ES");
            Assert.IsTrue(orderTag.Element("Forward").Value == "Yes");
            Assert.IsTrue(orderTag.Element("ReplaceLink").Value == "Yes");
            Assert.IsTrue(orderTag.Element("Unsubscribe").Value == "Yes");
            Assert.IsTrue(orderTag.Element("LanguageHeader").Value == "Dutch");
            Assert.IsTrue(orderTag.Element("NumberOfRedials").Value == "3");
            Assert.IsTrue(orderTag.Element("NumberOfResends").Value == "2");

            // TODO : make tests for these conditional fields and their output
            // conditionals
            Assert.IsTrue(orderTag.Element("ResendInterval").Value == "4");
            Assert.IsTrue(orderTag.Element("ListID").Value == "");
            Assert.IsTrue(orderTag.Element("ListName").Value == "requiredList.csv");
            Assert.IsTrue(Encoding.UTF8.GetString(Convert.FromBase64String(orderTag.Element("ListBinary").Value)) == "email\r\[email protected]");
            Assert.IsTrue(orderTag.Element("EmailField").Value == "email"); // header <- what happens when not set?

            // documents
            Assert.IsTrue(orderTag.Element("HtmlID").Value == "");
            Assert.IsNotNull(orderTag.Element("HtmlFile").Value);
            Assert.IsTrue(Encoding.UTF8.GetString(Convert.FromBase64String(orderTag.Element("HtmlBinary").Value)) == "Required content <b>html</b>");
            Assert.IsTrue(orderTag.Element("TextID").Value == "");
            Assert.IsNotNull(orderTag.Element("TextFile").Value);
            Assert.IsTrue(Encoding.UTF8.GetString(Convert.FromBase64String(orderTag.Element("TextBinary").Value)) == "Required content plaintext");
        }
        public void XmlOutputProofTest()
        {
            var eb = new EmailBroadcast();
            eb.TextBody = TextBody.FromText("required content");
            eb.List = ContactList.FromText("requiredList.csv", "email\r\[email protected]");
            eb.Proofs = new List<string>() { "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" };

            var xml = eb.ToXml();
            XDocument xDoc = XDocument.Parse(xml);

            var orderTag = xDoc.Root.Elements("Order").FirstOrDefault();
            var proofs = orderTag.Element("Proofs").Elements().ToList();
            Assert.IsTrue(orderTag.Element("Proofs").Elements().Count() ==  5);
            Assert.IsTrue(proofs[0].Value == "*****@*****.**");
            Assert.IsTrue(proofs[1].Value == "*****@*****.**");
            Assert.IsTrue(proofs[2].Value == "*****@*****.**");
            Assert.IsTrue(proofs[3].Value == "*****@*****.**");
            Assert.IsTrue(proofs[4].Value == "*****@*****.**");

            // overloading the amount of allowable proofs
            eb.Proofs.Add("*****@*****.**");

            xml = eb.ToXml();
            xDoc = XDocument.Parse(xml);
            orderTag = xDoc.Root.Elements("Order").FirstOrDefault();
            Assert.IsTrue(orderTag.Element("Proofs").Elements().Count() == 6);
        }
        public void XmlOutputDefaultValuesTest()
        {
            var eb = new EmailBroadcast();
            eb.TextBody = TextBody.FromText("Required content");
            eb.List = ContactList.FromText("requiredList.csv", "email\r\[email protected]");

            var xDoc = Parse(eb);
            VerifyFieldsExist(xDoc);
            var orderTag = xDoc.Root.Elements("Order").FirstOrDefault();
            Assert.IsTrue(orderTag.Element("AutoLaunch").Value == "Yes");
            //TODO : finish the rest of the default fields
        }
        public void XmlOutputAttachmentTest()
        {
            var eb = new EmailBroadcast();
            eb.TextBody = TextBody.FromText("required content");
            eb.List = ContactList.FromText("requiredList.csv", "email\r\[email protected]");
            eb.Attachments = new List<Attachment>()
            {
                Attachment.FromText("file1.txt", "content #1"),
                Attachment.FromText("file2.txt", "content #2"),
                Attachment.FromText("file3.txt", "content #3")
            };

            var xml = eb.ToXml();
            XDocument xDoc = XDocument.Parse(xml);
            var orderTag = xDoc.Root.Element("Order");
            var attachmentsTag = orderTag.Element("Attachments");

            Assert.IsNotNull(attachmentsTag);
            Assert.IsTrue(attachmentsTag.Elements().Count() == 3);

            var attachmentTag1 = attachmentsTag.Elements().ToList()[0];
            Assert.IsNotNull(attachmentTag1.Element("AttachmentID"));
            Assert.IsTrue(attachmentTag1.Element("AttachmentName").Value == "file1.txt");
            var value = attachmentTag1.Element("AttachmentBinary").Value;
            Assert.IsTrue(attachmentTag1.Element("AttachmentBinary").Value == Convert.ToBase64String(Encoding.UTF8.GetBytes("content #1")));
            var attachmentTag2 = attachmentsTag.Elements().ToList()[1];
            Assert.IsNotNull(attachmentTag2.Element("AttachmentID"));
            Assert.IsTrue(attachmentTag2.Element("AttachmentName").Value == "file2.txt");
            Assert.IsTrue(attachmentTag2.Element("AttachmentBinary").Value == Convert.ToBase64String(Encoding.UTF8.GetBytes("content #2")));
            var attachmentTag3 = attachmentsTag.Elements().ToList()[2];
            Assert.IsNotNull(attachmentTag3.Element("AttachmentID"));
            Assert.IsTrue(attachmentTag3.Element("AttachmentName").Value == "file3.txt");
            Assert.IsTrue(attachmentTag3.Element("AttachmentBinary").Value == Convert.ToBase64String(Encoding.UTF8.GetBytes("content #3")));
        }