public CachingProfileServiceTests() { inner = new FakeProfileService(); memoryCache = new MemoryCache(new MemoryCacheOptions()); logger = new FakeLogger <FakeCache <IsActiveContextCacheEntry> >(); cache = new FakeCache <IsActiveContextCacheEntry>(memoryCache, logger); profileServiceCache = new CachingProfileService <FakeProfileService>(inner, cache, new ProfileServiceCachingOptions <FakeProfileService>(), Mock.Of <ILogger <CachingProfileService <FakeProfileService> > >()); }
public async Task AssertExpiryOfCacheEntry() { var profileServiceCache = new CachingProfileService <FakeProfileService>(inner, cache, new ProfileServiceCachingOptions <FakeProfileService>() { Expiration = TimeSpan.FromSeconds(1) }, Mock.Of <ILogger <CachingProfileService <FakeProfileService> > >()); var principal = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim> { new Claim("sub", "1") })); var context = new IsActiveContext(principal, new Client(), "test"); await profileServiceCache.IsActiveAsync(context); await profileServiceCache.IsActiveAsync(context); Thread.Sleep(1000); await profileServiceCache.IsActiveAsync(context); await profileServiceCache.IsActiveAsync(context); context.IsActive.Should().BeTrue(); logger.AccessCount["Cache hit for 1"].Should().Equals(2); }