Getting my head all banged up trying to moq the interface below. The GetOrSet has me tripped up. The service comes from here
public interface ICacheService
{
T GetOrSet<T>(string cackeKey, int expiryInMinutes, Func<T> getItemCallback) where T : class;
}
public class CacheService : ICacheService
{
public T GetOrSet<T>(string cacheKey, int expiryInMinutes, Func<T> getItemCallback) where T : class
{
T item = MemoryCache.Default.Get(cacheKey) as T;
if (item == null)
{
item = getItemCallback();
MemoryCache.Default.Add(cacheKey, item, DateTime.Now.AddMinutes(expiryInMinutes));
}
return item;
}
}
Example in code:
var result = _cacheService.GetOrSet(
cacheKey,
cacheExpiry,
() => this.GetRoutes(routeType));
return result.Select(x => new Route(x));