|
|
@@ -389,4 +389,28 @@ public class MultipartReaderTests
|
|
|
var section = await reader.ReadNextSectionAsync();
|
|
|
Assert.NotNull(section);
|
|
|
}
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public async Task SyncReadWithOffsetWorks()
|
|
|
+ {
|
|
|
+ var stream = MakeStream(OnePartBody);
|
|
|
+ var reader = new MultipartReader(Boundary, stream);
|
|
|
+ var buffer = new byte[5];
|
|
|
+
|
|
|
+ var section = await reader.ReadNextSectionAsync();
|
|
|
+ Assert.NotNull(section);
|
|
|
+ Assert.Single(section.Headers);
|
|
|
+ Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]);
|
|
|
+
|
|
|
+ var read = section.Body.Read(buffer, 2, buffer.Length - 2);
|
|
|
+ Assert.Equal("\0\0tex", GetString(buffer, read + 2));
|
|
|
+
|
|
|
+ read = section.Body.Read(buffer, 1, buffer.Length - 1);
|
|
|
+ Assert.Equal("\0t de", GetString(buffer, read + 1));
|
|
|
+
|
|
|
+ read = section.Body.Read(buffer, 0, buffer.Length);
|
|
|
+ Assert.Equal("fault", GetString(buffer, read));
|
|
|
+
|
|
|
+ Assert.Null(await reader.ReadNextSectionAsync());
|
|
|
+ }
|
|
|
}
|