-
Notifications
You must be signed in to change notification settings - Fork 0
/
AFileStreamOnWindows.cs
64 lines (61 loc) · 2.16 KB
/
AFileStreamOnWindows.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
using System.IO;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;
namespace InsightsOnFiles.Tests
{
public static class AFileStreamOnWindows
{
[Theory]
[InlineData(100)]
[InlineData(1000)]
[InlineData(2000)]
[InlineData(3000)]
[InlineData(4000)]
[InlineData(4010)]
[InlineData(4050)]
[InlineData(4095)]
[InlineData(4096)]
[InlineData(4250)]
[InlineData(4500)]
[InlineData(4750)]
[InlineData(5000)]
[InlineData(6000)]
[InlineData(7000)]
[InlineData(8000)]
[InlineData(9000)]
[InlineData(20_000)]
[InlineData(50_000)]
[InlineData(63_999)]
[InlineData(64_000)]
[InlineData(80_000)]
public static async Task CompletesSynchronouslyWhenTheInternalBufferSizeIsLargerThanTheFile(int fileSize)
{
var fileName = $"Test file with {fileSize} bytes.blob";
try
{
var writeBuffer = new byte[fileSize];
for (var i = 0; i < fileSize; ++i)
{
writeBuffer[i] = (byte) (i % byte.MaxValue);
}
using (var writeStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous))
await writeStream.WriteAsync(writeBuffer);
var readBuffer = new byte[fileSize];
const int largeStreamBufferSize = 84075; // This is the largest array size that will fit on the SOH
using (var readStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, largeStreamBufferSize, FileOptions.Asynchronous))
{
var task = readStream.ReadAsync(readBuffer, 0, fileSize);
task.IsCompleted.Should().BeTrue();
task.Result.Should().Be(fileSize);
readBuffer.Should().Equal(writeBuffer);
}
}
finally
{
if (File.Exists(fileName))
File.Delete(fileName);
}
}
}
}