public void TestMultipart()
        {
            MultiPart parts;

            using (MemoryStream stream = new MemoryStream(exampleBytes))
            {
                parts = MultiPart.Parse(stream);
            }

            foreach (MultiPartSection section in parts.Sections)
            {
                System.Console.WriteLine("New Section");
                System.Console.WriteLine($"FileName: {section.FileName}");
                System.Console.WriteLine($"Name: {section.Name}");
                System.Console.WriteLine($"Content-Type: {section.ContentType}");
                System.Console.WriteLine($"Content: {section.DataAsString}");
                System.Console.WriteLine("-------------------");
            }


            Assert.AreEqual(3, parts.Sections.Count, "Not the correct amount of sections");
            Assert.IsNotNull(parts.Sections.FirstOrDefault(x => x.Name == "text"), "Missing Section");
            Assert.IsNotNull(parts.Sections.FirstOrDefault(x => x.Name == "file1"), "Missing Section");
            Assert.IsNotNull(parts.Sections.FirstOrDefault(x => x.Name == "file2"), "Missing Section");
            Assert.AreEqual(section1Data, parts.Sections.FirstOrDefault(x => x.Name == "text")?.DataAsString, "Incorrect data");
            Assert.AreEqual(section2Data, parts.Sections.FirstOrDefault(x => x.Name == "file1")?.DataAsString, "Incorrect data");
            Assert.AreEqual(section3Data, parts.Sections.FirstOrDefault(x => x.Name == "file2")?.DataAsString, "Incorrect data");
        }
Exemple #2
0
        private void parseStreamWithBoundary()
        {
            string fullBoundary = new string(HYPHEN_CHAR, 2) + m_Boundary;

            foreach (var segment in StreamHelpers.StreamSplitNew(m_Stream, m_Encoding.GetBytes(fullBoundary)))
            {
                var part = MultiPart.Parse(segment.Item1, segment.Item2, m_Encoding);
                m_Parts.Add(part);
            }
        }
Exemple #3
0
        private void parseStream(Stream stream, string boundary, Encoding encoding)
        {
            m_Stream = stream;
            string fullBoundary = new string(HYPHEN_CHAR, 2) + boundary;

            foreach (var segment in StreamHelpers.StreamSplitNew(stream, Encoding.UTF8.GetBytes(fullBoundary)))
            {
                var part = MultiPart.Parse(segment.Item1, segment.Item2);
                m_parts.Add(part);
            }
        }