Mock IOptionsMonitor
You are calling the constructor of the OptionsMonitor<TOptions>
class incorrectly.
In this case I would have just mocked the IOptionsMonitor<AuthenticationSettings>
interface
For example using Moq
AuthenticationSettings au = new AuthenticationSettings() { ... };
var monitor = Mock.Of<IOptionsMonitor<AuthenticationSettings>>(_ => _.CurrentValue == au);
ActiveDirectoryLogic _SUT = new ActiveDirectoryLogic(monitor);
Achieving the same in NSubstitute:
var optionsMonitorMock = Substitute.For<IOptionsMonitor<AuthenticationSettings>>();
optionsMonitorMock.CurrentValue.Returns(new AuthenticationSettings
{
// values go here
});
Here is another way to do it that doesn't involve trying to set the readonly CurrentValue field.
using Moq;
private IOptionsMonitor<AppConfig> GetOptionsMonitor(AppConfig appConfig)
{
var optionsMonitorMock = new Mock<IOptionsMonitor<AppConfig>>();
optionsMonitorMock.Setup(o => o.CurrentValue).Returns(appConfig);
return optionsMonitorMock.Object;
}