Пример #1
0
        public void TestAddStreamContentType()
        {
            var      fileName    = Path.Combine(TestHelper.ProjectDir, "TestData", "images", "girl.jpg");
            var      contentType = new ContentType("image", "gif");
            var      attachments = new AttachmentCollection();
            MimePart attachment;

            using (var stream = File.OpenRead(fileName))
                attachment = (MimePart)attachments.Add(fileName, stream, contentType);

            Assert.AreEqual(contentType.MimeType, attachment.ContentType.MimeType);
            Assert.AreEqual("girl.jpg", attachment.ContentType.Name);
            Assert.NotNull(attachment.ContentDisposition);
            Assert.AreEqual("attachment", attachment.ContentDisposition.Disposition);
            Assert.AreEqual("girl.jpg", attachment.ContentDisposition.FileName);
            Assert.AreEqual("girl.jpg", attachment.FileName);
            Assert.AreEqual(ContentEncoding.Base64, attachment.ContentTransferEncoding);
            Assert.AreEqual(1, attachments.Count);

            Assert.IsTrue(attachments.Contains(attachment), "Contains");
            Assert.AreEqual(0, attachments.IndexOf(attachment), "IndexOf");
            Assert.IsTrue(attachments.Remove(attachment), "Remove");
            Assert.AreEqual(0, attachments.Count);
            attachments.Clear();
        }
Пример #2
0
        public void TestDispose()
        {
            ac.Add(a);
            ac.Dispose();

            Assert.Throws <ObjectDisposedException>(() => ac.Add(a));
            Assert.Throws <ObjectDisposedException>(() => ac.Clear());

            // No throw on second dispose
            ac.Dispose();
        }
Пример #3
0
        public void TestAddEmailMessage()
        {
            var        fileName    = Path.Combine(TestHelper.ProjectDir, "TestData", "messages", "body.1.txt");
            var        attachments = new AttachmentCollection();
            MimeEntity attachment;

            using (var stream = File.OpenRead(fileName))
                attachment = attachments.Add("message.eml", stream);

            Assert.AreEqual("message/rfc822", attachment.ContentType.MimeType);
            Assert.AreEqual(1, attachments.Count);

            Assert.IsTrue(attachments.Contains(attachment), "Contains");
            Assert.AreEqual(0, attachments.IndexOf(attachment), "IndexOf");
            Assert.IsTrue(attachments.Remove(attachment), "Remove");
            Assert.AreEqual(0, attachments.Count);
            attachments.Clear();
        }
Пример #4
0
        public void TestAddFileName()
        {
            var      fileName    = Path.Combine(TestHelper.ProjectDir, "TestData", "images", "girl.jpg");
            var      attachments = new AttachmentCollection();
            MimePart attachment;

            attachment = (MimePart)attachments.Add(fileName);
            Assert.AreEqual("image/jpeg", attachment.ContentType.MimeType);
            Assert.AreEqual("girl.jpg", attachment.FileName);
            Assert.AreEqual(ContentEncoding.Base64, attachment.ContentTransferEncoding);
            Assert.AreEqual(1, attachments.Count);

            Assert.IsTrue(attachments.Contains(attachment), "Contains");
            Assert.AreEqual(0, attachments.IndexOf(attachment), "IndexOf");
            Assert.IsTrue(attachments.Remove(attachment), "Remove");
            Assert.AreEqual(0, attachments.Count);
            attachments.Clear();
        }
        public void TestAddTextFileName()
        {
            var      fileName    = Path.Combine(TestHelper.ProjectDir, "TestData", "text", "lorem-ipsum.txt");
            var      attachments = new AttachmentCollection();
            MimePart attachment;

            attachment = (MimePart)attachments.Add(fileName);
            Assert.AreEqual("text/plain", attachment.ContentType.MimeType);
            Assert.AreEqual("lorem-ipsum.txt", attachment.FileName);
            Assert.AreEqual(ContentEncoding.SevenBit, attachment.ContentTransferEncoding);
            Assert.AreEqual(1, attachments.Count);

            Assert.IsTrue(attachments.Contains(attachment), "Contains");
            Assert.AreEqual(0, attachments.IndexOf(attachment), "IndexOf");
            Assert.IsTrue(attachments.Remove(attachment), "Remove");
            Assert.AreEqual(0, attachments.Count);
            attachments.Clear();
        }
Пример #6
0
        public void TestAddDataContentType()
        {
            var      fileName    = Path.Combine("..", "..", "TestData", "images", "girl.jpg");
            var      contentType = new ContentType("image", "gif");
            var      attachments = new AttachmentCollection();
            MimePart attachment;

            attachment = (MimePart)attachments.Add(fileName, File.ReadAllBytes(fileName), contentType);
            Assert.AreEqual(contentType.MimeType, attachment.ContentType.MimeType);
            Assert.AreEqual("girl.jpg", attachment.FileName);
            Assert.AreEqual(ContentEncoding.Base64, attachment.ContentTransferEncoding);
            Assert.AreEqual(1, attachments.Count);

            Assert.IsTrue(attachments.Contains(attachment), "Contains");
            Assert.AreEqual(0, attachments.IndexOf(attachment), "IndexOf");
            Assert.IsTrue(attachments.Remove(attachment), "Remove");
            Assert.AreEqual(0, attachments.Count);
            attachments.Clear();
        }
Пример #7
0
        public void TestAddStream()
        {
            var      fileName    = Path.Combine("..", "..", "TestData", "images", "girl.jpg");
            var      attachments = new AttachmentCollection();
            MimePart attachment;

            using (var stream = File.OpenRead(fileName))
                attachment = (MimePart)attachments.Add(fileName, stream);

            Assert.AreEqual("image/jpeg", attachment.ContentType.MimeType);
            Assert.AreEqual("girl.jpg", attachment.FileName);
            Assert.AreEqual(ContentEncoding.Base64, attachment.ContentTransferEncoding);
            Assert.AreEqual(1, attachments.Count);

            Assert.IsTrue(attachments.Contains(attachment), "Contains");
            Assert.AreEqual(0, attachments.IndexOf(attachment), "IndexOf");
            Assert.IsTrue(attachments.Remove(attachment), "Remove");
            Assert.AreEqual(0, attachments.Count);
            attachments.Clear();
        }
Пример #8
0
        public async Task TestAddInlineEmailMessageAsync()
        {
            var        fileName    = Path.Combine(TestHelper.ProjectDir, "TestData", "messages", "body.1.txt");
            var        attachments = new AttachmentCollection(true);
            MimeEntity attachment;

            using (var stream = File.OpenRead(fileName))
                attachment = await attachments.AddAsync("message.eml", stream);

            Assert.AreEqual("message/rfc822", attachment.ContentType.MimeType);
            Assert.AreEqual("message.eml", attachment.ContentType.Name);
            Assert.NotNull(attachment.ContentDisposition);
            Assert.AreEqual("inline", attachment.ContentDisposition.Disposition);
            Assert.AreEqual("message.eml", attachment.ContentDisposition.FileName);
            Assert.AreEqual(1, attachments.Count);

            Assert.IsTrue(attachments.Contains(attachment), "Contains");
            Assert.AreEqual(0, attachments.IndexOf(attachment), "IndexOf");
            Assert.IsTrue(attachments.Remove(attachment), "Remove");
            Assert.AreEqual(0, attachments.Count);
            attachments.Clear();
        }
Пример #9
0
        public async Task TestAddInlineFileNameAsync()
        {
            var      fileName    = Path.Combine(TestHelper.ProjectDir, "TestData", "images", "girl.jpg");
            var      attachments = new AttachmentCollection(true);
            MimePart attachment;

            attachment = (MimePart)await attachments.AddAsync(fileName);

            Assert.AreEqual("image/jpeg", attachment.ContentType.MimeType);
            Assert.AreEqual("girl.jpg", attachment.ContentType.Name);
            Assert.NotNull(attachment.ContentDisposition);
            Assert.AreEqual("inline", attachment.ContentDisposition.Disposition);
            Assert.AreEqual("girl.jpg", attachment.ContentDisposition.FileName);
            Assert.AreEqual("girl.jpg", attachment.FileName);
            Assert.AreEqual(ContentEncoding.Base64, attachment.ContentTransferEncoding);
            Assert.AreEqual(1, attachments.Count);

            Assert.IsTrue(attachments.Contains(attachment), "Contains");
            Assert.AreEqual(0, attachments.IndexOf(attachment), "IndexOf");
            Assert.IsTrue(attachments.Remove(attachment), "Remove");
            Assert.AreEqual(0, attachments.Count);
            attachments.Clear();
        }