Пример #1
0
        public void ParseMessageWithTwoParts()
        {
            string contentType = "multipart/mixed; boundary=\"abcd\"";
            string content     = "\r\n--abcd\r\nContent-Type: application/xml;charset=UTF-8\r\n\r\n<movie>...</movie>\r\n--abcd\r\n\r\nplain text\r\n--abcd--";

            MultipartMessage message = ParseMessage(contentType, content);

            Assert.IsTrue(message.IsMultipart);
            Assert.AreEqual(MultipartMessage.MediaTypeMultipartMixed, message.MediaType);
            Assert.AreEqual("abcd", message.Boundary);
            Assert.AreEqual(2, message.Parts.Count);

            MultipartMessagePart part = message.Parts[0];

            Assert.IsTrue(part.HasHeader("content-type"));
            Assert.AreEqual("application/xml", part.GetHeader("content-type").FieldValue);
            Assert.AreEqual("<movie>...</movie>", Encoding.UTF8.GetString(part.Data));
        }
Пример #2
0
        public void ParseMessageWithBoundaryWithoutQuotes()
        {
            string contentType = "multipart/mixed; boundary=abcd";
            string content     = "\r\n--abcd\r\nContent-Type: application/xml;charset=UTF-8\r\n\r\n<movie>...</movie>\r\n--abcd--";

            MultipartMessage message = StartReading(contentType, content);

            Assert.IsTrue(message.IsMultipart);
            Assert.AreEqual(MultipartMessage.MediaTypeMultipartMixed, message.MediaType);
            Assert.AreEqual("abcd", message.Boundary);

            MultipartMessagePart part = reader.ReadNextPart();

            Assert.IsTrue(part.HasHeader("content-type"));
            Assert.AreEqual("application/xml", part.GetHeader("content-type").FieldValue);
            Assert.AreEqual("<movie>...</movie>", Encoding.UTF8.GetString(part.Data));

            Assert.IsNull(reader.ReadNextPart());
        }