public void CacheNamePersists() { var expectedName = "TestName"; using (Memocache.Memocache sut = new Memocache.Memocache(expectedName, new CacheItemPolicy())) { Assert.AreEqual(expectedName, sut.Name); } }
public void DefaultPolicyPersistsToCache() { var cache = A.Fake <ICache>(); var cacheItemPolicy = new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromMilliseconds(10) }; using (Memocache.Memocache sut = new Memocache.Memocache("cacheName", cacheItemPolicy, cache)) { Assert.AreEqual(TimeSpan.FromMilliseconds(10), cache.DefaultPolicy.SlidingExpiration); } }
public void CacheInjectionWorks() { var cache = A.Fake <ICache>(); A.CallTo(() => cache.Add(string.Empty, 0)).WithAnyArguments().DoesNothing(); Func <int, int, int> m; using (Memocache.Memocache sut = new Memocache.Memocache("cacheName", new CacheItemPolicy(), cache)) { m = sut.Cache <int, int, int>(Multiply); var answer = m(2, 2); A.CallTo(() => cache.Add(string.Empty, 0)).WithAnyArguments().MustHaveHappened(); } }
public void SimpleCacheTest2ArgumentFunc() { using (Memocache.Memocache sut = new Memocache.Memocache("cacheName", new CacheItemPolicy())) { var m = sut.Cache <int, int, int>(Multiply); var answer = m(2, 2); var secondCall = m(2, 2); var thirdcall = m(3, 3); Assert.AreEqual(4, answer); Assert.AreEqual(answer, secondCall); Assert.AreEqual(9, thirdcall); } }
public void CacheAllowsMultipleCachingOfSame() { using (Memocache.Memocache sut = new Memocache.Memocache("cacheName", new CacheItemPolicy())) { var m = sut.Cache <int, int, int>(Multiply); m = sut.Cache <int, int, int>(Multiply); var answer = m(2, 2); var secondCall = m(2, 2); var thirdcall = m(3, 3); Assert.AreEqual(4, answer); Assert.AreEqual(answer, secondCall); Assert.AreEqual(9, thirdcall); } }