Skip to content

Commit 95a4eee

Browse files
committed
Corrected test case
1 parent d685e97 commit 95a4eee

File tree

1 file changed

+5
-39
lines changed

1 file changed

+5
-39
lines changed

src/Http/WebUtilities/test/MultipartReaderTests.cs

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,6 @@ public class MultipartReaderTests
9292
"Content of a.txt.\r\n" +
9393
"\r\n" +
9494
"--9051914041544843365";
95-
private const string ThreePartBodyWithMixedFiles =
96-
"--9051914041544843365972754266\r\n" +
97-
"Content-Disposition: form-data; name=\"file1\"; filename=\"a.txt\"\r\n" +
98-
"Content-Type: text/plain\r\n" +
99-
"\r\n" +
100-
"Content of a.txt.\r\n" +
101-
"\r\n" +
102-
"--9051914041544843365972754266\r\n" +
103-
"Content-Disposition: form-data; name=\"file2\"; filename=\"a.html\"\r\n" +
104-
"Content-Type: text/html\r\n" +
105-
"\r\n" +
106-
"<!DOCTYPE html><title>Content of a.html.</title>\r\n" +
107-
"\r\n" +
108-
"--9051914041544843365972754266\r\n" +
109-
"Content-Disposition: form-data; name=\"file3\"; filename=\"a.json\"\r\n" +
110-
"Content-Type: application/json\r\n" +
111-
"\r\n" +
112-
"{ \"Text\": \"Content of a.json.\" }\r\n" +
113-
"\r\n" +
114-
"--9051914041544843365972754266--\r\n";
11595

11696
private static MemoryStream MakeStream(string text)
11797
{
@@ -337,9 +317,11 @@ public void MultipartReader_BufferSizeMustBeLargerThanBoundary_Throws()
337317
[Fact]
338318
public async Task MultipartReader_ReadMultipartBodyWithFilesForDeferredCopy_Success()
339319
{
340-
var stream = MakeStream(ThreePartBodyWithMixedFiles);
320+
var stream = MakeStream(ThreePartBody);
341321
var reader = new MultipartReader(Boundary, stream);
342322

323+
await reader.ReadNextSectionAsync(); // skip text field section
324+
343325
var section = await reader.ReadNextSectionAsync();
344326
Assert.NotNull(section);
345327
Assert.Equal(2, section.Headers.Count);
@@ -354,35 +336,19 @@ public async Task MultipartReader_ReadMultipartBodyWithFilesForDeferredCopy_Succ
354336
Assert.Equal("text/html", section.Headers["Content-Type"][0]);
355337
var stream2 = section.Body;
356338

357-
section = await reader.ReadNextSectionAsync();
358-
Assert.NotNull(section);
359-
Assert.Equal(2, section.Headers.Count);
360-
Assert.Equal("form-data; name=\"file3\"; filename=\"a.json\"", section.Headers["Content-Disposition"][0]);
361-
Assert.Equal("application/json", section.Headers["Content-Type"][0]);
362-
var stream3 = section.Body;
363-
364339
Assert.Null(await reader.ReadNextSectionAsync());
365340

366341
Assert.True(stream1.CanSeek);
367342
Assert.Equal(0, stream1.Seek(0, SeekOrigin.Begin));
368343
var buffer = new MemoryStream();
369-
var exception = await Record.ExceptionAsync(() => stream1.CopyToAsync(buffer));
370-
Assert.Null(exception);
344+
await stream1.CopyToAsync(buffer);
371345
Assert.Equal("Content of a.txt.\r\n", Encoding.ASCII.GetString(buffer.ToArray()));
372346

373347
Assert.True(stream2.CanSeek);
374348
Assert.Equal(0, stream2.Seek(0, SeekOrigin.Begin));
375349
buffer = new MemoryStream();
376-
exception = await Record.ExceptionAsync(() => stream2.CopyToAsync(buffer));
377-
Assert.Null(exception);
350+
await stream2.CopyToAsync(buffer);
378351
Assert.Equal("<!DOCTYPE html><title>Content of a.html.</title>\r\n", Encoding.ASCII.GetString(buffer.ToArray()));
379-
380-
Assert.True(stream3.CanSeek);
381-
Assert.Equal(0, stream3.Seek(0, SeekOrigin.Begin));
382-
buffer = new MemoryStream();
383-
exception = await Record.ExceptionAsync(() => stream3.CopyToAsync(buffer));
384-
Assert.Null(exception);
385-
Assert.Equal("{ \"Text\": \"Content of a.json.\" }\r\n", Encoding.ASCII.GetString(buffer.ToArray()));
386352
}
387353

388354
[Fact]

0 commit comments

Comments
 (0)