119 lines
5.4 KiB
C#
119 lines
5.4 KiB
C#
using Explorer.Application;
|
|
using Explorer.Contracts;
|
|
using Explorer.Domain;
|
|
using Explorer.Hosting.Ipc;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
namespace Explorer.Hosting.Tests;
|
|
|
|
public class WorkbenchPipeTests
|
|
{
|
|
[Fact]
|
|
public void Handle_forwards_indexing_and_transfer_calls()
|
|
{
|
|
var indexing = new FakeIndexing();
|
|
var transfers = new FakeTransfers();
|
|
var server = new WorkbenchPipeServer(
|
|
new WorkbenchHost(indexing, transfers, new StubSources(), new StubMutations()),
|
|
new WorkbenchIpcOptions { PipeName = "ew-test" },
|
|
NullLogger<WorkbenchPipeServer>.Instance);
|
|
|
|
var ping = server.Handle(new IpcEnvelope { V = WorkbenchIpc.ProtocolVersion, Op = "Ping" });
|
|
Assert.True(ping.Ok);
|
|
|
|
var scan = server.Handle(new IpcEnvelope { V = WorkbenchIpc.ProtocolVersion, Op = "Indexing.EnqueueFullScan", N = 42 });
|
|
Assert.True(scan.Ok);
|
|
Assert.Equal(42, indexing.FullScanId);
|
|
|
|
var pause = server.Handle(new IpcEnvelope { V = WorkbenchIpc.ProtocolVersion, Op = "Transfers.PauseAll" });
|
|
Assert.True(pause.Ok);
|
|
Assert.True(transfers.PausedAll);
|
|
|
|
var paused = server.Handle(new IpcEnvelope { V = WorkbenchIpc.ProtocolVersion, Op = "Transfers.IsPaused" });
|
|
Assert.True(paused.Paused);
|
|
|
|
var copy = server.Handle(new IpcEnvelope
|
|
{
|
|
V = WorkbenchIpc.ProtocolVersion,
|
|
Op = "Transfers.EnqueueCopy",
|
|
Paths = ["C:\\a.txt"],
|
|
Dest = "D:\\"
|
|
});
|
|
Assert.True(copy.Ok);
|
|
Assert.Equal(@"D:\", transfers.CopiedDest);
|
|
}
|
|
|
|
[Fact]
|
|
public void Handle_rejects_other_protocol_versions()
|
|
{
|
|
var server = new WorkbenchPipeServer(
|
|
new WorkbenchHost(new FakeIndexing(), new FakeTransfers(), new StubSources(), new StubMutations()),
|
|
new WorkbenchIpcOptions(),
|
|
NullLogger<WorkbenchPipeServer>.Instance);
|
|
var reply = server.Handle(new IpcEnvelope { V = 99, Op = "Ping" });
|
|
Assert.False(reply.Ok);
|
|
Assert.Contains("99", reply.Error);
|
|
}
|
|
|
|
private sealed class FakeIndexing : IIndexingHost
|
|
{
|
|
public long FullScanId { get; private set; }
|
|
public event EventHandler<ScanProgress>? ProgressChanged = delegate { };
|
|
public void EnqueueFullScan(long sourceId) => FullScanId = sourceId;
|
|
public void EnqueueFolderScan(long sourceId, string pathRel) { }
|
|
public void EnqueueReconcile(long sourceId, string pathRel) { }
|
|
public void Cancel(long sourceId) { }
|
|
}
|
|
|
|
private sealed class FakeTransfers : ITransferHost
|
|
{
|
|
public bool PausedAll { get; private set; }
|
|
public event EventHandler? Changed = delegate { };
|
|
public event EventHandler<TransferJob>? JobFinished = delegate { };
|
|
public bool IsPaused => PausedAll;
|
|
public IReadOnlyList<TransferJob> Snapshot() => [];
|
|
public void PauseAll() => PausedAll = true;
|
|
public void ResumeAll() => PausedAll = false;
|
|
public void Pause(long jobId) { }
|
|
public void Resume(long jobId) { }
|
|
public void Retry(long jobId) { }
|
|
public void Cancel(long jobId) { }
|
|
public void Dismiss(long jobId) { }
|
|
public void ClearFinished() { }
|
|
public bool MoveUp(long jobId) => false;
|
|
public bool MoveDown(long jobId) => false;
|
|
public string? CopiedDest { get; private set; }
|
|
public Task EnqueueCopyAsync(IReadOnlyList<string> sources, string destinationDirectory, CancellationToken cancellationToken = default)
|
|
{
|
|
CopiedDest = destinationDirectory;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
private sealed class StubSources : ISourceHost
|
|
{
|
|
public Task RefreshAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
|
|
public Task<Source> AddUncAsync(string path, CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(new Source { StableKey = "x", DisplayName = path });
|
|
public Task<Source?> EnsureForPathAsync(string path, CancellationToken cancellationToken = default)
|
|
=> Task.FromResult<Source?>(null);
|
|
public Task<bool> ForgetAsync(string path, CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(false);
|
|
}
|
|
|
|
private sealed class StubMutations : IIndexMutations
|
|
{
|
|
public Task<long> UpsertSyncProfileAsync(SyncProfile profile, CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(1L);
|
|
public Task DeleteSyncProfileAsync(long id, CancellationToken cancellationToken = default) => Task.CompletedTask;
|
|
public Task<long> UpsertOperationProfileAsync(OperationProfile profile, CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(1L);
|
|
public Task DeleteOperationProfileAsync(long id, CancellationToken cancellationToken = default) => Task.CompletedTask;
|
|
public Task<long> CreateRenameBatchAsync(IReadOnlyList<RenameBatchItem> items, CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(1L);
|
|
public Task MarkRenameBatchUndoneAsync(long id, CancellationToken cancellationToken = default) => Task.CompletedTask;
|
|
public Task EnqueueHashCollisionsAsync(long? sourceId, CancellationToken cancellationToken = default) => Task.CompletedTask;
|
|
public Task UpsertRelationAsync(FileRelation relation, CancellationToken cancellationToken = default) => Task.CompletedTask;
|
|
}
|
|
}
|