You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
packages
src
test
Microsoft.TestCommon
Microsoft.Web.Helpers.Test
Microsoft.Web.Http.Data.Test
Microsoft.Web.Mvc.Test
Microsoft.Web.WebPages.OAuth.Test
SPA.Test
System.Json.Test.Integration
System.Json.Test.Unit
System.Net.Http.Formatting.Test.Integration
System.Net.Http.Formatting.Test.Unit
DataSets
Formatting
Headers
Internal
Mocks
Properties
FormattingUtilitiesTests.cs
HttpClientExtensionsTest.cs
HttpContentCollectionExtensionsTests.cs
HttpContentExtensionsTest.cs
HttpContentMessageExtensionsTests.cs
HttpContentMultipartExtensionsTests.cs
HttpMessageContentTests.cs
HttpRequestHeadersExtensionsTest.cs
HttpRequestMessageCommonExtensionsTest.cs
HttpResponseHeadersExtensionsTest.cs
MultipartFileStreamProviderTests.cs
MultipartFormDataStreamProviderTests.cs
MultipartMemoryStreamProviderTests.cs
ObjectContentOfTTests.cs
ObjectContentTests.cs
ParserData.cs
System.Net.Http.Formatting.Test.Unit.csproj
UriExtensionsTests.cs
UriQueryDataSet.cs
UriQueryUtilityTests.cs
packages.config
System.Web.Helpers.Test
System.Web.Http.Integration.Test
System.Web.Http.SelfHost.Test
System.Web.Http.Test
System.Web.Http.WebHost.Test
System.Web.Mvc.Test
System.Web.Razor.Test
System.Web.WebPages.Administration.Test
System.Web.WebPages.Deployment.Test
System.Web.WebPages.Razor.Test
System.Web.WebPages.Test
WebMatrix.Data.Test
WebMatrix.WebData.Test
Settings.StyleCop
tools
.gitattributes
.gitignore
License.txt
README.md
Runtime.msbuild
Runtime.sln
Runtime.xunit
Settings.StyleCop
build.cmd
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
libgc
llvm
m4
man
mcs
mk
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
116 lines
4.6 KiB
C#
116 lines
4.6 KiB
C#
![]() |
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
|
|||
|
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
using Microsoft.TestCommon;
|
|||
|
using Xunit;
|
|||
|
using Assert = Microsoft.TestCommon.AssertEx;
|
|||
|
|
|||
|
namespace System.Net.Http
|
|||
|
{
|
|||
|
public class MultipartFormDataStreamProviderTests
|
|||
|
{
|
|||
|
private const int MinBufferSize = 1;
|
|||
|
private const int DefaultBufferSize = 0x1000;
|
|||
|
private const string ValidPath = @"c:\some\path";
|
|||
|
|
|||
|
[Fact]
|
|||
|
[Trait("Description", "MultipartFormDataStreamProvider is public, visible type.")]
|
|||
|
public void TypeIsCorrect()
|
|||
|
{
|
|||
|
Assert.Type.HasProperties(
|
|||
|
typeof(MultipartFormDataStreamProvider),
|
|||
|
TypeAssert.TypeProperties.IsPublicVisibleClass,
|
|||
|
typeof(IMultipartStreamProvider));
|
|||
|
}
|
|||
|
|
|||
|
[Fact]
|
|||
|
[Trait("Description", "MultipartFormDataStreamProvider ctor with invalid root paths.")]
|
|||
|
public void ConstructorInvalidRootPath()
|
|||
|
{
|
|||
|
Assert.ThrowsArgumentNull(() => { new MultipartFormDataStreamProvider(null); }, "rootPath");
|
|||
|
|
|||
|
foreach (string path in TestData.NotSupportedFilePaths)
|
|||
|
{
|
|||
|
Assert.Throws<NotSupportedException>(() => new MultipartFormDataStreamProvider(path, DefaultBufferSize));
|
|||
|
}
|
|||
|
|
|||
|
foreach (string path in TestData.InvalidNonNullFilePaths)
|
|||
|
{
|
|||
|
// Note: Path.GetFileName doesn't set the argument name when throwing.
|
|||
|
Assert.ThrowsArgument(() => { new MultipartFormDataStreamProvider(path, DefaultBufferSize); }, null, allowDerivedExceptions: true);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[Fact]
|
|||
|
[Trait("Description", "MultipartFormDataStreamProvider ctor with null path.")]
|
|||
|
public void ConstructorInvalidBufferSize()
|
|||
|
{
|
|||
|
Assert.ThrowsArgumentGreaterThanOrEqualTo(() => new MultipartFileStreamProvider(ValidPath, MinBufferSize - 1),
|
|||
|
"bufferSize", MinBufferSize.ToString(), MinBufferSize - 1);
|
|||
|
}
|
|||
|
|
|||
|
[Fact]
|
|||
|
[Trait("Description", "BodyPartFileNames empty.")]
|
|||
|
public void EmptyBodyPartFileNames()
|
|||
|
{
|
|||
|
MultipartFormDataStreamProvider instance = new MultipartFormDataStreamProvider(Path.GetTempPath());
|
|||
|
Assert.NotNull(instance.BodyPartFileNames);
|
|||
|
Assert.Equal(0, instance.BodyPartFileNames.Count);
|
|||
|
}
|
|||
|
|
|||
|
[Fact]
|
|||
|
[Trait("Description", "GetStream(HttpContentHeaders) throws on null.")]
|
|||
|
public void GetStreamThrowsOnNull()
|
|||
|
{
|
|||
|
MultipartFormDataStreamProvider instance = new MultipartFormDataStreamProvider(Path.GetTempPath());
|
|||
|
Assert.ThrowsArgumentNull(() => { instance.GetStream(null); }, "headers");
|
|||
|
}
|
|||
|
|
|||
|
[Fact]
|
|||
|
[Trait("Description", "GetStream(HttpContentHeaders) throws on no Content-Disposition header.")]
|
|||
|
public void GetStreamThrowsOnNoContentDisposition()
|
|||
|
{
|
|||
|
MultipartFormDataStreamProvider instance = new MultipartFormDataStreamProvider(Path.GetTempPath());
|
|||
|
HttpContent content = new StringContent("text");
|
|||
|
Assert.Throws<IOException>(() => { instance.GetStream(content.Headers); }, RS.Format(Properties.Resources.MultipartFormDataStreamProviderNoContentDisposition, "Content-Disposition"));
|
|||
|
}
|
|||
|
|
|||
|
[Fact]
|
|||
|
[Trait("Description", "GetStream(HttpContentHeaders) validation.")]
|
|||
|
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();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|