public void Test_EmbedImage_listlinkedresource()
        {
            var filename = new string[] { Path.GetTempFileName(), Path.GetTempFileName() };
            var attachments = filename.ToList().ConvertAll<Attachment>((x) => { return new Attachment(x); });
            var linkedResources = filename.ToList().ConvertAll<LinkedResource>((x) => { return new LinkedResource(x); });

            var mail = BasicMailBuilder
                .EmbedImages(linkedResources)
                .Build();

            var message = new SendGridMessage();
            message.AddAttachment(attachments[0].ContentStream, attachments[0].Name);
            message.AddAttachment(attachments[1].ContentStream, attachments[1].Name);
            message.EmbedImage(linkedResources[0].ContentId, linkedResources[0].ContentId);
            message.EmbedImage(linkedResources[1].ContentId, linkedResources[1].ContentId);
            CollectionAssert.AreEquivalent(message.GetEmbeddedImages().ToList(), mail.GetEmbeddedImages().ToList());
            Assert.AreEqual(2, message.StreamedAttachments.Count);
            Assert.AreEqual(2, mail.StreamedAttachments.Count);
            Assert.AreEqual(message.StreamedAttachments.First().Value.Length, mail.StreamedAttachments.First().Value.Length);
            Assert.AreEqual(message.StreamedAttachments.Last().Value.Length, mail.StreamedAttachments.Last().Value.Length);
        }
        public void Test_EmbedImage_linkedresourcecollection()
        {
            var filename = Path.GetTempFileName();
            var attachment = new Attachment(filename);
            var av = AlternateView.CreateAlternateViewFromString("Testing");
            av.LinkedResources.Add(new LinkedResource(filename));

            var mail = BasicMailBuilder
                .EmbedImages(av.LinkedResources)
                .Build();

            var message = new SendGridMessage();
            message.AddAttachment(attachment.ContentStream, attachment.Name);
            message.EmbedImage(av.LinkedResources[0].ContentId, av.LinkedResources[0].ContentId);
            CollectionAssert.AreEquivalent(message.GetEmbeddedImages().ToList(), mail.GetEmbeddedImages().ToList());
            Assert.AreEqual(1, message.StreamedAttachments.Count);
            Assert.AreEqual(1, mail.StreamedAttachments.Count);
            Assert.AreEqual(message.StreamedAttachments.First().Value.Length, mail.StreamedAttachments.First().Value.Length);
        }
        public void Test_EmbedImage_filepath_cid()
        {
            var filename = Path.GetTempFileName();
            var cid = "*****@*****.**";
            var mail = BasicMailBuilder
                .EmbedImage(filename, cid)
                .Build();

            var message = new SendGridMessage();
            message.AddAttachment(filename);
            message.EmbedImage(new FileInfo(filename).Name, cid);

            CollectionAssert.AreEquivalent(message.GetEmbeddedImages().ToList(), mail.GetEmbeddedImages().ToList());
            CollectionAssert.AreEquivalent(message.Attachments, mail.Attachments);
            CollectionAssert.AreEquivalent(message.StreamedAttachments, mail.StreamedAttachments);
        }
        public void Test_EmbedImage_linkedresource()
        {
            var filename = Path.GetTempFileName();
            var attachment = new Attachment(filename);
            var linkedResource = new LinkedResource(filename);

            var mail = BasicMailBuilder
                .EmbedImage(linkedResource)
                .Build();

            var message = new SendGridMessage();
            message.AddAttachment(attachment.ContentStream, attachment.Name);
            message.EmbedImage(linkedResource.ContentId, linkedResource.ContentId);
            CollectionAssert.AreEquivalent(message.GetEmbeddedImages().ToList(), mail.GetEmbeddedImages().ToList());
            Assert.AreEqual(1, message.StreamedAttachments.Count);
            Assert.AreEqual(1, mail.StreamedAttachments.Count);
            Assert.AreEqual(message.StreamedAttachments.First().Value.Length, mail.StreamedAttachments.First().Value.Length);
        }
Ejemplo n.º 5
0
 public MailBuilder EmbedImage(Stream stream, string name, string cid)
 {
     sendgrid.AddAttachment(stream, name);
     sendgrid.EmbedImage(name, cid);
     return(this);
 }