wabbajack/Wabbajack.Paths.IO.Test/AbsolutePathTests.cs
2021-10-23 10:51:17 -06:00

56 lines
1.4 KiB
C#

using System;
using System.Linq;
using System.Threading.Tasks;
using FsCheck.Xunit;
using Xunit;
namespace Wabbajack.Paths.IO.Test;
public class AbsolutePathTests
{
private AbsolutePath GetTempFile()
{
return KnownFolders.EntryPoint.Combine(Guid.NewGuid().ToString());
}
[Property(StartSize = 1024)]
public void CanReadAndWriteFiles(byte[] data)
{
var file = GetTempFile();
file.WriteAllBytes(data);
Assert.Equal(data.Length, file.Size());
Assert.Equal(data, file.ReadAllBytes());
file.Delete();
file.WriteAllText("Test");
Assert.Equal("Test", file.ReadAllText());
}
[Fact]
public async ValueTask CanReadAndWriteFilesAsync()
{
var data = "This is a test";
var file = GetTempFile();
await file.WriteAllTextAsync(data);
Assert.Equal(data.Length, file.Size());
Assert.Equal(data, await file.ReadAllTextAsync());
file.Delete();
}
[Property(EndSize = 100)] // OSX has a max length of 1024
public void LongPathsAreSupported(uint depth)
{
var basePath = KnownFolders.EntryPoint.Combine("deep_paths");
basePath.DeleteDirectory();
var path = Enumerable.Range(1, (int) depth + 1).Aggregate(basePath, (path, i) => path.Combine($"path_{i}"));
path.Parent.CreateDirectory();
path.WriteAllText("test");
basePath.DeleteDirectory();
}
}