StoreAspAssessNoSession_returns_exception_from_query_param_and_progress_validation() { // Given A.CallTo( () => storeAspService.GetProgressAndValidateInputsForStoreAspAssess( A <int?> ._, A <int?> ._, A <int?> ._, A <int?> ._ ) ).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); A.CallTo( () => storeAspService.GetProgressAndValidateInputsForStoreAspAssess( DefaultCustomisationVersion, DefaultScore, DefaultDelegateId, DefaultCustomisationId ) ).MustHaveHappenedOnceExactly(); A.CallTo(() => storeAspService.GetAndValidateSectionAssessmentDetails(A <int?> ._, A <int> ._)) .MustNotHaveHappened(); A.CallTo( () => storeAspService.ParseSessionIdAndValidateSessionForStoreAspNoSessionEndpoints( A <string?> ._, A <int> ._, A <int> ._, A <TrackerEndpointResponse> ._ ) ).MustNotHaveHappened(); CallsAfterStoreAspAssessValidationMustNotHaveHappened(); } }
GetProgressAndValidateInputsForStoreAspAssess_returns_StoreAspAssessException_if_a_query_param_is_null( int?version, int?candidateId, int?customisationId ) { // When var result = storeAspService.GetProgressAndValidateInputsForStoreAspAssess( version, 100, candidateId, customisationId ); // Then using (new AssertionScope()) { result.validationResponse.Should().Be(TrackerEndpointResponse.StoreAspAssessException); result.progress.Should().BeNull(); A.CallTo(() => courseDataService.GetDelegateCoursesInfo(A <int> ._)).MustNotHaveHappened(); } }
public TrackerEndpointResponse StoreAspAssessNoSession( int?version, int?sectionId, int?score, int?candidateId, int?customisationId, string?sessionId ) { var(validationResponse, progress) = storeAspService.GetProgressAndValidateInputsForStoreAspAssess( version, score, candidateId, customisationId ); if (validationResponse != null) { return(validationResponse); } var(sectionValidationResponse, assessmentDetails) = storeAspService.GetAndValidateSectionAssessmentDetails(sectionId, customisationId !.Value); if (sectionValidationResponse != null) { return(sectionValidationResponse); } var currentUtcTime = clockService.UtcNow; if (sessionId != null) { var(sessionValidationResponse, parsedSessionId) = storeAspService.ParseSessionIdAndValidateSessionForStoreAspNoSessionEndpoints( sessionId, candidateId !.Value, customisationId.Value, TrackerEndpointResponse.StoreAspAssessException ); if (sessionValidationResponse != null) { return(sessionValidationResponse); } sessionDataService.UpdateDelegateSessionDuration(parsedSessionId !.Value, currentUtcTime); } var previousAssessAttempts = progressDataService.GetAssessAttemptsForProgressSection( progress !.ProgressId, assessmentDetails !.SectionNumber ).ToList(); var duplicateCreationTimeThreshold = currentUtcTime.AddMinutes(-NumberOfMinutesForDuplicateAttemptThreshold); var duplicateRecord = previousAssessAttempts.FirstOrDefault( aa => aa.Score == score && aa.Date >= duplicateCreationTimeThreshold ); var numberOfFailedAttempts = previousAssessAttempts.Count(aa => !aa.Status); if (duplicateRecord == null) { var assessmentPassed = score >= assessmentDetails.PlaPassThreshold; progressDataService.InsertAssessAttempt( candidateId !.Value, customisationId.Value, version !.Value, currentUtcTime, assessmentDetails.SectionNumber, score !.Value, assessmentPassed, progress.ProgressId ); numberOfFailedAttempts += assessmentPassed ? 0 : 1; } if (assessmentDetails.AssessAttempts > 0 && numberOfFailedAttempts >= assessmentDetails.AssessAttempts) { progressDataService.LockProgress(progress.ProgressId); } else { progressService.CheckProgressForCompletionAndSendEmailIfCompleted(progress); } return(TrackerEndpointResponse.Success); }