コード例 #1
0
 public void Insert(Question question)
 {
     using (var dataContext = new QuizGeneratorContext())
     {
         dataContext.Questions.Add(question);
         dataContext.SaveChanges();
     }
 }
コード例 #2
0
        public Question GetById(int id)
        {
            using (var dataContext = new QuizGeneratorContext())
            {
                var questionRepository = new Repository <Question>(dataContext);

                Question question = questionRepository
                                    .GetById(id);

                return(question);
            }
        }
コード例 #3
0
        public IEnumerable <Question> GetAll()
        {
            using (var dataContext = new QuizGeneratorContext())
            {
                var questionRepository = new Repository <Question>(dataContext);

                IQueryable <Question> questions = questionRepository
                                                  .GetAll();

                return(questions);
            }
        }
コード例 #4
0
        public void QueryAllQuestions()
        {
            using (var dataContext = new QuizGeneratorContext())
            {
                var questionRepository = new Repository <Question>(dataContext);

                IQueryable <Question> questions = questionRepository
                                                  .GetAll();

                Assert.AreEqual(2, questions.Count());
            }
        }
コード例 #5
0
        public void Cleanup()
        {
            using (var dataContext = new QuizGeneratorContext())
            {
                IQueryable <Question> questions = dataContext.Questions.Select(x => x);

                foreach (Question question in questions)
                {
                    dataContext.Questions.Remove(question);
                }

                dataContext.SaveChanges();
            }
        }
コード例 #6
0
        public void Init()
        {
            Cleanup();

            using (var dataContext = new QuizGeneratorContext())
            {
                var q1 = new Question {
                    QuestionText = "Q1", Answer = "A"
                };
                var q2 = new Question {
                    QuestionText = "Q2", Answer = "B"
                };

                dataContext.Questions.Add(q1);
                dataContext.Questions.Add(q2);
                dataContext.SaveChanges();
            }
        }