-
Notifications
You must be signed in to change notification settings - Fork 112
/
MultipleParamsAndFiles.cs
86 lines (75 loc) · 2.52 KB
/
MultipleParamsAndFiles.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace HttpMultipartParser.UnitTests.ParserScenarios
{
/// <summary>
/// Test case for multiple parameters and files.
/// </summary>
public class MultipleParamsAndFiles
{
private static readonly string _testData = TestUtil.TrimAllLines(
@"--boundary
Content-Disposition: form-data; name=""text""
textdata
--boundary
Content-Disposition: form-data; name=""after"";TestForTextWithoutSplit
afterdata
--boundary
Content-Disposition: form-data; name=""file""; filename=""data.txt""
Content-Type: text/plain
I am the first data
--boundary
Content-Disposition: form-data;TestForTextWithoutSplit; name=""newfile""; filename=""superdata.txt""
Content-Type: text/plain
I am the second data
--boundary
Content-Disposition: form-data; name=""never""
neverdata
--boundary
Content-Disposition: form-data; name=""waylater""
waylaterdata
--boundary--"
);
private static readonly TestData _testCase = new TestData(
_testData,
new List<ParameterPart> {
new ParameterPart("text", "textdata"),
new ParameterPart("after", "afterdata"),
new ParameterPart("never", "neverdata"),
new ParameterPart("waylater", "waylaterdata")
},
new List<FilePart> {
new FilePart( "file", "data.txt", TestUtil.StringToStreamNoBom("I am the first data")),
new FilePart( "newfile", "superdata.txt", TestUtil.StringToStreamNoBom("I am the second data"))
}
);
public MultipleParamsAndFiles()
{
}
/// <summary>
/// Checks that multiple files don't get in the way of parsing each other
/// and that everything parses correctly.
/// </summary>
[Fact]
public void MultipleFilesAndParamsTest()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = MultipartFormDataParser.Parse(stream, "boundary", Encoding.UTF8, 16);
Assert.True(_testCase.Validate(parser));
}
}
[Fact]
public async Task MultipleFilesAndParamsTestAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16);
Assert.True(_testCase.Validate(parser));
}
}
}
}