public void ProcessQuery_with_valid_action_correctly_serialises_contentful_response()
        {
            // Given
            var dataToReturn = new TrackerObjectiveArray(
                new[]
            {
                new Objective(1, new List <int> {
                    6, 7, 8
                }, 4), new Objective(2, new List <int> {
                    17, 18, 19
                }, 0),
            }
                );
            var expectedJson =
                "{\"objectives\":[{\"interactions\":[6,7,8],\"tutorialid\":1,\"possible\":4,\"myscore\":0}," +
                "{\"interactions\":[17,18,19],\"tutorialid\":2,\"possible\":0,\"myscore\":0}]}";

            var query = new TrackerEndpointQueryParams
            {
                Action = "GetObjectiveArray", CustomisationId = 1, SectionId = 1
            };

            A.CallTo(() => actionService.GetObjectiveArray(1, 1)).Returns(dataToReturn);

            // When
            var result = trackerService.ProcessQuery(query, emptySessionVariablesDictionary);

            // Then
            result.Should().Be(expectedJson);
        }
        public void ProcessQuery_with_unknown_action_returns_InvalidAction_response()
        {
            // Given
            var query = new TrackerEndpointQueryParams {
                Action = "InvalidAction"
            };

            // When
            var result = trackerService.ProcessQuery(query, emptySessionVariablesDictionary);

            // Then
            result.Should().Be(TrackerEndpointResponse.InvalidAction);
        }
Esempio n. 3
0
        public void ProcessQuery_with_null_action_returns_NullAction_response()
        {
            // Given
            var query = new TrackerEndpointQueryParams {
                Action = null
            };

            // When
            var result = trackerService.ProcessQuery(query);

            // Then
            result.Should().Be(TrackerEndpointErrorResponse.NullAction);
        }
        public void ProcessQuery_with_GetObjectiveArray_action_passes_query_params()
        {
            // Given
            var query = new TrackerEndpointQueryParams
            {
                Action = "GetObjectiveArray", CustomisationId = 1, SectionId = 2
            };

            // When
            trackerService.ProcessQuery(query, emptySessionVariablesDictionary);

            // Then
            A.CallTo(() => actionService.GetObjectiveArray(1, 2)).MustHaveHappenedOnceExactly();
        }
        public void ProcessQuery_with_valid_action_correctly_serialises_null_response()
        {
            // Given
            TrackerObjectiveArray?dataToReturn = null;

            var query = new TrackerEndpointQueryParams
            {
                Action = "GetObjectiveArray", CustomisationId = 1, SectionId = 1
            };

            A.CallTo(() => actionService.GetObjectiveArray(1, 1)).Returns(dataToReturn);

            // When
            var result = trackerService.ProcessQuery(query, emptySessionVariablesDictionary);

            // Then
            result.Should().Be("{}");
        }
Esempio n. 6
0
        public void ProcessQuery_with_GetObjectiveArrayCc_action_passes_query_params_and_parses_IsPostLearning(
            string?isPostLearningValue,
            bool?expectedBool
            )
        {
            // Given
            var query = new TrackerEndpointQueryParams
            {
                Action = "GetObjectiveArrayCc", CustomisationId = 1, SectionId = 2, IsPostLearning = isPostLearningValue,
            };

            // When
            trackerService.ProcessQuery(query);

            // Then
            A.CallTo(() => actionService.GetObjectiveArrayCc(1, 2, expectedBool))
            .MustHaveHappenedOnceExactly();
        }
Esempio n. 7
0
        public string ProcessQuery(TrackerEndpointQueryParams query)
        {
            if (string.IsNullOrWhiteSpace(query.Action))
            {
                return(TrackerEndpointErrorResponse.NullAction);
            }

            try
            {
                if (Enum.TryParse <TrackerEndpointAction>(query.Action, true, out var action))
                {
                    ITrackerEndpointDataModel?actionDataResult = action switch
                    {
                        TrackerEndpointAction.GetObjectiveArray => trackerActionService.GetObjectiveArray(
                            query.CustomisationId,
                            query.SectionId
                            ),
                        TrackerEndpointAction.GetObjectiveArrayCc => trackerActionService.GetObjectiveArrayCc(
                            query.CustomisationId,
                            query.SectionId,
                            ConvertParamToNullableBoolean(query.IsPostLearning)
                            ),
                        _ => throw new ArgumentOutOfRangeException(),
                    };

                    return(ConvertToJsonString(actionDataResult));
                }

                return(TrackerEndpointErrorResponse.InvalidAction);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Error processing {query.Action}");
                return(TrackerEndpointErrorResponse.UnexpectedException);
            }
        }
Esempio n. 8
0
 public string Index([FromQuery] TrackerEndpointQueryParams queryParams)
 {
     return(trackerService.ProcessQuery(queryParams));
 }
Esempio n. 9
0
        public string Index([FromQuery] TrackerEndpointQueryParams queryParams)
        {
            var sessionVariables = GetSessionVariablesDictionary();

            return(trackerService.ProcessQuery(queryParams, sessionVariables));
        }
Esempio n. 10
0
        public string ProcessQuery(
            TrackerEndpointQueryParams query,
            Dictionary <TrackerEndpointSessionVariable, string?> sessionVariables
            )
        {
            if (string.IsNullOrWhiteSpace(query.Action))
            {
                return(TrackerEndpointResponse.NullAction);
            }

            try
            {
                if (Enum.TryParse <TrackerEndpointAction>(query.Action, true, out var action))
                {
                    if (action == TrackerEndpointAction.GetObjectiveArray)
                    {
                        var result = trackerActionService.GetObjectiveArray(
                            query.CustomisationId,
                            query.SectionId
                            );
                        return(ConvertToJsonString(result));
                    }

                    if (action == TrackerEndpointAction.GetObjectiveArrayCc)
                    {
                        var result = trackerActionService.GetObjectiveArrayCc(
                            query.CustomisationId,
                            query.SectionId,
                            ConvertParamToNullableBoolean(query.IsPostLearning)
                            );
                        return(ConvertToJsonString(result));
                    }

                    if (action == TrackerEndpointAction.StoreDiagnosticJson)
                    {
                        return(trackerActionService.StoreDiagnosticJson(
                                   query.ProgressId,
                                   query.DiagnosticOutcome
                                   ));
                    }

                    if (action == TrackerEndpointAction.StoreAspProgressV2)
                    {
                        return(trackerActionService.StoreAspProgressV2(
                                   query.ProgressId,
                                   query.Version,
                                   sessionVariables[TrackerEndpointSessionVariable.LmGvSectionRow],
                                   query.TutorialId,
                                   query.TutorialTime,
                                   query.TutorialStatus,
                                   query.CandidateId,
                                   query.CustomisationId
                                   ));
                    }

                    if (action == TrackerEndpointAction.StoreAspProgressNoSession)
                    {
                        return(trackerActionService.StoreAspProgressNoSession(
                                   query.ProgressId,
                                   query.Version,
                                   sessionVariables[TrackerEndpointSessionVariable.LmGvSectionRow],
                                   query.TutorialId,
                                   query.TutorialTime,
                                   query.TutorialStatus,
                                   query.CandidateId,
                                   query.CustomisationId,
                                   sessionVariables[TrackerEndpointSessionVariable.LmSessionId]
                                   ));
                    }

                    if (action == TrackerEndpointAction.StoreAspAssessNoSession)
                    {
                        return(trackerActionService.StoreAspAssessNoSession(
                                   query.Version,
                                   query.SectionId,
                                   query.Score,
                                   query.CandidateId,
                                   query.CustomisationId,
                                   sessionVariables[TrackerEndpointSessionVariable.LmSessionId]
                                   ));
                    }

                    throw new ArgumentOutOfRangeException();
                }

                return(TrackerEndpointResponse.InvalidAction);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Error processing {query.Action}");
                return(TrackerEndpointResponse.UnexpectedException);
            }
        }