我一次又一次地得到它
System.NotSupportedException: 'Unsupported expression: c => c.ProductMaxLenght
Non-overridable members (here: ConfigurationService.get_ProductMaxLenght)
may not be used in setup / verification expressions.'当我试着调用这个
var configurationService = new Mock<ConfigurationService>();
configurationService.SetupGet(c => c.ProductMaxLenght).Returns(productMaxLength)我在Startup中调用Initialize并从Configuratiom Configuration Service中获取所有数据:
public class ConfigurationService
{
private IConfiguration _configuration;
private int? _productMaxLength;
public int? ProductMaxLenght
{
get
{
if (!_productMaxLength.HasValue)
{
throw new ArgumentNullException(nameof(_productMaxLength));
}
return _productMaxLength;
}
}
public void Initialize(IConfiguration configuration)
{
_configuration = configuration ?? throw new ArgumentNullException(nameof(_configuration));
_productMaxLength = _configuration.GetValue<int>("ProductsMaxLength");
}
}发布于 2021-06-16 02:09:13
您必须将该属性设置为可重写,因此将其设置为virtual
public virtual int? ProductMaxLenght { get ...https://stackoverflow.com/questions/67991390
复制相似问题