Пример #1
0
        public void ParseContentDispositionFull()
        {
            const string contentDispositionValue =
                "attachment; " +
                "filename=genome.jpeg; " +
                "modification-date=\"Wed, 12 February 1997 16:29:51 -0500\"; " +
                "creation-date=\"Tue, 11 February 1997 15:29:51 -0400\"; " +
                "read-date=\"Tue, 11 February 1997 16:29:52 -0500\"; " +
                "size=509;";

            ContentDisposition contentDisposition = null;

            Assert.DoesNotThrow(delegate { contentDisposition = HeaderFieldParser.ParseContentDisposition(contentDispositionValue); });
            Assert.NotNull(contentDisposition);

            // It is an attachment, not inline
            Assert.IsFalse(contentDisposition.Inline);
            Assert.AreEqual("attachment", contentDisposition.DispositionType);

            Assert.AreEqual("genome.jpeg", contentDisposition.FileName);

            // -0500 is the same as adding 5 hours in UTC
            Assert.AreEqual(new DateTime(1997, 2, 12, 21, 29, 51, DateTimeKind.Utc), contentDisposition.ModificationDate);

            // -0400 is the same as adding 4 hours in UTC
            Assert.AreEqual(new DateTime(1997, 2, 11, 19, 29, 51, DateTimeKind.Utc), contentDisposition.CreationDate);

            // -0500 is the same as adding 5 hours in UTC
            Assert.AreEqual(new DateTime(1997, 2, 11, 21, 29, 52, DateTimeKind.Utc), contentDisposition.ReadDate);

            Assert.AreEqual(509, contentDisposition.Size);
        }
Пример #2
0
        public void ParseContentDispositionFull2()
        {
            const string contentDispositionValue =
                "inline; " +
                "filename=test.pdf; " +
                "modification-date=\"Tue, 16 November 2010 11:16:51 +0100\"; " +
                "creation-date=\"Tue, 16 November 2010 11:16:52 +0100\"; " +
                "read-date=\"Tue, 16 November 2010 11:16:53 +0100\"; " +
                "size=104953;";

            ContentDisposition contentDisposition = null;

            Assert.DoesNotThrow(delegate { contentDisposition = HeaderFieldParser.ParseContentDisposition(contentDispositionValue); });
            Assert.NotNull(contentDisposition);

            // It is an attachment, not inline
            Assert.IsTrue(contentDisposition.Inline);
            Assert.AreEqual("inline", contentDisposition.DispositionType);

            Assert.AreEqual("test.pdf", contentDisposition.FileName);

            // +0100 is the same as substractinbg 1 hour in UTC
            Assert.AreEqual(new DateTime(2010, 11, 16, 10, 16, 51, DateTimeKind.Utc), contentDisposition.ModificationDate);

            // -0400 is the same as adding 4 hours in UTC
            Assert.AreEqual(new DateTime(2010, 11, 16, 10, 16, 52, DateTimeKind.Utc), contentDisposition.CreationDate);

            // -0500 is the same as adding 5 hours in UTC
            Assert.AreEqual(new DateTime(2010, 11, 16, 10, 16, 53, DateTimeKind.Utc), contentDisposition.ReadDate);

            Assert.AreEqual(104953, contentDisposition.Size);
        }
Пример #3
0
        public void TestNoQuotesInAttachmentFilenameWithLinebreakAndTab()
        {
            const string       contentDispositionString = "attachment; filename=\r\n\t\"a.txt\"";
            ContentDisposition contentDisposition       = HeaderFieldParser.ParseContentDisposition(contentDispositionString);

            Assert.IsFalse(contentDisposition.Inline);
            Assert.AreEqual("a.txt", contentDisposition.Parameters["filename"]);
        }
Пример #4
0
        public static void ContentDispositionSimpleInline()
        {
            const string contentDispositionString = "inline";

            ContentDisposition contentDisposition = HeaderFieldParser.ParseContentDisposition(contentDispositionString);

            Assert.IsTrue(contentDisposition.Inline);
            Assert.AreEqual("inline", contentDisposition.DispositionType);
        }
Пример #5
0
        public void ParseContentDispositionFilenameWithEncoding2()
        {
            const string contentDispositionString =
                "attachment; filename*=ISO-8859-1\'\'Ans%E6ttelseskontrakt.pdf";

            ContentDisposition contentDisposition = HeaderFieldParser.ParseContentDisposition(contentDispositionString);

            Assert.AreEqual("Ansættelseskontrakt.pdf", contentDisposition.FileName);
        }
Пример #6
0
        public void ParseContentDispositionWithFilenameInQuotes()
        {
            const string contentDispositionString =
                "attachment; filename=\"49139-msg.jpg\"";

            ContentDisposition contentDisposition = HeaderFieldParser.ParseContentDisposition(contentDispositionString);

            Assert.AreEqual("49139-msg.jpg", contentDisposition.FileName);
        }
Пример #7
0
        public static void ContentDispositionSimpleAttachment()
        {
            const string contentDispositionString = "attachment";

            ContentDisposition contentDisposition = HeaderFieldParser.ParseContentDisposition(contentDispositionString);

            Assert.IsFalse(contentDisposition.Inline);
            Assert.AreEqual("attachment", contentDisposition.DispositionType);
        }
Пример #8
0
        public void TestContentTransferEncodingQoutedPrintableFunnyCase()
        {
            const string contentTransferEncodingString =
                "quOTed-pRinTabLE";

            ContentTransferEncoding encoding = HeaderFieldParser.ParseContentTransferEncoding(contentTransferEncodingString);

            Assert.AreEqual(ContentTransferEncoding.QuotedPrintable, encoding);
        }
Пример #9
0
        public void ParseContentDispositionFilenameWithEncodedWord()
        {
            const string contentDispositionString =
                "attachment; filename=\"=?utf-8?B?w5huc2tlIGluZGvDuGJzbGlzdGUuZG9j?=\"";

            ContentDisposition contentDisposition = HeaderFieldParser.ParseContentDisposition(contentDispositionString);

            Assert.AreEqual("Ønske indkøbsliste.doc", contentDisposition.FileName);
        }
Пример #10
0
        public void TestContentTransferEncodingBase64()
        {
            const string contentTransferEncodingString =
                "base64";

            ContentTransferEncoding encoding = HeaderFieldParser.ParseContentTransferEncoding(contentTransferEncodingString);

            Assert.AreEqual(ContentTransferEncoding.Base64, encoding);
        }
Пример #11
0
        public void TestContentTransferEncoding7Bit()
        {
            const string contentTransferEncodingString =
                "7bit";

            ContentTransferEncoding encoding = HeaderFieldParser.ParseContentTransferEncoding(contentTransferEncodingString);

            Assert.AreEqual(ContentTransferEncoding.SevenBit, encoding);
        }
Пример #12
0
        public void TestContentTransferEncodingBinary()
        {
            const string contentTransferEncodingString =
                "binary";

            ContentTransferEncoding encoding = HeaderFieldParser.ParseContentTransferEncoding(contentTransferEncodingString);

            Assert.AreEqual(ContentTransferEncoding.Binary, encoding);
        }
Пример #13
0
        public void ParseContentDispositionWithEncodedWordLong()
        {
            const string contentDispositionString =
                "attachment; filename=\"=?iso-8859-1?Q?Br=F8drenes_Jagtklub_-_Referat_af_generalforsamling.doc?=\"";

            ContentDisposition contentDisposition = HeaderFieldParser.ParseContentDisposition(contentDispositionString);

            Assert.AreEqual("Brødrenes Jagtklub - Referat af generalforsamling.doc", contentDisposition.FileName);
        }
Пример #14
0
        public void TestContentTransferEncodingQuotedPrintable()
        {
            const string contentTransferEncodingString =
                "quoted-printable";

            ContentTransferEncoding encoding = HeaderFieldParser.ParseContentTransferEncoding(contentTransferEncodingString);

            Assert.AreEqual(ContentTransferEncoding.QuotedPrintable, encoding);
        }
Пример #15
0
        public void TestContentTypeCharacterSet()
        {
            const string contentTypeString =
                "text/html; charset=\"iso-8859-1\"";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.AreEqual("text/html", contentType.MediaType);
            Assert.AreEqual("iso-8859-1", contentType.CharSet);
        }
Пример #16
0
        public void TestNoKeyValuesGetsIgnored()
        {
            //Test that values that don't have a key after the first one (which is the media type) do not override the media type
            const string contentTypeString = "text/html;iso-8859-1";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.NotNull(contentType);
            Assert.AreEqual("text/html", contentType.MediaType);
        }
Пример #17
0
        public void TestWhitespaceStrippedFromMediaType()
        {
            const string contentTypeString =
                "application/vnd.openxmlformats-officedocument.wordprocessingml.documen \r\n\tt";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.NotNull(contentType);
            Assert.AreEqual("application/vnd.openxmlformats-officedocument.wordprocessingml.document", contentType.MediaType);
        }
Пример #18
0
        public void ParseContentDispositionSizeInQuotes()
        {
            const string contentDispositionString =
                "attachment;" +
                " size=\"104710\"";

            ContentDisposition contentDisposition = HeaderFieldParser.ParseContentDisposition(contentDispositionString);

            Assert.AreEqual(104710, contentDisposition.Size);
        }
Пример #19
0
        public void TestContentTypeWithFilenameIncludingSemicolon()
        {
            const string contentTypeString =
                "application/msword; name=\"NUMMER; 251478.doc\"";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.AreEqual("application/msword", contentType.MediaType);
            Assert.AreEqual("NUMMER; 251478.doc", contentType.Name);
        }
Пример #20
0
        public void TestContentTypeWithExcessEndingSemicolonAndWhitespace()
        {
            const string contentTypeString =
                "application/vnd.ms-excel;name=\"MMSCecpmcountry12_06_2010.xls\"; ";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.AreEqual("application/vnd.ms-excel", contentType.MediaType);
            Assert.AreEqual("MMSCecpmcountry12_06_2010.xls", contentType.Name);
        }
Пример #21
0
        public void ParseContentDispositionFilenameLargeFirstCharacter()
        {
            const string contentDispositionString =
                "attachment;" +
                " Filename=\"test.csv\";";

            ContentDisposition contentDisposition = HeaderFieldParser.ParseContentDisposition(contentDispositionString);

            Assert.AreEqual("test.csv", contentDisposition.FileName);
        }
Пример #22
0
        public void TestContentTypeBoundary()
        {
            const string contentTypeString =
                "multipart/mixed; boundary=\"_004_76C5825B768EE04E99BD2EAC9C43507557EDD335B3server1hqcbbe_\"";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.AreEqual("multipart/mixed", contentType.MediaType);
            Assert.AreEqual("_004_76C5825B768EE04E99BD2EAC9C43507557EDD335B3server1hqcbbe_", contentType.Boundary);
        }
Пример #23
0
        public void TestContentTypeLongMediaType()
        {
            const string contentTypeString =
                "application/vnd.openxmlformats-officedocument.wordprocessingml.document; name=\"Hej.docx\"";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.AreEqual("application/vnd.openxmlformats-officedocument.wordprocessingml.document", contentType.MediaType);
            Assert.AreEqual("Hej.docx", contentType.Name);
        }
Пример #24
0
        public void TestContentTypeWithSpace()
        {
            const string contentTypeString =
                "image/gif; name=\"aleabanr.gif\"";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.AreEqual("aleabanr.gif", contentType.Name);
            Assert.AreEqual("image/gif", contentType.MediaType);
        }
Пример #25
0
        public void TestContentTypeFilenameInQoutes2()
        {
            const string contentTypeString =
                "image/jpeg;name=\"Rejsebazar_Kbh(2).jpg\"";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.AreEqual("Rejsebazar_Kbh(2).jpg", contentType.Name);
            Assert.AreEqual("image/jpeg", contentType.MediaType);
        }
Пример #26
0
        public void TestContentTypeFilenameInQoutes()
        {
            const string contentTypeString =
                "image/gif;name=\"gradient.gif\"";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.AreEqual("gradient.gif", contentType.Name);
            Assert.AreEqual("image/gif", contentType.MediaType);
        }
Пример #27
0
        public void TestContentTypeWithEncodedWordInName()
        {
            const string contentTypeString =
                "application/msword; name=\"=?Windows-1252?Q?revideret_forel=F8big_dagsorden_090110_version_2.doc?=\"";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.AreEqual("revideret foreløbig dagsorden 090110 version 2.doc", contentType.Name);
            Assert.AreEqual("application/msword", contentType.MediaType);
        }
Пример #28
0
        public void TestContentTypeWithNameEncoding()
        {
            const string contentTypeString =
                "application/pdf; name*=ISO-8859-1\'\'Ans%E6ttelseskontrakt.pdf";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.AreEqual("Ansættelseskontrakt.pdf", contentType.Name);
            Assert.AreEqual("application/pdf", contentType.MediaType);
        }
Пример #29
0
        public void TestContentTypeNameWithoutQuotes()
        {
            const string contentTypeString =
                "application/vnd.oasis.opendocument.text; name=Til";

            ContentType contentType = HeaderFieldParser.ParseContentType(contentTypeString);

            Assert.AreEqual("application/vnd.oasis.opendocument.text", contentType.MediaType);
            Assert.AreEqual("Til", contentType.Name);
        }
Пример #30
0
        public void ParseContentDispoistionWithNameParameter()
        {
            const string contentDispositionString =
                "attachment; name=\"010294-0011841.pdf\"; filename=\"010294-0011841.pdf\"";

            ContentDisposition contentDisposition = HeaderFieldParser.ParseContentDisposition(contentDispositionString);

            Assert.AreEqual("010294-0011841.pdf", contentDisposition.FileName);
            Assert.IsFalse(contentDisposition.Inline);
        }