Ejemplo n.º 1
0
        public void TestGetText()
        {
            const string text = "This is some Låtín1 text.";

            var encoding = Encoding.GetEncoding("iso-8859-1");
            var part     = new TextPart("plain");

            part.SetText("iso-8859-1", text);

            Assert.AreEqual(text, part.GetText("iso-8859-1"), "charset");
            Assert.AreEqual(text, part.GetText(encoding), "encoding");
        }
Ejemplo n.º 2
0
        public void TestArgumentExceptions()
        {
            var text = new TextPart(TextFormat.Plain);

            Assert.Throws <ArgumentNullException> (() => new TextPart("plain", (object[])null));
            Assert.Throws <ArgumentException> (() => new TextPart("plain", Encoding.UTF8, "blah blah blah", Encoding.UTF8));
            Assert.Throws <ArgumentException> (() => new TextPart("plain", Encoding.UTF8, "blah blah blah", "blah blah"));
            Assert.Throws <ArgumentException> (() => new TextPart("plain", 5));
            Assert.Throws <ArgumentOutOfRangeException> (() => new TextPart((TextFormat)500));

            Assert.Throws <ArgumentNullException> (() => text.Accept(null));
            Assert.Throws <ArgumentNullException> (() => text.GetText((string)null));
            Assert.Throws <ArgumentNullException> (() => text.GetText((Encoding)null));
            Assert.Throws <ArgumentNullException> (() => text.SetText((string)null, "text"));
            Assert.Throws <ArgumentNullException> (() => text.SetText((Encoding)null, "text"));
            Assert.Throws <ArgumentNullException> (() => text.SetText("iso-8859-1", null));
            Assert.Throws <ArgumentNullException> (() => text.SetText(Encoding.UTF8, null));
        }
Ejemplo n.º 3
0
        public void TestNullContentIsAscii()
        {
            var part = new TextPart("plain");

            Assert.AreEqual(string.Empty, part.Text, "Text");
            Assert.AreEqual(string.Empty, part.GetText(Encoding.ASCII), "GetText");

            var actual = part.GetText(out Encoding encoding);

            Assert.AreEqual(string.Empty, actual, "GetText(out Encoding)");
            Assert.AreEqual(Encoding.ASCII.CodePage, encoding.CodePage, "Encoding");
        }
Ejemplo n.º 4
0
        public static string GetTextInUtf8(this TextPart textPart)
        {
            var utf8 = Encoding.UTF8;

            if (!textPart.IsHtml && textPart.ContentTransferEncoding == ContentEncoding.SevenBit)
            {
                //TODO другие допилить если будет ерунда
                return(textPart.GetText(utf8));
            }

            return(textPart.Text);
        }