91 lines
4.1 KiB
C#
91 lines
4.1 KiB
C#
using Explorer.Application;
|
|
using Explorer.Contracts;
|
|
using Explorer.Domain;
|
|
|
|
namespace Explorer.Application.Tests;
|
|
|
|
public class WorkbenchHostTests
|
|
{
|
|
[Fact]
|
|
public void Forwards_indexing_and_transfer_sessions()
|
|
{
|
|
var indexing = new FakeIndexing();
|
|
var transfers = new FakeTransfers();
|
|
var sources = new StubSources();
|
|
var mutations = new StubMutations();
|
|
IWorkbenchHost host = new WorkbenchHost(indexing, transfers, sources, mutations);
|
|
Assert.Same(indexing, host.Indexing);
|
|
Assert.Same(transfers, host.Transfers);
|
|
Assert.Same(sources, host.Sources);
|
|
Assert.Same(mutations, host.Mutations);
|
|
|
|
host.Indexing.EnqueueFullScan(7);
|
|
host.Transfers.PauseAll();
|
|
Assert.Equal(7, indexing.FullScanId);
|
|
Assert.True(transfers.PausedAll);
|
|
}
|
|
|
|
private sealed class FakeIndexing : IIndexingHost
|
|
{
|
|
public long FullScanId { get; private set; }
|
|
public event EventHandler<ScanProgress>? ProgressChanged;
|
|
|
|
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) { }
|
|
|
|
public void Raise() => ProgressChanged?.Invoke(this, new ScanProgress
|
|
{
|
|
SourceId = 1,
|
|
CurrentPath = "",
|
|
Status = ScanJobStatus.Running
|
|
});
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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(0L);
|
|
public Task DeleteSyncProfileAsync(long id, CancellationToken cancellationToken = default) => Task.CompletedTask;
|
|
public Task<long> UpsertOperationProfileAsync(OperationProfile profile, CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(0L);
|
|
public Task DeleteOperationProfileAsync(long id, CancellationToken cancellationToken = default) => Task.CompletedTask;
|
|
public Task<long> CreateRenameBatchAsync(IReadOnlyList<RenameBatchItem> items, CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(0L);
|
|
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;
|
|
}
|
|
}
|