public void Can_GetKeysByPattern()
        {
            if (!(Cache is ICacheClientExtended))
                return;

            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();
            Assert.That(allKeys.Count, Is.EqualTo(10));

            JsConfig.Reset();
        }
        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);
            var roundedToSec = new TimeSpan(ttl.Value.Ticks - (ttl.Value.Ticks % 1000));
            Assert.That(roundedToSec, Is.GreaterThan(TimeSpan.FromSeconds(0)));
            Assert.That(roundedToSec, Is.LessThanOrEqualTo(sessionExpiry));
        }
        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.Reset();
        }
        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"));
        }