public void testDelimiterDetection()
        {

            log.enteredMethod();

            String[] multipartLines = {
                                          "",
                                          "-----------------------------114782935826962",
                                         "Content-Disposition: form-data; name=\"datafile\"; filename=\"test.txt\"",
                                         "Content-Type: text/plain",
                                         "",
                                         "0123",
                                         "4567",
                                         "89ab",
                                         "cdef",
                                         "-----------------------------114782935826962--",
                                     };

            Entity entity = buildEntity(multipartLines);
            MultiPartReader reader = new MultiPartReader("---------------------------114782935826962", entity);

            DelimiterIndicator indicator = reader.skipToNextDelimiterIndicator();
            Assert.NotNull(indicator);
            Assert.IsInstanceOf<DelimiterFound>(indicator);
            DelimiterFound delimiterFound = (DelimiterFound)indicator;

            Assert.AreEqual(0, delimiterFound.StartOfDelimiter);
            Assert.False(delimiterFound.IsCloseDelimiter);

            // Content-Disposition
            MutableData stringBuffer = new MutableData();
            String contentDisposition = reader.ReadLine(stringBuffer);
            Assert.AreEqual(multipartLines[2], contentDisposition);

            // Content-Type
            String contentType = reader.ReadLine(stringBuffer);
            Assert.AreEqual(multipartLines[3], contentType);

            // empty line
            String emptyLine = reader.ReadLine(stringBuffer);
            Assert.AreEqual("", emptyLine);

            // ending indicator
            indicator = reader.skipToNextDelimiterIndicator();
            Assert.NotNull(indicator);
            Assert.IsInstanceOf<DelimiterFound>(indicator);
            delimiterFound = (DelimiterFound)indicator;
            Assert.True(delimiterFound.IsCloseDelimiter);

        }
        static void testDoubleAttachments(String boundary, String contentSource, int length)
        {

            if (0 == length)
            {
                log.debugFormat(contentSource, "contentSource");
            }
            log.debug(length, "length");

            String attachment = buildAttachment(contentSource, length);
            Assert.AreEqual(length, attachment.Length);

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("\r\n--");
            stringBuilder.Append(boundary);
            stringBuilder.Append("\r\n");


            stringBuilder.Append("Content-Disposition: form-data; name=\"datafile\"; filename=\"test1.txt\"\r\n");
            stringBuilder.Append("Content-Type: text/plain\r\n");
            stringBuilder.Append("\r\n");
            stringBuilder.Append(attachment);

            stringBuilder.Append("\r\n--");
            stringBuilder.Append(boundary);
            stringBuilder.Append("\r\n");

            stringBuilder.Append("Content-Disposition: form-data; name=\"datafile\"; filename=\"test2.txt\"\r\n");
            stringBuilder.Append("Content-Type: text/plain\r\n");
            stringBuilder.Append("\r\n");
            stringBuilder.Append(attachment);

            stringBuilder.Append("\r\n--");
            stringBuilder.Append(boundary);
            stringBuilder.Append("--\r\n");


            Entity entity = buildEntity(stringBuilder.ToString());
            MultiPartReader reader = new MultiPartReader(boundary, entity);

            TestMultiPartHandler testMultiPartHandler = new TestMultiPartHandler();
            reader.Process(testMultiPartHandler);
            Assert.True(testMultiPartHandler._foundCloseDelimiter);

            Assert.AreEqual(2, testMultiPartHandler._partHandlers.Count);

            {
                TestPartHandler firstTestPartHandler = testMultiPartHandler._partHandlers[0];
                Assert.AreEqual(attachment.Length, firstTestPartHandler._data.Length);
                String actualContent = DataHelper.ToUtf8String(firstTestPartHandler._data);
                Assert.AreEqual(attachment, actualContent);
            }

            {
                TestPartHandler secondTestPartHandler = testMultiPartHandler._partHandlers[1];
                Assert.AreEqual(attachment.Length, secondTestPartHandler._data.Length);
                String actualContent = DataHelper.ToUtf8String(secondTestPartHandler._data);
                Assert.AreEqual(attachment, actualContent);
            }


        }
        public void TestDoubleMultiPartForm()
        {

            log.enteredMethod();

            String[] multipartLines = {
                                          "",
                                          "-----------------------------114782935826962",
                                         "Content-Disposition: form-data; name=\"datafile\"; filename=\"test1.txt\"",
                                         "Content-Type: text/plain",
                                         "",
                                         "0123",
                                         "4567",
                                         "89ab",
                                         "cdef",
                                         "-----------------------------114782935826962",
                                         "Content-Disposition: form-data; name=\"datafile\"; filename=\"test2.txt\"",
                                         "Content-Type: text/plain",
                                         "",
                                         "cdef",
                                         "89ab",
                                         "4567",
                                         "0123",
                                         "-----------------------------114782935826962--",
                                     };

            Entity entity = buildEntity(multipartLines);
            MultiPartReader reader = new MultiPartReader("---------------------------114782935826962", entity);

            TestMultiPartHandler testMultiPartHandler = new TestMultiPartHandler();
            reader.Process(testMultiPartHandler);
            Assert.True(testMultiPartHandler._foundCloseDelimiter);

            Assert.AreEqual(2, testMultiPartHandler._partHandlers.Count);

            {
                TestPartHandler firstTestPartHandler = testMultiPartHandler._partHandlers[0];
                Assert.AreEqual(16 + 6, firstTestPartHandler._data.Length);
                String expectedContent = "0123\r\n4567\r\n89ab\r\ncdef";
                String actualContent = DataHelper.ToUtf8String(firstTestPartHandler._data);
                Assert.AreEqual(expectedContent, actualContent);
            }

            {
                TestPartHandler secondTestPartHandler = testMultiPartHandler._partHandlers[1];
                Assert.AreEqual(16 + 6, secondTestPartHandler._data.Length);
                String expectedContent = "cdef\r\n89ab\r\n4567\r\n0123";
                String actualContent = DataHelper.ToUtf8String(secondTestPartHandler._data);
                Assert.AreEqual(expectedContent, actualContent);
            }
        }