Exemple #1
0
        public void TestPrepare()
        {
            using (var content = new MemoryStream(new byte[64], false)) {
                var part = new MimePart("application/octet-stream")
                {
                    Content = new MimeContent(content)
                };
                var message = new MimeMessage()
                {
                    Body = part
                };
                var rfc822 = new MessagePart()
                {
                    Message = message
                };

                var encoding = part.GetBestEncoding(EncodingConstraint.SevenBit);

                Assert.AreEqual(ContentEncoding.Base64, encoding, "GetBestEncoding");

                rfc822.Prepare(EncodingConstraint.SevenBit);

                Assert.AreEqual(ContentEncoding.Base64, part.ContentTransferEncoding, "Prepare #1");

                // now make sure that calling Prepare() again doesn't change anything

                rfc822.Prepare(EncodingConstraint.SevenBit);

                Assert.AreEqual(ContentEncoding.Base64, part.ContentTransferEncoding, "Prepare #2");

                part.ContentTransferEncoding = ContentEncoding.Binary;
                rfc822.Prepare(EncodingConstraint.None);

                Assert.AreEqual(ContentEncoding.Binary, part.ContentTransferEncoding, "Prepare #3");

                rfc822.Prepare(EncodingConstraint.SevenBit);

                Assert.AreEqual(ContentEncoding.Base64, part.ContentTransferEncoding, "Prepare #4");
            }
        }