Redis缓存清除C#

Redis Cache Clear C#

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

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.'

希望对您有所帮助。

您正在创建一个 Mock<>,它默认使用 MockBehavior.Strict 而

MockBehavior.Strict : Causes the mock to always throw an exception for invocations that don't have a corresponding setup.

Somewhere in your code you are invoking members that have no setup configured. I suggest create a setup for all members you intend to invoke during your tests

like this:

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");