63 lines
2.2 KiB
C#
63 lines
2.2 KiB
C#
using System.Linq;
|
|
using Autofac;
|
|
using Nitride.Contents;
|
|
using Nitride.IO.Contents;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
using Zio;
|
|
using Zio.FileSystems;
|
|
|
|
namespace Nitride.IO.Tests
|
|
{
|
|
/// <summary>
|
|
/// Tests the functionality of the WriteFiles().
|
|
/// </summary>
|
|
public class WriteFilesTest : NitrideIOTestsBase
|
|
{
|
|
private readonly MemoryFileSystem fileSystem;
|
|
|
|
public WriteFilesTest(ITestOutputHelper output)
|
|
: base(output)
|
|
{
|
|
this.fileSystem = new MemoryFileSystem();
|
|
this.fileSystem.CreateDirectory("/b1");
|
|
this.fileSystem.CreateDirectory("/c1");
|
|
this.fileSystem.CreateDirectory("/c1/c2");
|
|
this.fileSystem.CreateDirectory("/d1");
|
|
this.fileSystem.WriteAllText("/a.txt", "File A");
|
|
this.fileSystem.WriteAllText("/b1/b.md", "File B");
|
|
this.fileSystem.WriteAllText("/c1/c2/e.md", "File E");
|
|
}
|
|
|
|
[Fact]
|
|
public void WriteAllFiles()
|
|
{
|
|
// Set up the operation.
|
|
var output = new MemoryFileSystem();
|
|
var readFiles = this.Container.Resolve<ReadFiles.Factory>();
|
|
var factory = this.Container.Resolve<WriteFiles.Factory>();
|
|
WriteFiles op = factory(output);
|
|
|
|
// Read and write out the files. We switch one of the files to be
|
|
// text content to make sure that works too.
|
|
readFiles(this.fileSystem)
|
|
.Read()
|
|
.Select(
|
|
x => x.Get<UPath>() == "/b1/b.md"
|
|
? x.SetTextContent(
|
|
((ITextContentConvertable)x.GetBinaryContent())
|
|
.ToTextContent())
|
|
: 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"));
|
|
}
|
|
}
|
|
}
|