49 lines
2.1 KiB
C#
49 lines
2.1 KiB
C#
using Explorer.Domain;
|
|
using Explorer.Domain.Abstractions;
|
|
using Explorer.FileOperations;
|
|
|
|
namespace Explorer.FileOperations.Tests;
|
|
|
|
public class FileOperationTests
|
|
{
|
|
[Fact]
|
|
public void New_folder_and_rename_on_real_filesystem()
|
|
{
|
|
var root = Path.Combine(Path.GetTempPath(), "ew-ops", Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(root);
|
|
try
|
|
{
|
|
var ops = new FileOperationService(null!, new StubShell(), new StubEnum());
|
|
var created = ops.NewFolder(root);
|
|
Assert.True(Directory.Exists(created));
|
|
ops.Rename(created, "Renamed");
|
|
Assert.True(Directory.Exists(Path.Combine(root, "Renamed")));
|
|
}
|
|
finally
|
|
{
|
|
try { Directory.Delete(root, true); } catch { /* ignore */ }
|
|
}
|
|
}
|
|
}
|
|
|
|
file sealed class StubEnum : IFileSystemEnumerator
|
|
{
|
|
public IEnumerable<FileSystemItem> EnumerateChildren(string directoryPath) => [];
|
|
public IReadOnlyList<FileSystemItem> EnumerateChildrenSafe(string directoryPath, out string? error) { error = null; return []; }
|
|
public FileSystemItem? GetItem(string path) => null;
|
|
}
|
|
|
|
file sealed class StubShell : IShellFileOperations
|
|
{
|
|
public void Open(string path) { }
|
|
public bool DeleteToRecycleBin(IReadOnlyList<string> paths, out string? error) => Delete(paths, true, out error);
|
|
public bool Delete(IReadOnlyList<string> paths, bool recycle, out string? error) { error = "n/a"; return false; }
|
|
public bool CopyFileWithProgress(string source, string destination, bool overwrite, IProgress<long>? progress, CancellationToken cancellationToken, out string? error, Func<bool>? pauseRequested = null)
|
|
{ error = "n/a"; return false; }
|
|
public bool MoveFileWithProgress(string source, string destination, bool overwrite, IProgress<long>? progress, CancellationToken cancellationToken, out string? error, Func<bool>? pauseRequested = null)
|
|
{ error = "n/a"; return false; }
|
|
public bool CreateShortcut(string targetPath, string shortcutPath, out string? error)
|
|
{ error = null; return true; }
|
|
public bool EmptyRecycleBin(out string? error) { error = null; return true; }
|
|
}
|