[英]C# Unit Test NSubstitute Unable to Set Value in ObjectCache
我无法在单元测试中使用Set在ObjectCache中插入缓存条目。
var objectCache = Substitute.For<ObjectCache>();
objectCache.Set("TestKey", object, Arg.Any<DateTimeOffset>());
当我进入代码时
var cachedData = _objectCache.Get("TestKey");
// cachedData is null
我正在使用Nsubstitute来模拟库。
有谁知道如何克服这个问题?
您将需要为Get
方法配置模拟。 请参阅NSubstitute docs中有关return
方法的示例 。
就像是...
var objectCache = Substitute.For<ObjectCache>();
objectCache.Get("TestKey").Returns(...what you want it to return);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.