diff options
Diffstat (limited to 'tests/slskd.Tests.Unit/TestOptionsMonitor.cs')
| -rw-r--r-- | tests/slskd.Tests.Unit/TestOptionsMonitor.cs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/slskd.Tests.Unit/TestOptionsMonitor.cs b/tests/slskd.Tests.Unit/TestOptionsMonitor.cs new file mode 100644 index 00000000..6c16adf5 --- /dev/null +++ b/tests/slskd.Tests.Unit/TestOptionsMonitor.cs @@ -0,0 +1,40 @@ +using System; +using Microsoft.Extensions.Options; +using Moq; + +namespace slskd.Tests.Unit +{ + public class TestOptionsMonitor<TOptions> : IOptionsMonitor<TOptions> + { + private Action<TOptions, string> _listener; + + public TestOptionsMonitor(TOptions currentValue) + { + CurrentValue = currentValue; + } + + public TOptions CurrentValue { get; private set; } + + public TOptions Get(string name) + { + return CurrentValue; + } + + public void Set(TOptions value) + { + CurrentValue = value; + _listener.Invoke(value, null); + } + + public IDisposable OnChange(Action<TOptions, string> listener) + { + _listener = listener; + return new Mock<IDisposable>().Object; + } + + public void RaiseOnChange(TOptions options) + { + _listener(options, null); + } + } +} |
