}
}
+ [Theory]
+ [MemberData(nameof(GetSyncAsyncOptions))]
+ public void ReadFromBeyondEndOfFileReturnsZero(FileOptions options)
+ {
+ string filePath = GetTestFilePath();
+ File.WriteAllBytes(filePath, new byte[100]);
+
+ using (SafeFileHandle handle = File.OpenHandle(filePath, FileMode.Open, options: options))
+ {
+ long eof = RandomAccess.GetLength(handle);
+ Assert.Equal(0, RandomAccess.Read(handle, new byte[1], fileOffset: eof + 1));
+ }
+ }
+
[Theory]
[MemberData(nameof(GetSyncAsyncOptions))]
public void ReadsBytesFromGivenFileAtGivenOffset(FileOptions options)
}
}
+ [Theory]
+ [MemberData(nameof(GetSyncAsyncOptions))]
+ public async Task ReadFromBeyondEndOfFileReturnsZeroAsync(FileOptions options)
+ {
+ string filePath = GetTestFilePath();
+ File.WriteAllBytes(filePath, new byte[100]);
+
+ using (SafeFileHandle handle = File.OpenHandle(filePath, FileMode.Open, options: options))
+ {
+ long eof = RandomAccess.GetLength(handle);
+ Assert.Equal(0, await RandomAccess.ReadAsync(handle, new byte[1], fileOffset: eof + 1));
+ }
+ }
+
[Theory]
[MemberData(nameof(GetSyncAsyncOptions))]
public async Task HappyPath(FileOptions options)
}
}
+ [Theory]
+ [MemberData(nameof(GetSyncAsyncOptions))]
+ public void ReadFromBeyondEndOfFileReturnsZero(FileOptions options)
+ {
+ string filePath = GetTestFilePath();
+ File.WriteAllBytes(filePath, new byte[100]);
+
+ using (SafeFileHandle handle = File.OpenHandle(filePath, FileMode.Open, options: options))
+ {
+ long eof = RandomAccess.GetLength(handle);
+ Assert.Equal(0, RandomAccess.Read(handle, new Memory<byte>[] { new byte[1] }, fileOffset: eof + 1));
+ }
+ }
+
[Theory]
[MemberData(nameof(GetSyncAsyncOptions))]
public void ReadsBytesFromGivenFileAtGivenOffset(FileOptions options)
}
}
+ [Theory]
+ [MemberData(nameof(GetSyncAsyncOptions))]
+ public async Task ReadFromBeyondEndOfFileReturnsZeroAsync(FileOptions options)
+ {
+ string filePath = GetTestFilePath();
+ File.WriteAllBytes(filePath, new byte[100]);
+
+ using (SafeFileHandle handle = File.OpenHandle(filePath, FileMode.Open, options: options))
+ {
+ long eof = RandomAccess.GetLength(handle);
+ Assert.Equal(0, await RandomAccess.ReadAsync(handle, new Memory<byte>[] { new byte[1] }, fileOffset: eof + 1));
+ }
+ }
+
[Theory]
[MemberData(nameof(GetSyncAsyncOptions))]
public async Task ReadsBytesFromGivenFileAtGivenOffsetAsync(FileOptions options)
Assert.Equal(stackAllocated.ToArray(), File.ReadAllBytes(filePath));
}
+ [Theory]
+ [MemberData(nameof(GetSyncAsyncOptions))]
+ public void WriteBeyondEndOfFileExtendsTheFile(FileOptions options)
+ {
+ string filePath = GetTestFilePath();
+
+ using (SafeFileHandle handle = File.OpenHandle(filePath, FileMode.CreateNew, FileAccess.Write, options: options))
+ {
+ Assert.Equal(0, RandomAccess.GetLength(handle));
+ RandomAccess.Write(handle, new byte[1] { 1 }, fileOffset: 1);
+ Assert.Equal(2, RandomAccess.GetLength(handle));
+ }
+
+ Assert.Equal(new byte[] { 0, 1 }, File.ReadAllBytes(filePath));
+ }
+
[Theory]
[MemberData(nameof(GetSyncAsyncOptions))]
public void WritesBytesFromGivenBufferToGivenFileAtGivenOffset(FileOptions options)
}
}
+ [Theory]
+ [MemberData(nameof(GetSyncAsyncOptions))]
+ public async Task WriteBeyondEndOfFileExtendsTheFileAsync(FileOptions options)
+ {
+ string filePath = GetTestFilePath();
+
+ using (SafeFileHandle handle = File.OpenHandle(filePath, FileMode.CreateNew, FileAccess.Write, options: options))
+ {
+ Assert.Equal(0, RandomAccess.GetLength(handle));
+ await RandomAccess.WriteAsync(handle, new byte[1] { 1 }, fileOffset: 1);
+ Assert.Equal(2, RandomAccess.GetLength(handle));
+ }
+
+ Assert.Equal(new byte[] { 0, 1 }, await File.ReadAllBytesAsync(filePath));
+ }
+
[Theory]
[MemberData(nameof(GetSyncAsyncOptions))]
public async Task WritesBytesFromGivenBufferToGivenFileAtGivenOffsetAsync(FileOptions options)
}
}
+ [Theory]
+ [MemberData(nameof(GetSyncAsyncOptions))]
+ public void WriteBeyondEndOfFileExtendsTheFile(FileOptions options)
+ {
+ string filePath = GetTestFilePath();
+
+ using (SafeFileHandle handle = File.OpenHandle(filePath, FileMode.CreateNew, FileAccess.Write, options: options))
+ {
+ Assert.Equal(0, RandomAccess.GetLength(handle));
+ RandomAccess.Write(handle, new ReadOnlyMemory<byte>[] { new byte[1] { 1 } }, fileOffset: 1);
+ Assert.Equal(2, RandomAccess.GetLength(handle));
+ }
+
+ Assert.Equal(new byte[] { 0, 1 }, File.ReadAllBytes(filePath));
+ }
+
[Theory]
[MemberData(nameof(GetSyncAsyncOptions))]
public void WritesBytesFromGivenBuffersToGivenFileAtGivenOffset(FileOptions options)
}
}
+ [Theory]
+ [MemberData(nameof(GetSyncAsyncOptions))]
+ public async Task WriteBeyondEndOfFileExtendsTheFileAsync(FileOptions options)
+ {
+ string filePath = GetTestFilePath();
+
+ using (SafeFileHandle handle = File.OpenHandle(filePath, FileMode.CreateNew, FileAccess.Write, options: options))
+ {
+ Assert.Equal(0, RandomAccess.GetLength(handle));
+ await RandomAccess.WriteAsync(handle, new ReadOnlyMemory<byte>[] { new byte[1] { 1 } }, fileOffset: 1);
+ Assert.Equal(2, RandomAccess.GetLength(handle));
+ }
+
+ Assert.Equal(new byte[] { 0, 1 }, await File.ReadAllBytesAsync(filePath));
+ }
+
[Theory]
[MemberData(nameof(GetSyncAsyncOptions))]
public async Task WritesBytesFromGivenBufferToGivenFileAtGivenOffsetAsync(FileOptions options)