Beispiel #1
0
        public async Task CreateAsync(QuizEntity quiz)
        {
            Guard.ArgumentNotNull(quiz, nameof(quiz));

            await _repository.AddAsync(quiz).ConfigureAwait(false);
        }
        private async Task SeedQuizzesAndQuizAnswers()
        {
            var id1     = ObjectId.GenerateNewId().ToString();
            var id2     = ObjectId.GenerateNewId().ToString();
            var id3     = ObjectId.GenerateNewId().ToString();
            var quizzes = new List <Quiz>
            {
                new Quiz
                {
                    CreatorUserId       = _userModels[1].UserId,
                    StartDate           = DateTime.Now,
                    ExpireDate          = DateTime.MaxValue,
                    Title               = "title",
                    EligibleGroupsNames = _groupModels.Select(g => g.Name).ToList(),
                    AreStatsPublic      = true,
                    MaxAssessment       = 3,
                    Questions           = new List <QuizQuestion>
                    {
                        new QuizQuestion
                        {
                            Id            = id1,
                            QuestionText  = "?",
                            AnswerOptions = new List <AnswerOption>
                            {
                                new AnswerOption {
                                    QuestionText = "1"
                                },
                                new AnswerOption {
                                    QuestionText = "2"
                                },
                                new AnswerOption {
                                    QuestionText = "3"
                                }
                            },
                            CorrectAnswerOptions = new List <int> {
                                0, 1
                            },
                            AnswerType    = Types.GetQuizAnswerTypeAsString(QuizAnswerType.Multiselection),
                            MaxAssessment = 1,
                            PreciseMatch  = false
                        },
                        new QuizQuestion
                        {
                            Id            = id2,
                            QuestionText  = "?",
                            AnswerOptions = new List <AnswerOption>
                            {
                                new AnswerOption {
                                    QuestionText = "1"
                                },
                                new AnswerOption {
                                    QuestionText = "2"
                                }
                            },
                            CorrectAnswerOptions = new List <int> {
                                0
                            },
                            AnswerType    = Types.GetQuizAnswerTypeAsString(QuizAnswerType.Singleselection),
                            MaxAssessment = 1,
                            PreciseMatch  = true
                        },
                        new QuizQuestion
                        {
                            Id            = id3,
                            QuestionText  = "?",
                            AnswerType    = Types.GetQuizAnswerTypeAsString(QuizAnswerType.TextInput),
                            MaxAssessment = 1,
                            PreciseMatch  = null
                        },
                    }
                },
            };

            foreach (var quiz in quizzes)
            {
                await _quizRepository.AddAsync(quiz);
            }
            var quizAnswersUnits = new List <QuizAnswersUnit>
            {
                new QuizAnswersUnit
                {
                    CreatorUserId = _userModels[2].UserId,
                    PollBaseId    = quizzes[0].Id,
                    AnswerDate    = DateTime.Now,
                    Answers       = new List <QuizAnswer>
                    {
                        new QuizAnswer
                        {
                            QuestionId      = id1,
                            SelectedOptions = new List <int> {
                                0, 1
                            },
                        },
                        new QuizAnswer
                        {
                            QuestionId      = id2,
                            SelectedOptions = new List <int> {
                                0
                            },
                        },
                        new QuizAnswer
                        {
                            QuestionId = id3,
                            Text       = "text"
                        }
                    }
                }
            };

            foreach (var quizAnswersUnit in quizAnswersUnits)
            {
                await _quizRepository.AddAnswersUnitAsync(quizAnswersUnit);
            }
        }