Redis缓存清除C#

时间:2017-09-12 08:51:03

标签: c# azure-redis-cache

我尝试使用上面的方法删除数据

public virtual void ClearOrderTypeCache()
{
    orderTypeList = null;
    cacheService.Set<OrderTypeProjection[]>(orderTypeCacheKey, null);
}

但是当我尝试使用它时我有一个例外

ICacheService.Set<OrderTypeProjection[]>("189b5a92-e728-405a-b13a-e3b62c870845-OrderTypes", null) 
invocation failed with mock behavior Strict.
All invocations on the mock must have a corresponding setup.'

1 个答案:

答案 0 :(得分:0)

我希望这会有所帮助。

您正在创建一个Mock&lt;&gt;,默认情况下使用MockBehavior.Strict

  

MockBehavior.Strict:使mock总是抛出异常   没有相应设置的调用。

     

在代码中的某个位置,您正在调用没有设置的成员   配置。我建议为你想要的所有成员创建一个设置   在测试期间调用

     像这样:

var httpStatusCode = System.Net.HttpStatusCode.BadRequest;//or what ever you want it to be
responseMessage.Setup(m => m.StatusCode).Returns(httpStatusCode);
responseMessage.Setup(m => m.ReadContentAsString()).Returns("Put your return string here");
相关问题