Beispiel #1
0
        internal static IAppCache SetUpCacheEntryRemove <T>(this IAppCache mockedCachingService, string cacheEntryKey)
        {
            EnsureArgument.IsNotNull(mockedCachingService, nameof(mockedCachingService));
            EnsureArgument.IsNotNullOrEmpty(cacheEntryKey, nameof(cacheEntryKey));

            Logger.LogDebug("Setting up cache entry Remove for '{cacheEntryKey}'", cacheEntryKey);

            mockedCachingService.When(x => x.Remove(Arg.Is <string>(s => s.Equals(cacheEntryKey))))
            .Do(x =>
            {
                Logger.LogDebug("Cache Remove invoked");
                ProjectReflectionShortcuts.SetUpCacheEntryGetMethod(typeof(T)).Invoke(null, new object[] { mockedCachingService, cacheEntryKey, default(T) });
            });

            return(mockedCachingService);
        }
Beispiel #2
0
        internal static IAppCache SetUpCacheEntryAdd <T>(this IAppCache mockedCachingService, string cacheEntryKey)
        {
            EnsureArgument.IsNotNull(mockedCachingService, nameof(mockedCachingService));
            EnsureArgument.IsNotNullOrEmpty(cacheEntryKey, nameof(cacheEntryKey));

            Logger.LogDebug("Setting up cache entry Add for '{cacheEntryKey}'", cacheEntryKey);

            mockedCachingService.When(x => x.Add(Arg.Is <string>(s => s.Equals(cacheEntryKey)), Arg.Any <T>(), Arg.Any <MemoryCacheEntryOptions>()))
            .Do(x =>
            {
                Logger.LogDebug("Cache Add invoked");

                //x provides the args as objects; this means we have to use reflection to set the item type for the SetUpCacheEntryGet method
                var args = x.Args();

                var key   = args[0].ToString();
                var value = args[1];

                ProjectReflectionShortcuts.SetUpCacheEntryGetMethod(value.GetType()).Invoke(null, new[] { mockedCachingService, key, value });
            });

            return(mockedCachingService);
        }