using AvParser.Core.Collecting;
namespace AvParser.UI.HeadlessTests;
/// A store that records what it was asked to do and holds nothing.
internal sealed class FakeMediaStore : IMediaStore
{
public List Purged { get; } = [];
public MediaStoreStats Stats { get; set; } = new(0, 0, 0, 0);
public List Browse { get; } = [];
public List SourceIds { get; } = [];
public MediaBrowseQuery? LastBrowse { get; private set; }
public int? TotalOverride { get; set; }
public bool BrowseThrows { get; set; }
public PurgeResult PurgeResult { get; set; } = new(3, 2, 4096);
public ShowcaseMode Mode { get; private set; } = ShowcaseMode.HardLink;
public Task InitialiseAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
public void Configure(ShowcaseMode mode) => Mode = mode;
public Task BeginRunAsync(string sourceId, CancellationToken cancellationToken = default) =>
Task.FromResult("run");
public Task CompleteRunAsync(string runId, RunSummary summary, CancellationToken cancellationToken = default) =>
Task.CompletedTask;
public Task> GetSeenAsync(
string sourceId,
IReadOnlyCollection urls,
CancellationToken cancellationToken = default
) =>
Task.FromResult>(
new Dictionary(StringComparer.Ordinal)
);
public Task RecordSeenAsync(
string sourceId,
string url,
SeenOutcome outcome,
int? httpStatus = null,
string? errorCode = null,
CancellationToken cancellationToken = default
) => Task.CompletedTask;
public Task> LoadTombstonesAsync(CancellationToken cancellationToken = default) =>
Task.FromResult>(new HashSet(StringComparer.Ordinal));
public Task TombstoneAsync(string sha256, string? reason, CancellationToken cancellationToken = default) =>
Task.FromResult(0);
public Task StoreAsync(MediaStoreRequest request, CancellationToken cancellationToken = default) =>
Task.FromResult(new CollectedItem(request.Candidate, request.Blob, CollectStatus.Stored));
public Task PurgeAsync(PurgeOptions options, CancellationToken cancellationToken = default)
{
Purged.Add(options.SourceId);
return Task.FromResult(PurgeResult);
}
public Task RebuildShowcaseAsync(string sourceId, CancellationToken cancellationToken = default) =>
Task.FromResult(0);
public Task GetStatsAsync(CancellationToken cancellationToken = default) => Task.FromResult(Stats);
public Task BrowseAsync(MediaBrowseQuery query, CancellationToken cancellationToken = default)
{
LastBrowse = query;
return BrowseThrows
? throw new InvalidOperationException("the index is unreadable")
: Task.FromResult(new MediaPage(Browse, TotalOverride ?? Browse.Count));
}
public Task> GetSourceIdsAsync(CancellationToken cancellationToken = default) =>
Task.FromResult>(SourceIds);
}