public SessionLifecycleHandlerBuilder ConfigureSessionWriter(RawSession session)
 {
     SessionWriter
     .Setup(w => w.WriteSession(session, IdleExpirationTime))
     .Returns(Task.CompletedTask);
     return(this);
 }
 public SessionLifecycleHandlerBuilder ConfigureSessionCreator(RawSession session)
 {
     SessionCreator
     .Setup(c => c.CreateSession())
     .Returns(session);
     return(this);
 }
 public SessionLifecycleHandlerBuilder ConfigureExpirationRetriever(RawSession session)
 {
     ExpirationRetriever
     .Setup(r => r.GetExpiration(session))
     .Returns(IdleExpirationTime);
     return(this);
 }
예제 #4
0
 private async Task WriteSessionData(RawSession session, DateTime expirationDate)
 {
     await _sessionStorage.WriteSessionData(
         session.GetId(),
         session.SessionData,
         expirationDate);
 }
예제 #5
0
 private async Task WriteNew(RawSession session, DateTime idleExpirationDate)
 {
     if (!session.IsEmpty())
     {
         await WriteSessionData(session, idleExpirationDate);
     }
 }
예제 #6
0
 public async Task WriteSession(RawSession session, DateTime expirationDate)
 {
     await session.State.Match(
         @new : _ => WriteNew(session, expirationDate),
         existing : state => WriteExisting(state, session, expirationDate),
         existingWithNewId : state => WriteExistingWithNewId(state, session, expirationDate),
         abandoned : WriteAbandonedSession);
 }
예제 #7
0
        private static void TestAbandonsSession(ISessionStateVariant state, ISessionStateVariant expectedState)
        {
            var rawSession = new RawSession(state, new SessionData(CreationDate));
            var session    = CreateSession(rawSession);

            session.Abandon();
            Assert.Equal(rawSession.State, expectedState);
        }
예제 #8
0
        private async Task WriteExistingWithNewId(ExistingWithNewId state, RawSession session, DateTime expirationDate)
        {
            await RemoveSession(state.OldId);

            if (!session.IsEmpty())
            {
                await WriteSessionData(session, expirationDate);
            }
        }
예제 #9
0
        public void PreviousSession_Return_NotNull_IfSessionsNotEmpty()
        {
            var rawSession = new RawSession()
            {
                Duration = 10, Name = "Session 1"
            };

            _morningSlot.AddSession(rawSession);
            Assert.IsNotNull(_morningSlot.PreviousSession, "Null will be returned if No Sessions in the Slot");
        }
 public SessionLifecycleHandlerBuilder ConfigureCookieWriter(RawSession session)
 {
     CookieWriter
     .Setup(w => w.WriteCookie(
                It.IsAny <IRequest>(),
                It.IsAny <IResponse>(),
                session,
                IdleExpirationTime));
     return(this);
 }
예제 #11
0
 private async Task WriteExisting(Existing state, RawSession session, DateTime expirationDate)
 {
     if (session.IsEmpty())
     {
         await RemoveSession(state.Id);
     }
     else
     {
         await WriteSessionData(session, expirationDate);
     }
 }
예제 #12
0
        public void PreviousSessionEndTime_Return_NotNull_IfSessionsNotEmpty()
        {
            var rawSession = new RawSession()
            {
                Duration = 10, Name = "Session 1"
            };

            _morningSlot.AddSession(rawSession);

            var result = _morningSlot.PreviousSessionEndTime;

            Assert.AreEqual(result, new TimeSpan(9, 10, 0), "Previous will be returned if No Sessions in the Slot");
        }
예제 #13
0
        public async Task LoadsSession()
        {
            var sessionId       = new SessionId("1234");
            var sessionData     = new SessionData(DateTime.UnixEpoch);
            var expectedSession = new RawSession(new Existing(sessionId), sessionData);

            var sessionStorage = new Mock <ISessionStorage>(MockBehavior.Strict);

            sessionStorage
            .Setup(s => s.ReadSessionData(sessionId))
            .ReturnsAsync(sessionData);

            var request = MockRequest(sessionId.Value);

            var sessionLoader = CreateSessionLoader(sessionStorage.Object);
            var session       = await sessionLoader.LoadFromRequest(request);

            Assert.Equal(expectedSession, session);
        }
        public void CreatesNewSession()
        {
            var sessionId       = new SessionId("foo-bar-baz");
            var sessionState    = new New(sessionId);
            var creationDate    = DateTime.UnixEpoch;
            var expectedSession = new RawSession(sessionState, new SessionData(creationDate));

            var sessionIdGenerator = new Mock <ISessionIdGenerator>();

            sessionIdGenerator.Setup(g => g.Generate())
            .Returns(sessionId);
            var dateTimeFactory = new Mock <IDateTimeFactory>();

            dateTimeFactory.Setup(f => f.Now())
            .Returns(creationDate);
            var sessionCreator = new SessionCreator(sessionIdGenerator.Object, dateTimeFactory.Object);

            Assert.Equal(expectedSession, sessionCreator.CreateSession());
        }
예제 #15
0
 public bool AddSessionToSlot(Slot slot, RawSession rawSession)
 {
     return(slot.AddSession(rawSession));
 }
예제 #16
0
 private static ISession CreateSession(RawSession rawSession)
 {
     return(new Session.Internal.Session(rawSession, MockSessionIdGenerator()));
 }
 public SessionStub(RawSession rawSession)
 {
     RawSession = rawSession;
 }
예제 #18
0
 private ISession CreateSession(RawSession rawSession)
 => new Internal.Session(rawSession, _sessionIdGenerator);