-
Notifications
You must be signed in to change notification settings - Fork 112
/
SingleFile.cs
63 lines (57 loc) · 1.63 KB
/
SingleFile.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
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace HttpMultipartParser.UnitTests.ParserScenarios
{
public class SingleFile
{
private static readonly string _testData = TestUtil.TrimAllLines(
@"--boundary
Content-Disposition: form-data; name=""file""; filename=""data.txt"";
Content-Type: text/plain
I am the first data1
--boundary--"
);
/// <summary>
/// Test case for single files.
/// </summary>
private static readonly TestData _testCase = new TestData(
_testData,
new List<ParameterPart> { },
new List<FilePart> {
new FilePart("file", "data.txt", TestUtil.StringToStreamNoBom("I am the first data1"), "text/plain", "form-data")
}
);
/// <summary>
/// Initializes the test data before each run, this primarily
/// consists of resetting data stream positions.
/// </summary>
public SingleFile()
{
foreach (var filePart in _testCase.ExpectedFileData)
{
filePart.Data.Position = 0;
}
}
[Fact]
public void SingleFileTest()
{
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 SingleFileTest_Async()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16);
Assert.True(_testCase.Validate(parser));
}
}
}
}