1

我无法在单元测试中使用Set在 ObjectCache 中插入缓存条目。

var objectCache = Substitute.For<ObjectCache>();
objectCache.Set("TestKey", object, Arg.Any<DateTimeOffset>());

当我进入我的代码时

var cachedData = _objectCache.Get("TestKey");
// cachedData is null

我正在使用 Nsubstitute 来模拟库。

有谁知道如何克服这个问题?

4

1 回答 1

4

您将需要为该Get方法配置模拟。请参阅NSubstitute 文档return中的方法示例。

就像是...

var objectCache = Substitute.For<ObjectCache>();
objectCache.Get("TestKey").Returns(...what you want it to return);
于 2018-01-24T22:59:40.113 回答