using Microsoft.Extensions.Options;
using PLib.Application.Metadata;
namespace PLib.Tests.Library;
///
/// A fixed over metadata sources.
///
///
/// The service reads CurrentValue on every lookup, because the user can add a source
/// without restarting. A substitute would answer null and blow up in the one place that
/// matters, so the tests hand it a real value instead.
///
internal sealed class MetadataMonitor(MetadataOptions value) : IOptionsMonitor
{
public static MetadataMonitor Empty { get; } = new(new MetadataOptions());
public static MetadataMonitor With(params MetadataSourceOptions[] sources) =>
new(new MetadataOptions { Sources = [.. sources] });
public static MetadataMonitor With(IReadOnlyList sources, int delayMilliseconds) =>
new(new MetadataOptions { Sources = [.. sources], RequestDelayMilliseconds = delayMilliseconds });
public MetadataOptions CurrentValue { get; } = value;
public MetadataOptions Get(string? name) => CurrentValue;
public IDisposable? OnChange(Action listener) => null;
}