public void Can_GetKeysByPattern() { if (!(Cache is ICacheClientExtended)) { return; } ((PocoDynamo)((DynamoDbCacheClient)Cache).Dynamo).PagingLimit = 2; JsConfig.ExcludeTypeInfo = true; 5.Times(i => { IAuthSession session = new CustomAuthSession { Id = "sess-" + i, UserAuthId = i.ToString(), Custom = "custom" + i }; var sessionKey = SessionFeature.GetSessionKey(session.Id); Cache.Set(sessionKey, session, SessionFeature.DefaultSessionExpiry); Cache.Set("otherkey" + i, i); }); var sessionPattern = IdUtils.CreateUrn <IAuthSession>(""); Assert.That(sessionPattern, Is.EqualTo("urn:iauthsession:")); var sessionKeys = Cache.GetKeysStartingWith(sessionPattern).ToList(); Assert.That(sessionKeys.Count, Is.EqualTo(5)); Assert.That(sessionKeys.All(x => x.StartsWith("urn:iauthsession:"))); var allSessions = Cache.GetAll <IAuthSession>(sessionKeys); Assert.That(allSessions.Values.Count(x => x != null), Is.EqualTo(sessionKeys.Count)); var allKeys = Cache.GetAllKeys().ToList() .Where(x => x.StartsWith("urn:iauthsession:") || x.StartsWith("otherkey")).ToList(); Assert.That(allKeys.Count, Is.EqualTo(10)); JsConfig.Reset(); }
public async Task Can_GetKeysByPattern() { if (!(Cache is ICacheClientExtended)) { return; } JsConfig.ExcludeTypeInfo = true; for (int i = 0; i < 5; i++) { IAuthSession session = new CustomAuthSession { Id = "sess-" + i, UserAuthId = i.ToString(), Custom = "custom" + i }; var sessionKey = SessionFeature.GetSessionKey(session.Id); await Cache.SetAsync(sessionKey, session, SessionFeature.DefaultSessionExpiry); await Cache.SetAsync("otherkey" + i, i); } var sessionPattern = IdUtils.CreateUrn <IAuthSession>(""); Assert.That(sessionPattern, Is.EqualTo("urn:iauthsession:")); #if !NETFX var sessionKeys = await Cache.GetKeysStartingWithAsync(sessionPattern).ToListAsync(); Assert.That(sessionKeys.Count, Is.EqualTo(5)); Assert.That(sessionKeys.All(x => x.StartsWith("urn:iauthsession:"))); var allSessions = await Cache.GetAllAsync <IAuthSession>(sessionKeys); Assert.That(allSessions.Values.Count(x => x != null), Is.EqualTo(sessionKeys.Count)); var allKeys = (await Cache.GetAllKeysAsync().ToListAsync()).ToList(); Assert.That(allKeys.Count, Is.EqualTo(10)); #endif JsConfig.Reset(); }
public async Task Can_retrieve_IAuthSession() { IAuthSession session = new CustomAuthSession { Id = "sess-1", UserAuthId = "1", Custom = "custom" }; var sessionKey = SessionFeature.GetSessionKey(session.Id); await Cache.SetAsync(sessionKey, session, SessionFeature.DefaultSessionExpiry); var sessionCache = await Cache.GetAsync <IAuthSession>(sessionKey); Assert.That(sessionCache, Is.Not.Null); var typedSession = sessionCache as CustomAuthSession; Assert.That(typedSession, Is.Not.Null); Assert.That(typedSession.Custom, Is.EqualTo("custom")); }
public void Can_GetKeysByPattern() { if (!(Cache is ICacheClientExtended)) return; ((PocoDynamo)((DynamoDbCacheClient)Cache).Dynamo).PagingLimit = 2; JsConfig.ExcludeTypeInfo = true; 5.Times(i => { IAuthSession session = new CustomAuthSession { Id = "sess-" + i, UserAuthId = i.ToString(), Custom = "custom" + i }; var sessionKey = SessionFeature.GetSessionKey(session.Id); Cache.Set(sessionKey, session, SessionFeature.DefaultSessionExpiry); Cache.Set("otherkey" + i, i); }); var sessionPattern = IdUtils.CreateUrn<IAuthSession>(""); Assert.That(sessionPattern, Is.EqualTo("urn:iauthsession:")); var sessionKeys = Cache.GetKeysStartingWith(sessionPattern).ToList(); Assert.That(sessionKeys.Count, Is.EqualTo(5)); Assert.That(sessionKeys.All(x => x.StartsWith("urn:iauthsession:"))); var allSesssions = Cache.GetAll<IAuthSession>(sessionKeys); Assert.That(allSesssions.Values.Count(x => x != null), Is.EqualTo(sessionKeys.Count)); var allKeys = Cache.GetAllKeys().ToList() .Where(x => x.StartsWith("urn:iauthsession:") || x.StartsWith("otherkey")).ToList(); Assert.That(allKeys.Count, Is.EqualTo(10)); JsConfig.Reset(); }
public void Can_retrieve_IAuthSession_with_global_ExcludeTypeInfo_set() { JsConfig.ExcludeTypeInfo = true; IAuthSession session = new CustomAuthSession { Id = "sess-1", UserAuthId = "1", Custom = "custom" }; var sessionKey = SessionFeature.GetSessionKey(session.Id); Cache.Set(sessionKey, session, SessionFeature.DefaultSessionExpiry); var sessionCache = Cache.Get<IAuthSession>(sessionKey); Assert.That(sessionCache, Is.Not.Null); var typedSession = sessionCache as CustomAuthSession; Assert.That(typedSession, Is.Not.Null); Assert.That(typedSession.Custom, Is.EqualTo("custom")); JsConfig.ExcludeTypeInfo = false; }
public void Can_retrieve_TimeToLive_on_IAuthSession() { IAuthSession session = new CustomAuthSession { Id = "sess-1", UserAuthId = "1", Custom = "custom" }; var sessionKey = SessionFeature.GetSessionKey(session.Id); Cache.Remove(sessionKey); var ttl = Cache.GetTimeToLive(sessionKey); Assert.That(ttl, Is.Null); Cache.Set(sessionKey, session); ttl = Cache.GetTimeToLive(sessionKey); Assert.That(ttl.Value, Is.EqualTo(TimeSpan.MaxValue)); var sessionExpiry = SessionFeature.DefaultSessionExpiry; Cache.Set(sessionKey, session, sessionExpiry); ttl = Cache.GetTimeToLive(sessionKey); Assert.That(ttl.Value, Is.GreaterThan(TimeSpan.FromSeconds(0))); Assert.That(ttl.Value, Is.LessThanOrEqualTo(sessionExpiry)); }
public void Can_retrieve_IAuthSession() { IAuthSession session = new CustomAuthSession { Id = "sess-1", UserAuthId = "1", Custom = "custom" }; var sessionKey = SessionFeature.GetSessionKey(session.Id); Cache.Set(sessionKey, session, SessionFeature.DefaultSessionExpiry); var sessionCache = Cache.Get<IAuthSession>(sessionKey); Assert.That(sessionCache, Is.Not.Null); var typedSession = sessionCache as CustomAuthSession; Assert.That(typedSession, Is.Not.Null); Assert.That(typedSession.Custom, Is.EqualTo("custom")); }