aboutsummaryrefslogtreecommitdiffstats
path: root/tests/slskd.Tests.Unit/TestOptionsMonitor.cs
blob: 6a8909aca864035c12802d81ef57be73668cdf96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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);
        }
    }
}