42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
using PLib.Application.Abstractions;
|
|
using PLib.Application.Library;
|
|
using PLib.Domain.Videos;
|
|
|
|
namespace PLib.Tests.Library;
|
|
|
|
/// <summary>Hand-written double mirroring the EF repository's lookup-by-normalized-name rule.</summary>
|
|
internal sealed class InMemoryLabelRepository : ILabelRepository
|
|
{
|
|
private readonly List<LibraryLabel> _labels = [];
|
|
|
|
public Task<IReadOnlyList<LibraryLabel>> GetAllAsync(CancellationToken cancellationToken = default) =>
|
|
Task.FromResult<IReadOnlyList<LibraryLabel>>([.. _labels]);
|
|
|
|
public Task<IReadOnlyList<LabelSummary>> GetSummariesAsync(CancellationToken cancellationToken = default) =>
|
|
Task.FromResult<IReadOnlyList<LabelSummary>>(
|
|
[.. _labels.Select(label => new LabelSummary(label.Id, label.Name, label.Kind, label.Videos.Count, label.ImagePath))]);
|
|
|
|
public Task<LibraryLabel?> FindAsync(
|
|
LabelKind kind,
|
|
string name,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var normalized = LibraryLabel.Normalize(name);
|
|
|
|
return Task.FromResult(_labels.FirstOrDefault(
|
|
label => label.Kind == kind && label.NormalizedName == normalized));
|
|
}
|
|
|
|
public Task AddAsync(LibraryLabel label, CancellationToken cancellationToken = default)
|
|
{
|
|
_labels.Add(label);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task RemoveAsync(LibraryLabel label, CancellationToken cancellationToken = default)
|
|
{
|
|
_labels.Remove(label);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|