I'm trying to setup method OnChange in IOptionsMonitor from asp.net core. But it is not obvious for me, why Setup() doesn't work. Btw I saw similar examples here System.NotSupportedException: Unsupported expression: p => (p.UserProfileId == 1) And I have allmost the same. What is the reason of error?
Execution code:
var optionMonitorMock = new Mock<IOptionsMonitor<MyConfig>>();
optionMonitorMock
.Setup(mock => mock.OnChange(It.IsAny<Action<MyConfig>>()));
Code falls with exception:
System.NotSupportedException. Unsupported expression: mock => mock.OnChange< MyConfig>(It.IsAny< Action< MyConfig>>()) Extension methods (here: OptionsMonitorExtensions.OnChange) may not be used in setup / verification expressions.
The asp.net's interface:
public interface IOptionsMonitor<out TOptions>
{
TOptions CurrentValue { get; }
TOptions Get(string name);
IDisposable OnChange(Action<TOptions, string> listener);
}
The model:
public class MyConfig
{
public int Id { get; set; }
public string Options { get; set; }
}