public void GetStreamValidation()
        {
            Stream stream0 = null;
            Stream stream1 = null;

            try
            {
                MultipartFormDataContent content = new MultipartFormDataContent();
                content.Add(new StringContent("Not a file"), "notafile");
                content.Add(new StringContent("This is a file"), "file", "filename");

                MultipartFormDataStreamProvider instance = new MultipartFormDataStreamProvider(Path.GetTempPath());
                stream0 = instance.GetStream(content.ElementAt(0).Headers);
                Assert.IsType <MemoryStream>(stream0);
                stream1 = instance.GetStream(content.ElementAt(1).Headers);
                Assert.IsType <FileStream>(stream1);

                Assert.Equal(1, instance.BodyPartFileNames.Count);
                Assert.Contains("BodyPart", instance.BodyPartFileNames.Values.ElementAt(0));
            }
            finally
            {
                if (stream0 != null)
                {
                    stream0.Close();
                }

                if (stream1 != null)
                {
                    stream1.Close();
                }
            }
        }
        public void GetStreamValidation()
        {
            Stream stream0 = null;
            Stream stream1 = null;

            try
            {
                MultipartFormDataContent content = new MultipartFormDataContent();
                content.Add(new StringContent("Not a file"), "notafile");
                content.Add(new StringContent("This is a file"), "file", "filename");

                MultipartFileStreamProvider instance = new MultipartFileStreamProvider(Path.GetTempPath());
                stream0 = instance.GetStream(content.ElementAt(0).Headers);
                Assert.IsType<FileStream>(stream0);
                stream1 = instance.GetStream(content.ElementAt(1).Headers);
                Assert.IsType<FileStream>(stream1);

                Assert.Equal(2, instance.BodyPartFileNames.Count);
                Assert.Contains("BodyPart", instance.BodyPartFileNames[0]);
                Assert.Contains("BodyPart", instance.BodyPartFileNames[1]);
            }
            finally
            {
                if (stream0 != null)
                {
                    stream0.Close();
                }

                if (stream1 != null)
                {
                    stream1.Close();
                }
            }
        }
        public void GetStream()
        {
            Stream stream0 = null;
            Stream stream1 = null;

            try
            {
                string tempPath = Path.GetTempPath();
                MultipartFormDataContent content = new MultipartFormDataContent();
                content.Add(new StringContent("Content 1"), "NoFile");
                content.Add(new StringContent("Content 2"), "File", "Filename");

                MultipartFileStreamProvider provider = new MultipartFileStreamProvider(tempPath);
                stream0 = provider.GetStream(content, content.ElementAt(0).Headers);
                stream1 = provider.GetStream(content, content.ElementAt(1).Headers);

                Assert.IsType <FileStream>(stream0);
                Assert.IsType <FileStream>(stream1);

                Assert.Equal(2, provider.FileData.Count);
                string partialFileName = String.Format("{0}BodyPart_", tempPath);
                Assert.Contains(partialFileName, provider.FileData[0].LocalFileName);
                Assert.Contains(partialFileName, provider.FileData[1].LocalFileName);

                Assert.Same(
                    content.ElementAt(0).Headers.ContentDisposition,
                    provider.FileData[0].Headers.ContentDisposition
                    );
                Assert.Same(
                    content.ElementAt(1).Headers.ContentDisposition,
                    provider.FileData[1].Headers.ContentDisposition
                    );
            }
            finally
            {
                if (stream0 != null)
                {
                    stream0.Close();
                }

                if (stream1 != null)
                {
                    stream1.Close();
                }
            }
        }
        public void GetStream()
        {
            // Arrange
            Stream stream0 = null;
            Stream stream1 = null;

            try
            {
                MultipartFormDataContent content = new MultipartFormDataContent();
                content.Add(new StringContent("Content 1"), "NoFile");
                content.Add(new StringContent("Content 2"), "File", "Filename");

                CustomMultipartFormDataRemoteStreamProvider provider =
                    new CustomMultipartFormDataRemoteStreamProvider();

                // Act
                stream0 = provider.GetStream(content, content.ElementAt(0).Headers);
                stream1 = provider.GetStream(content, content.ElementAt(1).Headers);

                // Assert
                Assert.IsType <MemoryStream>(stream0);
                Assert.Single(provider.RemoteStreams, stream1);

                MultipartRemoteFileData fileData = Assert.Single(provider.FileData);
                string expectedUrl = provider.UrlBase + "Filename";
                Assert.Equal(expectedUrl, fileData.Location);

                Assert.Same(
                    content.ElementAt(1).Headers.ContentDisposition,
                    fileData.Headers.ContentDisposition
                    );
            }
            finally
            {
                if (stream0 != null)
                {
                    stream0.Close();
                }

                if (stream1 != null)
                {
                    stream1.Close();
                }
            }
        }
        public void GetStream_StreamResultNullThrowsException()
        {
            // Arrange
            MultipartFormDataContent content = new MultipartFormDataContent();

            content.Add(new StringContent("Content"), "File", "Filename");
            CustomMultipartFormDataRemoteStreamProvider provider =
                new CustomMultipartFormDataRemoteStreamProvider(isResultNull: true);

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () => provider.GetStream(content, content.ElementAt(0).Headers),
                "The 'GetRemoteStream' method in 'CustomMultipartFormDataRemoteStreamProvider' returned null. " +
                "It must return a RemoteStreamResult instance containing a writable stream and a valid URL."
                );
        }
        private async Task ValidateSubscriptionContent(MultipartFormDataContent content, int index, string name, string value)
        {
            StringContent parameter = (StringContent)content.ElementAt(index);
            string actual = await parameter.ReadAsStringAsync();

            Assert.Equal(value, actual);
            Assert.Null(parameter.Headers.ContentType);
            ContentDispositionHeaderValue cd = parameter.Headers.ContentDisposition;
            Assert.Equal(name, cd.Name);
        }