2021-09-07 05:15:45 +00:00
|
|
|
using System.Linq;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
2022-09-06 05:53:22 +00:00
|
|
|
using MfGames.Nitride.Contents;
|
|
|
|
using MfGames.Nitride.IO.Contents;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
2021-09-07 05:15:45 +00:00
|
|
|
using Xunit;
|
|
|
|
using Xunit.Abstractions;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
2021-09-07 05:15:45 +00:00
|
|
|
using Zio;
|
|
|
|
using Zio.FileSystems;
|
|
|
|
|
2022-09-06 05:53:22 +00:00
|
|
|
namespace MfGames.Nitride.IO.Tests;
|
2022-06-05 18:44:51 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Tests the functionality of the WriteFiles().
|
|
|
|
/// </summary>
|
|
|
|
public class WriteFilesTest : NitrideIOTestBase
|
2021-09-07 05:15:45 +00:00
|
|
|
{
|
2022-06-05 18:44:51 +00:00
|
|
|
public WriteFilesTest(ITestOutputHelper output)
|
|
|
|
: base(output)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WriteAllFiles()
|
2021-09-07 05:15:45 +00:00
|
|
|
{
|
2022-06-05 18:44:51 +00:00
|
|
|
// Set up the test.
|
|
|
|
using NitrideIOTestContext context = this.CreateContext();
|
|
|
|
|
|
|
|
// Set up the file.
|
|
|
|
IFileSystem fileSystem = context.FileSystem;
|
|
|
|
|
|
|
|
fileSystem.CreateDirectory("/b1");
|
|
|
|
fileSystem.CreateDirectory("/c1");
|
|
|
|
fileSystem.CreateDirectory("/c1/c2");
|
|
|
|
fileSystem.CreateDirectory("/d1");
|
|
|
|
fileSystem.WriteAllText("/a.txt", "File A");
|
|
|
|
fileSystem.WriteAllText("/b1/b.md", "File B");
|
|
|
|
fileSystem.WriteAllText("/c1/c2/e.md", "File E");
|
|
|
|
|
|
|
|
// Set up the operation.
|
|
|
|
var output = new MemoryFileSystem();
|
|
|
|
ReadFiles readFiles = context.Resolve<ReadFiles>();
|
2022-07-09 04:52:10 +00:00
|
|
|
|
|
|
|
WriteFiles op = context.Resolve<WriteFiles>()
|
|
|
|
.WithFileSystem(output);
|
2022-06-05 18:44:51 +00:00
|
|
|
|
|
|
|
// Read and write out the files. We switch one of the files to be
|
|
|
|
// text content to make sure that works too.
|
|
|
|
readFiles.WithPattern("/**")
|
|
|
|
.Run()
|
|
|
|
.Select(
|
|
|
|
x => x.Get<UPath>() == "/b1/b.md"
|
2023-01-15 00:19:42 +00:00
|
|
|
? x.SetTextContent(
|
|
|
|
((ITextContentConvertable)x.GetBinaryContent())
|
|
|
|
.ToTextContent())
|
2022-06-05 18:44:51 +00:00
|
|
|
: x)
|
|
|
|
.Run(op);
|
|
|
|
|
|
|
|
// Verify the results.
|
|
|
|
Assert.True(output.FileExists("/a.txt"));
|
|
|
|
Assert.True(output.FileExists("/b1/b.md"));
|
|
|
|
Assert.True(output.FileExists("/c1/c2/e.md"));
|
|
|
|
|
|
|
|
Assert.Equal("File A", output.ReadAllText("/a.txt"));
|
|
|
|
Assert.Equal("File B", output.ReadAllText("/b1/b.md"));
|
|
|
|
Assert.Equal("File E", output.ReadAllText("/c1/c2/e.md"));
|
2021-09-07 05:15:45 +00:00
|
|
|
}
|
|
|
|
}
|