public async Task AssertHitingDataStoreAtLeastOnce() { 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); await profileServiceCache.IsActiveAsync(context); context.IsActive.Should().BeTrue(); logger.AccessCount["Cache hit for 1"].Should().Equals(2); }
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); }