public void Caches_Single() { var isCached = false; var cache = new Mock <IAppPolicyCache>(); cache.Setup(x => x.Insert(It.IsAny <string>(), It.IsAny <Func <object> >(), It.IsAny <TimeSpan?>(), It.IsAny <bool>(), It.IsAny <string[]>())) .Callback(() => isCached = true); var defaultPolicy = new SingleItemsOnlyRepositoryCachePolicy <AuditItem, object>(cache.Object, DefaultAccessor, new RepositoryCachePolicyOptions()); AuditItem unused = defaultPolicy.Get(1, id => new AuditItem(1, AuditType.Copy, 123, "test", "blah"), ids => null); Assert.IsTrue(isCached); }
public void Caches_Single() { var isCached = false; var cache = new Mock <IRuntimeCacheProvider>(); cache.Setup(x => x.InsertCacheItem(It.IsAny <string>(), It.IsAny <Func <object> >(), It.IsAny <TimeSpan?>(), It.IsAny <bool>(), It.IsAny <CacheItemPriority>(), It.IsAny <CacheItemRemovedCallback>(), It.IsAny <string[]>())) .Callback(() => { isCached = true; }); var defaultPolicy = new SingleItemsOnlyRepositoryCachePolicy <AuditItem, object>(cache.Object, new RepositoryCachePolicyOptions()); var found = defaultPolicy.Get(1, id => new AuditItem(1, "blah", AuditType.Copy, 123), ids => null); Assert.IsTrue(isCached); }
public void Get_All_Doesnt_Cache() { var cached = new List <string>(); var cache = new Mock <IAppPolicyCache>(); cache.Setup(x => x.Insert(It.IsAny <string>(), It.IsAny <Func <object> >(), It.IsAny <TimeSpan?>(), It.IsAny <bool>(), It.IsAny <string[]>())) .Callback((string cacheKey, Func <object> o, TimeSpan? t, bool b, string[] s) => cached.Add(cacheKey)); cache.Setup(x => x.SearchByKey(It.IsAny <string>())).Returns(new AuditItem[] { }); var defaultPolicy = new SingleItemsOnlyRepositoryCachePolicy <AuditItem, object>(cache.Object, DefaultAccessor, new RepositoryCachePolicyOptions()); AuditItem[] unused = defaultPolicy.GetAll(new object[] { }, ids => new[] { new AuditItem(1, AuditType.Copy, 123, "test", "blah"), new AuditItem(2, AuditType.Copy, 123, "test", "blah2") }); Assert.AreEqual(0, cached.Count); }
public void Get_All_Doesnt_Cache() { var cached = new List <string>(); var cache = new Mock <IRuntimeCacheProvider>(); cache.Setup(x => x.InsertCacheItem(It.IsAny <string>(), It.IsAny <Func <object> >(), It.IsAny <TimeSpan?>(), It.IsAny <bool>(), It.IsAny <CacheItemPriority>(), It.IsAny <CacheItemRemovedCallback>(), It.IsAny <string[]>())) .Callback((string cacheKey, Func <object> o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); }); cache.Setup(x => x.GetCacheItemsByKeySearch(It.IsAny <string>())).Returns(new AuditItem[] { }); var defaultPolicy = new SingleItemsOnlyRepositoryCachePolicy <AuditItem, object>(cache.Object, new RepositoryCachePolicyOptions()); var found = defaultPolicy.GetAll(new object[] { }, ids => new[] { new AuditItem(1, "blah", AuditType.Copy, 123), new AuditItem(2, "blah2", AuditType.Copy, 123) }); Assert.AreEqual(0, cached.Count); }