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 void MapToTestQuestionWithResultDto_QuestionWithChoiceAnswers_ValidDto() { //arrange var userNumericAnswer = 5; var choices = GetChoices(); var question = GetQuestion(ChoiceAnswerType.MultipleChoice, choices); var userAnswer = GetChoiceUserAnswer(question.Id, userNumericAnswer); var expectedChoiceDtos = new List <ChoiceDto> { new ChoiceDto { Correct = choices[0].Valid, Value = choices[0].Content, UserAnswer = true }, new ChoiceDto { Correct = choices[1].Valid, Value = choices[1].Content, UserAnswer = false }, new ChoiceDto { Correct = choices[2].Valid, Value = choices[2].Content, UserAnswer = true }, }; QuestionWithResultDto expectedDto = new QuestionWithChoiceAnswerResultDto { Question = question.Content, QuestionId = question.Id, Choices = expectedChoiceDtos }; //act var mapper = new QuestionServiceMapper(); var dto = mapper.MapToTestQuestionWithResultDto(question, userAnswer); //assert dto.Should().BeEquivalentTo(expectedDto); }
public void MapToTestQuestionDto_QuestionWithWrittenAnswer_ValidDto() { //arrange var expectedDto = new QuestionWithWrittenAnswerDto { Id = questionWithWrittenAnswer.Id, Question = questionWithWrittenAnswer.Content }; //act var mapper = new QuestionServiceMapper(); var dto = mapper.MapToTestQuestionDto(questionWithWrittenAnswer); //assert dto.Should().BeEquivalentTo(expectedDto); }
public async Task StudentShouldGetTheirAnswers() { int testId = controllerFixture.ScheduledTest.Id; var student = fixture.OrganizationOwnerMembers[fixture.UserId].First(); var answers = controllerFixture.UserAnswers.Where(x => x.UserId == student.Id); var mapper = new QuestionServiceMapper(); var expectedAnswerDtos = answers.Select(mapper.MapToTestQuestionAnswerDto); var token = fixture.GenerateToken(student); var response = await fixture.RequestSender.GetAsync($"tests/{testId}/answers", token); response.StatusCode.Should().Be(HttpStatusCode.OK); var responseData = await response.Content.ReadAsStringAsync(); var result = fixture.Deserialize <List <QuestionAnswerDto> >(responseData); result.Should().BeEquivalentTo(expectedAnswerDtos); }
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 MapToTestQuestionAnswerDto_ChoiceUserAnswer_ValidDto() { //arrange int questionId = 2; int numericValue = 5; UserAnswer userAnswer = GetChoiceUserAnswer(questionId, numericValue); var expectedDto = new ChoiceAnswerDto { QuestionId = questionId, Value = numericValue }; //act var mapper = new QuestionServiceMapper(); var dto = mapper.MapToTestQuestionAnswerDto(userAnswer); //assert dto.Should().BeEquivalentTo(expectedDto); }
public void MapToTestQuestionAnswerDto_WrittenUserAnswer_ValidDto() { //arrange int questionId = 4; string userAnswerContent = "user answer value"; UserAnswer userAnswer = GetWrittenUserAnswer(questionId, userAnswerContent); var expectedDto = new WrittenAnswerDto { QuestionId = questionId, Text = userAnswerContent }; //act var mapper = new QuestionServiceMapper(); var dto = mapper.MapToTestQuestionAnswerDto(userAnswer); //assert dto.Should().BeEquivalentTo(expectedDto); }
public void MapToWizardQuestionDto_QuestionWithWrittenAnswers_ValidDto() { //arrange var expectedDto = new Dtos.Wizard.QuestionWithWrittenAnswerDto { Id = questionWithWrittenAnswer.Id, Answer = ((WrittenAnswer)questionWithWrittenAnswer.Answer).Value, Question = questionWithWrittenAnswer.Content, Score = questionWithWrittenAnswer.Answer.MaxScore, Categories = new List <int>() }; //act var mapper = new QuestionServiceMapper(); var dto = mapper.MapToWizardQuestionDto(questionWithWrittenAnswer); //assert dto.Should().BeEquivalentTo(expectedDto); }
public void MapToTestQuestionWithResultDto_QuestionWithWrittenAnswer_ValidDto() { //arrange var userAnswerContent = "my answer"; var userAnswer = GetWrittenUserAnswer(questionWithWrittenAnswer.Id, userAnswerContent); QuestionWithResultDto expectedDto = new QuestionWithWrittenResultDto { Question = questionWithWrittenAnswer.Content, QuestionId = questionWithWrittenAnswer.Id, CorrectAnswer = ((WrittenAnswer)questionWithWrittenAnswer.Answer).Value, UserAnswer = userAnswerContent }; //act var mapper = new QuestionServiceMapper(); var dto = mapper.MapToTestQuestionWithResultDto(questionWithWrittenAnswer, userAnswer); //assert dto.Should().BeEquivalentTo(expectedDto); }
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 MapToAnswer_QuestionWithWritenAnswerDto_ValidAnswer() { //arrange var answerValue = "answer content"; var score = 5f; Dtos.Wizard.QuestionDto dto = new Dtos.Wizard.QuestionWithWrittenAnswerDto { Id = 1, Answer = answerValue, Categories = new List <int>(), Question = "Question content", Score = score }; var expectedAnswer = new WrittenAnswer(answerValue, score); //act var mapper = new QuestionServiceMapper(); var answer = mapper.MapToAnswer(dto); //assert answer.Should().BeEquivalentTo(expectedAnswer); }
public async Task ShouldReturnAllQuestions() { int authorId = fixture.UserId; var questions = new List <Question>(); var choices = new List <Choice>() { new Choice { Valid = false, Content = "1957" }, new Choice { Valid = true, Content = "1958" }, new Choice { Valid = false, Content = "1959" }, new Choice { Valid = false, Content = "1960" }, new Choice { Valid = false, Content = "1961" }, new Choice { Valid = false, Content = "1962" } }; var choiceAnswer = new ChoiceAnswer(choices, ChoiceAnswerType.SingleChoice, 1f); questions.Add(new Question("When was Nasa founded?", choiceAnswer, authorId)); choices = new List <Choice>() { new Choice { Valid = false, Content = "99 years" }, new Choice { Valid = false, Content = "100 years" }, new Choice { Valid = false, Content = "113 years" }, new Choice { Valid = true, Content = "116 years" } }; choiceAnswer = new ChoiceAnswer(choices, ChoiceAnswerType.SingleChoice, 1f); questions.Add(new Question("How many years did the 100 years war last?", choiceAnswer, authorId)); var writtenAnswer = new WrittenAnswer("George Washington", 1f); questions.Add(new Question("Who was the first president of the United States?", writtenAnswer, authorId)); await fixture.ExecuteDbContext(db => { foreach (var question in questions) { db.Questions.Add(question); } return(db.SaveChangesAsync()); }); var mapper = new QuestionServiceMapper(); var questionDtos = questions.Select(mapper.MapToWizardQuestionDto); int offset = 0; int limit = 10; var queryString = $"?Offset={offset}&Limit={limit}"; var response = await fixture.RequestSender.GetAsync("questions" + queryString); response.StatusCode.Should().Be(HttpStatusCode.OK); var responseData = await response.Content.ReadAsStringAsync(); var result = fixture.Deserialize <Paginated <QuestionDto> >(responseData); result.Data.Should().NotBeEmpty(); foreach (var questionDto in questionDtos) { result.Data.Should().ContainEquivalentOf(questionDto); } }