public void GetAnswers_when_SubmittedAnswer_empty_Returns_empty()
        {
            _submittedAnswer = string.Empty;

            var result = CheckBoxListMapper.GetAnswers(_applicationId, _sequenceNumber, _sectionNumber, _pageId, _question, _submittedAnswer);

            CollectionAssert.IsEmpty(result);
        }
        public void GetAnswers_when_SubmittedAnswer_null_Returns_empty()
        {
            _submittedAnswer = null;

            var result = CheckBoxListMapper.GetAnswers(_applicationId, _pageId, _question, _submittedAnswer);

            CollectionAssert.IsEmpty(result);
        }
コード例 #3
0
        private static List <SubmittedApplicationAnswer> ExtractQuestionAnswers(Guid applicationId, string pageId, Question question, ICollection <Answer> answers)
        {
            var submittedQuestionAnswers = new List <SubmittedApplicationAnswer>();

            var questionId = question.QuestionId;

            // Note: RoATP only has a single answer per question
            var questionAnswer = answers?.FirstOrDefault(ans => ans.QuestionId == questionId && !string.IsNullOrWhiteSpace(ans.Value));

            if (questionAnswer != null)
            {
                switch (question.Input.Type.ToUpper())
                {
                case "TABULARDATA":
                    var tabularData    = JsonConvert.DeserializeObject <TabularData>(questionAnswer.Value);
                    var tabularAnswers = TabularDataMapper.GetAnswers(applicationId, pageId, question, tabularData);
                    submittedQuestionAnswers.AddRange(tabularAnswers);
                    break;

                case "CHECKBOXLIST":
                case "COMPLEXCHECKBOXLIST":
                    var checkboxAnswers = CheckBoxListMapper.GetAnswers(applicationId, pageId, question, questionAnswer.Value);
                    submittedQuestionAnswers.AddRange(checkboxAnswers);
                    break;

                default:
                    var submittedAnswer = SubmittedAnswerMapper.GetAnswer(applicationId, pageId, question, questionAnswer.Value);
                    submittedQuestionAnswers.Add(submittedAnswer);
                    break;
                }

                // We have to do similar for extracting any matching further question
                if (question.Input.Options != null)
                {
                    var submittedFurtherQuestionAnswers = new List <SubmittedApplicationAnswer>();

                    var submittedValues = submittedQuestionAnswers.Where(sqa => sqa.QuestionId == questionId).Select(ans => ans.Answer);

                    foreach (var option in question.Input.Options.Where(opt => opt.FurtherQuestions != null))
                    {
                        // Check that option was selected
                        if (submittedValues.Contains(option.Value))
                        {
                            foreach (var furtherQuestion in option.FurtherQuestions)
                            {
                                var furtherQuestionAnswers = ExtractQuestionAnswers(applicationId, pageId, furtherQuestion, answers);
                                submittedFurtherQuestionAnswers.AddRange(furtherQuestionAnswers);
                            }
                        }
                    }

                    submittedQuestionAnswers.AddRange(submittedFurtherQuestionAnswers);
                }
            }

            return(submittedQuestionAnswers);
        }
        public void GetAnswers_Returns_expected_result()
        {
            var expectedItemCount = _question.Input.Options.Count;

            var result = CheckBoxListMapper.GetAnswers(_applicationId, _pageId, _question, _submittedAnswer);

            CollectionAssert.IsNotEmpty(result);
            Assert.AreEqual(expectedItemCount, result.Count);

            for (int index = 0; index < result.Count; index++)
            {
                Assert.AreEqual(_applicationId, result[index].ApplicationId);
                Assert.AreEqual(_pageId, result[index].PageId);
                Assert.AreEqual(_question.QuestionId, result[index].QuestionId);
                Assert.AreEqual(_question.Input.Type, result[index].QuestionType);
                Assert.AreEqual(_question.Input.Options[index].Value, result[index].Answer);
            }
        }