示例#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();
        }
        public void StoreAspAssessNoSession_returns_exception_from_session_validation()
        {
            // Given
            GivenRequiredValidationForStoreAspAssessPassesAndReturnsDefaults();
            A.CallTo(
                () => storeAspService.ParseSessionIdAndValidateSessionForStoreAspNoSessionEndpoints(
                    A <string?> ._,
                    A <int> ._,
                    A <int> ._,
                    A <TrackerEndpointResponse> ._
                    )
                ).Returns((TrackerEndpointResponse.StoreAspAssessException, null));

            // When
            var result = trackerActionService.StoreAspAssessNoSession(
                DefaultCustomisationVersion,
                DefaultSectionId,
                DefaultScore,
                DefaultDelegateId,
                DefaultCustomisationId,
                DefaultSessionId.ToString()
                );

            // Then
            using (new AssertionScope())
            {
                result.Should().Be(TrackerEndpointResponse.StoreAspAssessException);
                RequiredValidationForStoreAspAssessMustHaveBeenCalledOnceWithDefaultValues();
                A.CallTo(
                    () => storeAspService.ParseSessionIdAndValidateSessionForStoreAspNoSessionEndpoints(
                        DefaultSessionId.ToString(),
                        DefaultDelegateId,
                        DefaultCustomisationId,
                        TrackerEndpointResponse.StoreAspAssessException
                        )
                    ).MustHaveHappenedOnceExactly();
                A.CallTo(() => sessionDataService.UpdateDelegateSessionDuration(A <int> ._, A <DateTime> ._))
                .MustNotHaveHappened();
                CallsAfterStoreAspAssessValidationMustNotHaveHappened();
            }
        }
示例#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);
            }
        }