I am trying to write a unit test for some code that uses IMemoryCache in controller
if(!_memoryCache.TryGetValue(cacheKey,out IEnumerable<myClass> class))
{
class = await _myService.GetMyData(date, dateTo);
var cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromSeconds(_appSettings.Value.cacheDuration));
_memoryCache.Set(cacheKey, class, cacheEntryOptions);
}
Note: I am trying to mock following code:.How to write unit test cases for ImemoryCache,
_memoryCache = new Mock<IMemoryCache>();
_memoryCache.Setup(c => c.Get(It.Is<string>(k => k == mycacheKey))).Returns(mysampleclasslist);