Example #1
0
        public void StartOrUpdateDelegateSession_should_StartOrRestartDelegateSession_for_course_not_in_session()
        {
            // Given
            httpContextSession.Clear();
            const int newCourseId        = CustomisationId; // Not in session
            const int oldCourseInSession = CustomisationId + 1;

            httpContextSession.SetInt32($"SessionID-{oldCourseInSession}", DefaultSessionId + 1);

            // When
            sessionService.StartOrUpdateDelegateSession(CandidateId, newCourseId, httpContextSession);

            // Then
            A.CallTo(() => sessionDataService.StartOrRestartDelegateSession(CandidateId, newCourseId))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => sessionDataService.StartOrRestartDelegateSession(A <int> ._, A <int> ._))
            .WhenArgumentsMatch(
                (int candidateId, int customisationId) =>
                candidateId != CandidateId || customisationId != newCourseId
                )
            .MustNotHaveHappened();

            A.CallTo(() => sessionDataService.UpdateDelegateSessionDuration(A <int> ._, A <DateTime> ._))
            .MustNotHaveHappened();
        }
Example #2
0
        public void SetUp()
        {
            sessionDataService = A.Fake <ISessionDataService>();
            A.CallTo(() => sessionDataService.StartOrRestartDelegateSession(A <int> ._, A <int> ._))
            .Returns(DefaultSessionId);

            httpContextSession = new MockHttpContextSession();

            sessionService = new SessionService(sessionDataService);
        }
Example #3
0
        public void StartOrUpdateDelegateSession(int candidateId, int customisationId, ISession httpContextSession)
        {
            var currentSessionId = httpContextSession.GetInt32($"SessionID-{customisationId}");

            if (currentSessionId != null)
            {
                sessionDataService.UpdateDelegateSessionDuration(currentSessionId.Value);
            }
            else
            {
                // Clear all session variables
                httpContextSession.Clear();

                // Make and keep track of a new session starting at this request
                var newSessionId = sessionDataService.StartOrRestartDelegateSession(candidateId, customisationId);
                httpContextSession.SetInt32($"SessionID-{customisationId}", newSessionId);
            }
        }