27 lines
996 B
C#
27 lines
996 B
C#
using Microsoft.Extensions.Options;
|
|
using PLib.Application.Metadata;
|
|
|
|
namespace PLib.Tests.Library;
|
|
|
|
/// <summary>
|
|
/// A fixed <see cref="IOptionsMonitor{T}"/> over metadata sources.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The service reads <c>CurrentValue</c> 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.
|
|
/// </remarks>
|
|
internal sealed class MetadataMonitor(MetadataOptions value) : IOptionsMonitor<MetadataOptions>
|
|
{
|
|
public static MetadataMonitor Empty { get; } = new(new MetadataOptions());
|
|
|
|
public static MetadataMonitor With(params MetadataSourceOptions[] sources) =>
|
|
new(new MetadataOptions { Sources = [.. sources] });
|
|
|
|
public MetadataOptions CurrentValue { get; } = value;
|
|
|
|
public MetadataOptions Get(string? name) => CurrentValue;
|
|
|
|
public IDisposable? OnChange(Action<MetadataOptions, string?> listener) => null;
|
|
}
|