diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-02-06 17:10:31 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-02-06 17:10:31 -0600 |
| commit | 4ab8c662d2fa04049fdb57a2b0a300dd4239b8b6 (patch) | |
| tree | afe94e32088a6bcfdb84388f641d5bce14c7de65 /tests/slskd.Tests.Unit/TestOptionsMonitor.cs | |
| parent | d25de33ba639e4633f7bcd65290b1e479d2927fd (diff) | |
| download | slskd-4ab8c662d2fa04049fdb57a2b0a300dd4239b8b6.tar.gz | |
add some things to make testing easier
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..92cf2fa5 --- /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); + } + } +} |
