コード例 #1
0
        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, HostContext.GetDefaultSessionExpiry());

            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;
        }
コード例 #2
0
        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 = HostContext.GetDefaultSessionExpiry();

            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));
        }
コード例 #3
0
        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, HostContext.GetDefaultSessionExpiry());

            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"));
        }
コード例 #4
0
        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"));
        }
コード例 #5
0
        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, HostContext.GetDefaultSessionExpiry());

            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;
        }
コード例 #6
0
        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 = HostContext.GetDefaultSessionExpiry();
            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));
        }