Exemple #1
0
        private void Answers(OnlineTestsDbContext context)
        {
            context.Answer.Add(new Answer()
            {
                Text = "lorem"
            });
            context.Answer.Add(new Answer()
            {
                Text = "ipsum"
            });
            context.Answer.Add(new Answer()
            {
                Text = "dolor"
            });
            context.Answer.Add(new Answer()
            {
                Text = "sit"
            });
            context.Answer.Add(new Answer()
            {
                Text = "amet"
            });

            context.SaveChanges();
        }
Exemple #2
0
 protected override void Seed(OnlineTestsDbContext context)
 {
     if (!context.Answer.Any())
     {
         Answers(context);
         Questions(context);
         Tests(context);
     }
 }
        public GenericRepository(OnlineTestsDbContext context)
        {
            if (context == null)
            {
                throw new ArgumentException("An instance of HangmanDbContext is required to use this repository.", "context");
            }

            this.Context = context;
            this.DbSet   = this.Context.Set <T>();
        }
Exemple #4
0
        private void Tests(OnlineTestsDbContext context)
        {
            Question[] questions = context.Question.ToArray();

            for (int i = 1; i <= TestsConstants.NumberOfTests; i++)
            {
                var questionsForCurrentTest = GetRandomQuestions(questions);
                context.Test.Add(new Test()
                {
                    Name      = "Test " + i,
                    Questions = questionsForCurrentTest
                });
            }

            context.SaveChanges();
        }
Exemple #5
0
        private void Questions(OnlineTestsDbContext context)
        {
            var answers = context.Answer.ToArray();

            context.Question.Add(new Question
            {
                Text    = "What is the first word in the following text?",
                Answers = new HashSet <Answer>()
                {
                    answers[0],
                    answers[1],
                    answers[2]
                },
                CorrectAnswerId = answers[0].Id,
                Description     = TestsConstants.DescriptionTextForQuestions
            });
            context.Question.Add(new Question
            {
                Text    = "What is the second word in the following text?",
                Answers = new HashSet <Answer>()
                {
                    answers[0],
                    answers[1],
                    answers[2]
                },
                CorrectAnswerId = answers[1].Id,
                Description     = TestsConstants.DescriptionTextForQuestions
            });
            context.Question.Add(new Question
            {
                Text    = "What is the third word in the following text?",
                Answers = new HashSet <Answer>()
                {
                    answers[0],
                    answers[1],
                    answers[2]
                },
                CorrectAnswerId = answers[2].Id,
                Description     = TestsConstants.DescriptionTextForQuestions
            });
            context.Question.Add(new Question
            {
                Text    = "What is the fourth word in the following text?",
                Answers = new HashSet <Answer>()
                {
                    answers[1],
                    answers[2],
                    answers[3]
                },
                CorrectAnswerId = answers[3].Id,
                Description     = TestsConstants.DescriptionTextForQuestions
            });
            context.Question.Add(new Question
            {
                Text    = "What is the fifth word in the following text?",
                Answers = new HashSet <Answer>()
                {
                    answers[4],
                    answers[1],
                    answers[2]
                },
                CorrectAnswerId = answers[4].Id,
                Description     = TestsConstants.DescriptionTextForQuestions
            });

            context.SaveChanges();
        }