Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions PolyShim.Tests/Net90/FileTests.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,58 @@
using System.IO;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.Net90;

public class FileTests
{
[Fact]
public void AppendAllBytes_Test()
{
// Arrange
var tempFilePath = Path.GetTempFileName();

try
{
File.WriteAllBytes(tempFilePath, [0x00, 0x01, 0x02]);

// Act
File.AppendAllBytes(tempFilePath, new byte[] { 0x0A, 0x0B, 0x0C, 0x0D, 0x0E });

// Assert
var readBytes = File.ReadAllBytes(tempFilePath);
readBytes.Should().Equal(0x00, 0x01, 0x02, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E);
}
finally
{
try
{
File.Delete(tempFilePath);
}
catch
{
// Ignore
}
}
}

[Fact]
public async Task AppendAllBytesAsync_Test()
{
// Arrange
var bytesToAppend = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };
var tempFilePath = Path.GetTempFileName();

try
{
await File.WriteAllBytesAsync(tempFilePath, [0x00, 0x01, 0x02]);

// Act
await File.AppendAllBytesAsync(tempFilePath, bytesToAppend);
await File.AppendAllBytesAsync(tempFilePath, [0x01, 0x02, 0x03, 0x04, 0x05]);

// Assert
var readBytes = await File.ReadAllBytesAsync(tempFilePath);
Assert.Equal(bytesToAppend, readBytes);
readBytes.Should().Equal(0x00, 0x01, 0x02, 0x01, 0x02, 0x03, 0x04, 0x05);
}
finally
{
Expand Down
4 changes: 2 additions & 2 deletions PolyShim.Tests/NetCore20/FileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public async Task ReadAllLinesAsync_Test()
public async Task ReadAllTextAsync_Test()
{
// Arrange
var textToWrite = "This is a sample text for testing ReadAllTextAsync.";
const string textToWrite = "This is a sample text for testing ReadAllTextAsync.";
var tempFilePath = Path.GetTempFileName();

try
Expand Down Expand Up @@ -218,7 +218,7 @@ public async Task WriteAllLinesAsync_Test()
public async Task WriteAllTextAsync_Test()
{
// Arrange
var textToWrite = "Testing WriteAllTextAsync method.";
const string textToWrite = "Testing WriteAllTextAsync method.";
var tempFilePath = Path.GetTempFileName();

try
Expand Down
14 changes: 13 additions & 1 deletion PolyShim/Net90/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ internal static partial class PolyfillExtensions
#if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER
extension(File)
{
#if FEATURE_TASK
// https://learn.microsoft.com/dotnet/api/system.io.file.appendallbytes#system-io-file-appendallbytes(system-string-system-byte())
public static void AppendAllBytes(string path, byte[] bytes)
{
using var stream = new FileStream(
path,
FileMode.Append,
FileAccess.Write,
FileShare.None
);

stream.Write(bytes, 0, bytes.Length);
}

#if FEATURE_TASK
// https://learn.microsoft.com/dotnet/api/system.io.file.appendallbytesasync#system-io-file-appendallbytesasync(system-string-system-byte()-system-threading-cancellationtoken)
public static async Task AppendAllBytesAsync(
string path,
Expand Down
5 changes: 3 additions & 2 deletions PolyShim/Signatures.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Signatures

- **Total:** 237
- **Total:** 238
- **Types:** 62
- **Members:** 175
- **Members:** 176

___

Expand Down Expand Up @@ -71,6 +71,7 @@ ___
- [`Task<string[]> ReadAllLinesAsync(string, Encoding, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.io.file.readalllinesasync#system-io-file-readalllinesasync(system-string-system-text-encoding-system-threading-cancellationtoken)) <sup><sub>.NET Core 2.0</sub></sup>
- [`Task<string> ReadAllTextAsync(string, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.io.file.readalltextasync#system-io-file-readalltextasync(system-string-system-threading-cancellationtoken)) <sup><sub>.NET Core 2.0</sub></sup>
- [`Task<string> ReadAllTextAsync(string, Encoding, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.io.file.readalltextasync#system-io-file-readalltextasync(system-string-system-text-encoding-system-threading-cancellationtoken)) <sup><sub>.NET Core 2.0</sub></sup>
- [`void AppendAllBytes(string, byte[])`](https://learn.microsoft.com/dotnet/api/system.io.file.appendallbytes#system-io-file-appendallbytes(system-string-system-byte())) <sup><sub>.NET 9.0</sub></sup>
- [`void Move(string, string, bool)`](https://learn.microsoft.com/dotnet/api/system.io.file.move#system-io-file-move(system-string-system-string-system-boolean)) <sup><sub>.NET Core 3.0</sub></sup>
- `HashCode`
- [**[class]**](https://learn.microsoft.com/dotnet/api/system.hashcode) <sup><sub>.NET Core 2.1</sub></sup>
Expand Down
Loading