【问题标题】:how we can mock and setup this GetCache我们如何模拟和设置这个 GetCache
【发布时间】:2023-01-03 03:09:49
【问题描述】:

实际数据访问层方法

var cache = _cacheProvider.GetCache<IDictionary<Guid, DataExportRequestModel>>(CacheName.Redis.ToString(),
            new TimeSpan(_cacheTTLDays, 0, 0, 0)); // Timespan of two days

在设置方法中。

_mockRediscacheProvider = new Mock<IRedisCacheProvider>();

在测试方法中

_mockRediscacheProvider.Setup(x=>x.GetCache(CacheName.Redis.ToString(), new TimeSpan(_cacheTTLDays, 0, 0, 0)));

我正在尝试修复此编译错误。

【问题讨论】:

    标签: c# unit-testing nunit moq


    【解决方案1】:

    根据您收到的 CS0411 编译器错误,它失败了,因为编译器无法推断您的 GetCache 方法的类型参数。

    所以用你想要的类型参数更新你的模拟GetCache设置调用。例如:

    _mockRediscacheProvider
     .Setup(x=>x.GetCache<IDictionary<Guid,DataExportRequestModel>>(...);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-19
      • 1970-01-01
      • 1970-01-01
      • 2018-03-02
      • 1970-01-01
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多