public async Task PostProcessing_ProcessesFormData_WithCustomMultipartFormDataStreamProvider()
        {
            // Arrange
            string tempPath       = Path.GetTempPath();
            int    maxContents    = 16;
            string contentFormat  = "Content {0}";
            string formNameFormat = "FormName_{0}";
            string fileNameFormat = "FileName_{0}";

            MultipartFormDataContent multipartContent = new MultipartFormDataContent();

            // Create half contents for form data and the other half for file data.
            for (int index = 0; index < maxContents; index++)
            {
                string content  = String.Format(contentFormat, index);
                string formName = String.Format(formNameFormat, index);
                if (index < maxContents / 2)
                {
                    multipartContent.Add(new StringContent(content), formName);
                }
                else
                {
                    string fileName = String.Format(fileNameFormat, index);
                    multipartContent.Add(new StringContent(content), formName, fileName);
                }
            }

            CustomMultipartFormDataStreamProvider provider =
                new CustomMultipartFormDataStreamProvider(tempPath);

            foreach (HttpContent content in multipartContent)
            {
                provider.Contents.Add(content);
                using (provider.GetStream(multipartContent, content.Headers)) { }
            }

            // Act
            await provider.ExecutePostProcessingAsync();

            // Assert
            Assert.Equal(maxContents / 2, provider.FormData.Count);

            // half contents for form data
            for (int index = 0; index < maxContents / 2; index++)
            {
                string content  = String.Format(contentFormat, index);
                string formName = String.Format(formNameFormat, index);
                Assert.Equal(content, provider.FormData[formName]);
            }

            // the other half for file data
            HttpContent[] contents = multipartContent.ToArray();
            for (int index = maxContents / 2; index < maxContents; index++)
            {
                int    fileDataIndex = index - (maxContents / 2);
                string fileName      = String.Format(fileNameFormat, index);
                Assert.Equal(fileName, provider.FileData[fileDataIndex].LocalFileName);
                Assert.Same(contents[index].Headers, provider.FileData[fileDataIndex].Headers);
            }
        }
        public async void PostProcessing_ProcessesFormData()
        {
            // Arrange
            int    maxContents    = 16;
            string contentFormat  = "Content {0}";
            string formNameFormat = "FormName_{0}";
            string fileNameFormat = "FileName_{0}";

            MultipartFormDataContent multipartContent = new MultipartFormDataContent();

            // Create half contents for form data and the other half for file data.
            for (int index = 0; index < maxContents; index++)
            {
                string content  = String.Format(contentFormat, index);
                string formName = String.Format(formNameFormat, index);
                if (index < maxContents / 2)
                {
                    multipartContent.Add(new StringContent(content), formName);
                }
                else
                {
                    string fileName = String.Format(fileNameFormat, index);
                    multipartContent.Add(new StringContent(content), formName, fileName);
                }
            }

            CustomMultipartFormDataRemoteStreamProvider provider =
                new CustomMultipartFormDataRemoteStreamProvider();

            foreach (HttpContent content in multipartContent)
            {
                provider.Contents.Add(content);
                using (provider.GetStream(multipartContent, content.Headers))
                {
                }
            }

            // Act
            Task  processingTask = provider.ExecutePostProcessingAsync();
            await processingTask;

            // Assert
            Assert.Equal(TaskStatus.RanToCompletion, processingTask.Status);
            Assert.Equal(maxContents / 2, provider.FormData.Count);

            // half contents for form data
            for (int index = 0; index < maxContents / 2; index++)
            {
                string content  = String.Format(contentFormat, index);
                string formName = String.Format(formNameFormat, index);
                Assert.Equal(content, provider.FormData[formName]);
            }

            // the other half for file data
            HttpContent[] contents = multipartContent.ToArray();
            for (int index = maxContents / 2; index < maxContents; index++)
            {
                int    fileDataIndex = index - (maxContents / 2);
                string fileName      = String.Format(fileNameFormat, index);
                string url           = provider.UrlBase + fileName;
                Assert.Equal(url, provider.FileData[fileDataIndex].Location);
                Assert.Same(contents[index].Headers, provider.FileData[fileDataIndex].Headers);
            }
        }