public void MapToWizardQuestionDto_QuestionWithChoiceAnswers_ValidDto(ChoiceAnswerType choiceAnswerType, bool allRequired) { //arrange var choices = GetChoices(); var question = GetQuestion(choiceAnswerType, choices, allRequired); var expectedDto = new Dtos.Wizard.QuestionWithChoiceAnswersDto { Id = question.Id, Choices = ((ChoiceAnswer)question.Answer) .Choices.Select(x => new Dtos.Wizard.ChoiceDto { Content = x.Content, Valid = x.Valid }) .ToList(), AllValidChoicesRequired = allRequired, ChoiceAnswerType = choiceAnswerType, Question = question.Content, Score = question.Answer.MaxScore, Categories = new List <int>() }; //act var mapper = new QuestionServiceMapper(); var dto = mapper.MapToWizardQuestionDto(question); //assert dto.Should().BeEquivalentTo(expectedDto); }
public ChoiceAnswer(int questionId, List <Choice> choices, ChoiceAnswerType choiceAnswerType, float maxScore, bool allValidChoicesRequired = true) : this(choices, choiceAnswerType, maxScore, allValidChoicesRequired) { QuestionId = questionId; }
private static Question GetQuestion(ChoiceAnswerType choiceAnswerType, List <Choice> choices, bool allRequired = true) { int questionId = 5; var authorId = 1; var score = 1f; var answer = new ChoiceAnswer(choices, choiceAnswerType, score, allRequired); var question = new Question(questionId, "Question content", answer, authorId); return(question); }
public static int GetTypeDiscriminatorValue(ChoiceAnswerType choiceAnswerType) { switch (choiceAnswerType) { case ChoiceAnswerType.MultipleChoice: return((int)QuestionTypeDiscriminator.MultipleChoice); case ChoiceAnswerType.SingleChoice: return((int)QuestionTypeDiscriminator.SingleChoice); default: throw new ArgumentException(); } }
public ChoiceAnswer(List <Choice> choices, ChoiceAnswerType choiceAnswerType, float maxScore, bool allValidChoicesRequired = true) { if (choices == null) { throw new ArgumentNullException(); } ChoiceAnswerType = choiceAnswerType; Choices = choices; NumericValue = GetNumericValueFromChoices(choices); MaxScore = maxScore; AllValidChoicesRequired = allValidChoicesRequired; }
public void MapToAnswer_QuestionWithChoiceAnswersDto_ValidAnswer(ChoiceAnswerType choiceAnswerType, bool allRequired) { //arrange var score = 5f; Dtos.Wizard.QuestionDto dto = new Dtos.Wizard.QuestionWithChoiceAnswersDto { Id = 1, ChoiceAnswerType = choiceAnswerType, AllValidChoicesRequired = allRequired, Choices = new List <Dtos.Wizard.ChoiceDto> { new Dtos.Wizard.ChoiceDto { Content = "1", Valid = true }, new Dtos.Wizard.ChoiceDto { Content = "2", Valid = false }, }, Categories = new List <int>(), Question = "Question content", Score = score }; var expectedChoices = new List <Choice> { new Choice { Content = "1", Valid = true }, new Choice { Content = "2", Valid = false } }; var expectedAnswer = new ChoiceAnswer(expectedChoices, choiceAnswerType, score, allRequired); //act var mapper = new QuestionServiceMapper(); var answer = mapper.MapToAnswer(dto); //assert answer.Should().BeEquivalentTo(expectedAnswer); }
public void MapToTestQuestionDto_QuestionWithChoiceAnswers_ValidDto(ChoiceAnswerType choiceAnswerType) { //arrange List <Choice> choices = GetChoices(); Question question = GetQuestion(choiceAnswerType, choices); var expectedDto = new QuestionWithChoiceAnswersDto { Id = question.Id, Question = question.Content, ChoiceAnswerType = choiceAnswerType, Choices = choices.Select(x => x.Content).ToList() }; //act var mapper = new QuestionServiceMapper(); var dto = mapper.MapToTestQuestionDto(question); //assert dto.Should().BeEquivalentTo(expectedDto); }
public void Constructor_ValidData_CreatesObjectWithCalculatedNumericValue(List <Choice> choices, ChoiceAnswerType choiceAnswerType, int expectedNumericValue, float maxScore) { //act ChoiceAnswer choiceAnswer = new ChoiceAnswer(choices, choiceAnswerType, maxScore); //assert choiceAnswer.NumericValue.Should().Be(expectedNumericValue); }