public void ParseHeaderWithoutParameters() { HeaderField field = HeaderField.Parse("Content-type : multipart/mixed"); Assert.AreEqual("Content-type", field.FieldName); Assert.AreEqual(MultipartMessage.MediaTypeMultipartMixed, field.FieldValue); Assert.AreEqual(0, field.Parameters.Count); Assert.AreEqual("Content-type: multipart/mixed", field.ToString()); }
public void ParseHeaderWithParameters2() { HeaderField field = HeaderField.Parse("Content-Disposition: attachment; filename=test.pdf"); Assert.AreEqual("Content-Disposition", field.FieldName); Assert.AreEqual("attachment", field.FieldValue); Assert.AreEqual(1, field.Parameters.Count); Assert.AreEqual("test.pdf", field.Parameters["filename"]); }
public void ParseHeaderWithParameters() { HeaderField field = HeaderField.Parse("Content-type: multipart/mixed; boundary=\"23232\"; test=2"); Assert.AreEqual("Content-type", field.FieldName); Assert.AreEqual(MultipartMessage.MediaTypeMultipartMixed, field.FieldValue); Assert.AreEqual(2, field.Parameters.Count); Assert.AreEqual("\"23232\"", field.Parameters["boundary"]); Assert.AreEqual("2", field.Parameters["test"]); Assert.AreEqual("Content-type: multipart/mixed; boundary=\"23232\"; test=2", field.ToString()); }
public void WriteMessageAsAWhole() { string boundary = "-----Test"; MultipartMessage message = new MultipartMessage(HeaderField.Parse("Content-type: multipart/mixed; boundary=-----Test")); MultipartMessagePart part; part = new MultipartMessagePart(); part.AddHeader(new HeaderField("Content-Type", "text/plain")); part.Data = Encoding.UTF8.GetBytes("my text"); message.AddPart(part); part = new MultipartMessagePart(); part.AddHeader(new HeaderField("Content-Type", "application/xml")); part.Data = Encoding.UTF8.GetBytes("<tag/>"); message.AddPart(part); using (MemoryStream stream = new MemoryStream()) { long writtenBytes; using (MultipartStreamWriter writer = new MultipartStreamWriter( stream, boundary, Encoding.UTF8)) { writer.WriteWholeMessage(message); writtenBytes = writer.BytesWritten; } byte[] bytes = stream.ToArray(); Assert.AreEqual(bytes.Length, writtenBytes); string result = Encoding.UTF8.GetString(bytes); Assert.AreEqual("\r\n-------Test\r\nContent-Type: text/plain\r\n\r\nmy text\r\n-------Test\r\nContent-Type: application/xml\r\n\r\n<tag/>\r\n-------Test--", result); } }