Beispiel #1
0
        private void Setup(List <AnswerPotential> countries)
        {
            var nonConditionalQuestion =
                new SelectQuestion(
                    nameof(PupilCountryQuestion),
                    Content.PupilCountryQuestion_Select_Title,
                    Content.PupilCountryQuestion_Select_Label,
                    countries, new Validator
            {
                AllowNull           = false,
                InValidErrorMessage = string.Empty,
                NullErrorMessage    = Content.PupilCountryQuestion_Select_NullErrorMessage,
                ValidatorType       = ValidatorType.None
            });

            SetupNonConditionalQuestion(nonConditionalQuestion);

            var conditionalQuestion = new StringQuestion(
                $"{nameof(PupilCountryQuestion)}.Other",
                Content.PupilCountryQuestion_Other_Title,
                Content.PupilCountryQuestion_Other_Label, new Validator
            {
                InValidErrorMessage = Content.PupilCountryQuestion_Other_InvalidErrorMessage,
                NullErrorMessage    = Content.PupilCountryQuestion_Other_NullErrorMessage,
                ValidatorType       = ValidatorType.AlphabeticalIncludingSpecialChars,
                AllowNull           = false,
            });

            SetupConditionalQuestion(conditionalQuestion, "Other");
        }
        public void Select_ShouldReturnCorrectResult(IQuestion <string> question, Func <string, object> selector)
        {
            // act
            var actual = question.Select(selector);
            // assert
            var expected = new SelectQuestion <string, object>(question, selector);

            actual.Should().BeOfType <SelectQuestion <string, object> >();
            actual.Should().BeEquivalentTo(expected);
        }
Beispiel #3
0
        public void Name_ShouldReturnCorrectValue(
            SelectQuestion <string, object> sut,
            string expectedName)
        {
            // arrange
            Mock.Get(sut.Question).Setup(q => q.Name).Returns(expectedName);
            // act
            var actual = sut.Name;
            // assert
            var expected = "[Select] " + expectedName;

            actual.Should().Be(expected);
        }
Beispiel #4
0
        public static Question CreateContractQuestion(this QuestionEntity entity)
        {
            Question question;

            switch (entity)
            {
            case InputQuestionEntity inputEntity:
                question = new InputQuestion
                {
                    CorrectAnswer = inputEntity.CorrectAnswer
                };
                break;

            case SelectQuestionEntity select:
                question = new SelectQuestion
                {
                    OneCorrectAnswer = select.OneCorrectAnswer,
                    Options          = select.Options.Select(o => new Option
                    {
                        IsCorrect = o.IsCorrect,
                        Title     = o.Title
                    }).ToArray()
                };
                break;

            case GeneralQuestionEntity _:
                question = new GeneralQuestion();
                break;

            default:
                throw new InvalidOperationException($"Can't create contract model from '{entity.GetType().Name}' entity.");
            }

            question.OrderIndex       = entity.OrderIndex;
            question.Title            = entity.Title;
            question.Description      = entity.Description;
            question.MaxAnswerSeconds = entity.MaxAnswerSeconds;

            return(question);
        }
        private static Question Convert(QuestionEntity entity)
        {
            Question question;

            switch (entity)
            {
            case GeneralQuestionEntity generalQuestionEntity:
                question = new GeneralQuestion();
                break;

            case InputQuestionEntity inputQuestionEntity:
                question = new InputQuestion();
                break;

            case SelectQuestionEntity selectQuestionEntity:
                question = new SelectQuestion
                {
                    OneCorrectAnswer = selectQuestionEntity.OneCorrectAnswer,
                    Options          = selectQuestionEntity.Options
                                       .Select(option => new Option
                    {
                        Id    = option.Id,
                        Title = option.Title
                    })
                                       .ToArray()
                };
                break;

            default:
                throw new InvalidOperationException($"Can't cast '{entity.GetType().FullName}'.");
            }

            question.Title       = entity.Title;
            question.Description = entity.Description;
            question.OrderIndex  = entity.OrderIndex;

            return(question);
        }
Beispiel #6
0
        private void BtnAddQuestion_Click_1(object sender, EventArgs e)
        {
            SelectQuestion selectQuestion = new SelectQuestion();

            selectQuestion.ShowDialog();
        }