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); }
private async Task WriteSessionData(RawSession session, DateTime expirationDate) { await _sessionStorage.WriteSessionData( session.GetId(), session.SessionData, expirationDate); }
private async Task WriteNew(RawSession session, DateTime idleExpirationDate) { if (!session.IsEmpty()) { await WriteSessionData(session, idleExpirationDate); } }
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); }
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); }
private async Task WriteExistingWithNewId(ExistingWithNewId state, RawSession session, DateTime expirationDate) { await RemoveSession(state.OldId); if (!session.IsEmpty()) { await WriteSessionData(session, expirationDate); } }
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); }
private async Task WriteExisting(Existing state, RawSession session, DateTime expirationDate) { if (session.IsEmpty()) { await RemoveSession(state.Id); } else { await WriteSessionData(session, expirationDate); } }
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"); }
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()); }
public bool AddSessionToSlot(Slot slot, RawSession rawSession) { return(slot.AddSession(rawSession)); }
private static ISession CreateSession(RawSession rawSession) { return(new Session.Internal.Session(rawSession, MockSessionIdGenerator())); }
public SessionStub(RawSession rawSession) { RawSession = rawSession; }
private ISession CreateSession(RawSession rawSession) => new Internal.Session(rawSession, _sessionIdGenerator);