コード例 #1
0
        public void testPartsNoCR()
        {
            String eol        = "\n";
            String partString = eol +
                                BOUNDARY + eol +
                                "Content-Type: text/plain" + eol +
                                "Content-Range: bytes 27-28/30" + eol +
                                eol +
                                "ag" + eol +
                                BOUNDARY + eol +
                                "Content-Type: text/plain" + eol +
                                "Content-Range: bytes 9-9/30" + eol +
                                eol +
                                "e" + eol +
                                BOUNDARY + eol +
                                "Content-Type: text/plain" + eol +
                                "Content-Range: bytes 5-5/30" + eol +
                                eol +
                                "s" + eol +
                                BOUNDARY + eol +
                                "Content-Type: text/plain" + eol +
                                "Content-Range: bytes 4-4/30" + eol +
                                eol +
                                " " + eol +
                                BOUNDARY + eol +
                                "Content-Type: text/plain" + eol +
                                "Content-Range: bytes 27-29/30" + eol +
                                eol +
                                "ago" + eol +
                                BOUNDARY + "--" + eol;
            MultipartEntity entity = MultipartEntity.FromStream(new MemoryStream(Encoding.UTF8.GetBytes(partString)),
                                                                BOUNDARY);

            Assert.AreEqual(entity.Count(), 5, "Wrong number of parts");
            Assert.AreEqual(entity[0].ContentType, "text/plain", "Part 1 content type is wrong");
            Assert.AreEqual(entity[0].ContentExtent, new Extent(27, 2), "Part 1 range is wrong");
            Assert.IsTrue(entity[0].Data.SequenceEqual(Encoding.UTF8.GetBytes("ag")), "Part 1 data is wrong");
            Assert.AreEqual(entity[1].ContentType, "text/plain", "Part 2 content type is wrong");
            Assert.AreEqual(entity[1].ContentExtent, new Extent(9, 1), "Part 2 range is wrong");
            Assert.IsTrue(entity[1].Data.SequenceEqual(Encoding.UTF8.GetBytes("e")), "Part 2 data is wrong");
            Assert.AreEqual(entity[2].ContentType, "text/plain", "Part 3 content type is wrong");
            Assert.AreEqual(entity[2].ContentExtent, new Extent(5, 1), "Part 3 range is wrong");
            Assert.IsTrue(entity[2].Data.SequenceEqual(Encoding.UTF8.GetBytes("s")), "Part 3 data is wrong");
            Assert.AreEqual(entity[3].ContentType, "text/plain", "Part 4 content type is wrong");
            Assert.AreEqual(entity[3].ContentExtent, new Extent(4, 1), "Part 4 range is wrong");
            Assert.IsTrue(entity[3].Data.SequenceEqual(Encoding.UTF8.GetBytes(" ")), "Part 4 data is wrong");
            Assert.AreEqual(entity[4].ContentType, "text/plain", "Part 5 content type is wrong");
            Assert.AreEqual(entity[4].ContentExtent, new Extent(27, 3), "Part 5 range is wrong");
            Assert.IsTrue(entity[4].Data.SequenceEqual(Encoding.UTF8.GetBytes("ago")), "Part 5 data is wrong");
        }
コード例 #2
0
        public void testOnePart()
        {
            String eol        = "\n";
            String partString = eol +
                                BOUNDARY + eol +
                                "Content-Type: text/plain" + eol +
                                "Content-Range: bytes 27-28/30" + eol +
                                eol +
                                "ag" + eol +
                                BOUNDARY + "--" + eol;
            MultipartEntity entity = MultipartEntity.FromStream(new MemoryStream(Encoding.UTF8.GetBytes(partString)),
                                                                BOUNDARY);

            Assert.AreEqual(entity.Count(), 1, "Wrong number of parts");
            Assert.AreEqual(entity[0].ContentType, "text/plain", "Part 1 content type is wrong");
            Assert.AreEqual(entity[0].ContentExtent, new Extent(27, 2), "Part 1 range is wrong");
            Assert.IsTrue(entity[0].Data.SequenceEqual(Encoding.UTF8.GetBytes("ag")), "Part 1 data is wrong");
        }