public void TestMultipartWriterGzipped() { var mp = new MultipartWriter("foo/bar", "BOUNDARY"); var data1 = Enumerable.Repeat((byte)'*', 100); mp.SetNextPartHeaders(new Dictionary <string, string> { { "Content-Type", "star-bellies" } }); mp.AddGZippedData(data1); var output = mp.AllOutput(); // Compression flags & OS type will differ depending on which platform this test is run on // So we need to compare for "almost" equality. In this particular output the compression // flags are on byte 97 and the os type is in byte 98 var expectedOutput = GetType().GetResourceAsStream("MultipartStars.mime").ReadAllBytes(); Assert.AreEqual(expectedOutput.Take(96), output.Take(96)); Assert.AreEqual(expectedOutput.Skip(98), output.Skip(98)); }
public void TestMultipartWriter() { const string expectedOutput = "\r\n--BOUNDARY\r\nContent-Length: 16\r\n\r\n<part the first>\r\n--BOUNDARY\r\nContent-Length: " + "10\r\nContent-Type: something\r\n\r\n<2nd part>\r\n--BOUNDARY--"; for (var bufSize = 1; bufSize < expectedOutput.Length - 1; ++bufSize) { var mp = new MultipartWriter("foo/bar", "BOUNDARY"); Assert.AreEqual("foo/bar; boundary=\"BOUNDARY\"", mp.ContentType); Assert.AreEqual("BOUNDARY", mp.Boundary); mp.AddData(Encoding.UTF8.GetBytes("<part the first>")); mp.SetNextPartHeaders(new Dictionary <string, string> { { "Content-Type", "something" } }); mp.AddData(Encoding.UTF8.GetBytes("<2nd part>")); Assert.AreEqual(expectedOutput.Length, mp.Length); var output = mp.AllOutput(); Assert.IsNotNull(output); Assert.AreEqual(expectedOutput, Encoding.UTF8.GetString(output.ToArray())); mp.Close(); } }