在.net core 项目中如何来mock配置文件读取的IOptionsMonitor:
第一种:
var options = new ServiceOptions();
var optionsMocker = new Mock<IOptionsMonitor<ServiceOptions>>();
optionsMocker.Setup(m => m.CurrentValue).Returns(options);
第二种:
var options = new ServiceOptions();
var monitor = Mock.Of<IOptionsMonitor<AuthenticationSettings>>(a => a.CurrentValue == options);
本文介绍在.NET Core项目中使用两种方法mock配置文件读取的IOptionsMonitor。第一种方法通过创建ServiceOptions实例并使用Moq库的Mock类进行设置。第二种方法则直接使用Mock.Of方法创建IOptionsMonitor实例。

800

被折叠的 条评论
为什么被折叠?



