public void TestableDatabaseSecurityTokenCache_ParametersGetsExposedCorrectly() { // Tests / documents that the specific C# constructor precedence relied on in this test works as intended. var cache = new TestableDatabaseSecurityTokenCache(new AlwaysMissingSessionSecurityTokenCache(), new AlwaysMissingSessionSecurityTokenStore()); cache.Should().NotBeNull(); cache.SessionSecurityTokenCache.Should().BeOfType <AlwaysMissingSessionSecurityTokenCache>(); cache.SessionSecurityTokenStore.Should().BeOfType <AlwaysMissingSessionSecurityTokenStore>(); }
public void Get_SessionSecurityTokenNotInCache_ReturnsNull(SessionSecurityTokenCache memoryCache, SessionSecurityTokenStore store) { var token = CreateToken(DateTime.UtcNow, TimeSpan.MaxValue); var key = CreateKeyFromToken(token); var cache = new TestableDatabaseSecurityTokenCache(memoryCache, store); var roundtrippedToken = cache.Get(key); roundtrippedToken.Should().BeNull(); }
public void AddOrUpdate_EternalSessionSecurityToken_GetReturnsToken(SessionSecurityTokenCache memoryCache, SessionSecurityTokenStore store) { var token = CreateToken(DateTime.UtcNow, TimeSpan.MaxValue); var key = CreateKeyFromToken(token); var cache = new TestableDatabaseSecurityTokenCache(memoryCache, store); cache.AddOrUpdate(key, token, token.KeyExpirationTime); var roundtrippedToken = cache.Get(key); roundtrippedToken.ShouldBeEquivalentTo(token); }
public void Get_SessionSecurityTokenDeletedFromCache_ReturnsNull(SessionSecurityTokenCache memoryCache, SessionSecurityTokenStore store) { var token = CreateToken(DateTime.UtcNow, TimeSpan.MaxValue); var key = CreateKeyFromToken(token); var cache = new TestableDatabaseSecurityTokenCache(memoryCache, store); cache.AddOrUpdate(key, token, token.KeyExpirationTime); cache.Remove(key); var roundtrippedToken = cache.Get(key); roundtrippedToken.Should().BeNull(); }
public void AddOrUpdate_SessionSecurityTokenExpiredInCache_GetReturnsToken(SessionSecurityTokenCache memoryCache, SessionSecurityTokenStore store) { // It is, unfortunately, impossible to create a SessionSecurityToken that is expired... var token = CreateToken(DateTime.UtcNow, TimeSpan.FromMilliseconds(500)); var key = CreateKeyFromToken(token); var cache = new TestableDatabaseSecurityTokenCache(memoryCache, store); cache.AddOrUpdate(key, token, token.KeyExpirationTime); Thread.Sleep(TimeSpan.FromSeconds(1)); var roundtrippedToken = cache.Get(key); roundtrippedToken.ShouldBeEquivalentTo(token); }