public void TestAllFirstMessagesWithMediaTypeSimpleNotFound() { const string rfcExample = "Content-type: text/plain; charset=us-ascii\r\n" + "\r\n" + "This is explicitly typed plain US-ASCII text"; OPMessage message = new OPMessage(Encoding.ASCII.GetBytes(rfcExample)); System.Collections.Generic.List<MessagePart> parts = message.FindAllMessagePartsWithMediaType("text/html"); // We should not be able to find such a MessagePart Assert.NotNull(parts); Assert.IsEmpty(parts); }
public void TestGetAllMessagesWithMediaTypeMultiPartFindMultiPartMediaTypeWithMultipleMultiParts() { const string rfcExample = "From: Nathaniel Borenstein <*****@*****.**>\r\n" + "To: Ned Freed <*****@*****.**>\r\n" + "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\r\n" + "Subject: Sample message\r\n" + "MIME-Version: 1.0\r\n" + "Content-type: multipart/mixed; boundary=\"simple boundary\"\r\n" + "\r\n" + "--simple boundary\r\n" + "Content-type: multipart/mixed; boundary=\"anotherBoundary\"\r\n" + "\r\n" + "--anotherBoundary\r\n" + "\r\n" + "TEXT\r\n" + "--anotherBoundary\r\n" + "Content-Type: text/html; charset=us-ascii\r\n" + "\r\n" + "HTML\r\n" + "--anotherBoundary--\r\n" + "--simple boundary\r\n" + "Content-type: text/html; charset=ISO-8859-1\r\n" + "\r\n" + "MORE HTML\r\n" + "--simple boundary--"; OPMessage message = new OPMessage(Encoding.ASCII.GetBytes(rfcExample)); System.Collections.Generic.List<MessagePart> parts = message.FindAllMessagePartsWithMediaType("multipart/mixed"); Assert.NotNull(parts); Assert.IsNotEmpty(parts); Assert.AreEqual(2, parts.Count); MessagePart firstPart = parts[0]; Assert.IsTrue(firstPart.IsMultiPart); Assert.AreEqual("multipart/mixed", firstPart.ContentType.MediaType); Assert.AreEqual("simple boundary", firstPart.ContentType.Boundary); MessagePart secondPart = parts[1]; Assert.IsTrue(secondPart.IsMultiPart); Assert.AreEqual("multipart/mixed", secondPart.ContentType.MediaType); Assert.AreEqual("anotherBoundary", secondPart.ContentType.Boundary); }
public void TestGetAllMessagesWithMediaTypeSimpleFound() { const string rfcExample = "Content-type: text/plain; charset=us-ascii\r\n" + "\r\n" + "This is explicitly typed plain US-ASCII text"; OPMessage message = new OPMessage(Encoding.ASCII.GetBytes(rfcExample)); System.Collections.Generic.List<MessagePart> parts = message.FindAllMessagePartsWithMediaType("text/plain"); Assert.NotNull(parts); Assert.IsNotEmpty(parts); Assert.AreEqual(1, parts.Count); MessagePart foundMessagePart = parts[0]; Assert.AreEqual("text/plain", foundMessagePart.ContentType.MediaType); Assert.AreEqual("us-ascii", foundMessagePart.ContentType.CharSet); Assert.AreEqual(Encoding.ASCII, foundMessagePart.BodyEncoding); Assert.AreEqual("This is explicitly typed plain US-ASCII text", foundMessagePart.GetBodyAsText()); }