public XDocument Parse(EmailBroadcast eb)
 {
     var xml = eb.ToXml();
     Assert.IsNotNull(xml);
     XDocument xDoc = XDocument.Parse(xml);
     Assert.IsNotNull(xDoc);
     return xDoc;
 }
 public void BuildXmlWithoutRequiredInput()
 {
     try
     {
         var eb = new EmailBroadcast();
         var xml = eb.ToXml();
     }
     catch (FormatException)
     {
         Assert.IsTrue(true);
     }
 }
        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 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")));
        }