public void Insert(Question question) { using (var dataContext = new QuizGeneratorContext()) { dataContext.Questions.Add(question); dataContext.SaveChanges(); } }
public Question GetById(int id) { using (var dataContext = new QuizGeneratorContext()) { var questionRepository = new Repository <Question>(dataContext); Question question = questionRepository .GetById(id); return(question); } }
public IEnumerable <Question> GetAll() { using (var dataContext = new QuizGeneratorContext()) { var questionRepository = new Repository <Question>(dataContext); IQueryable <Question> questions = questionRepository .GetAll(); return(questions); } }
public void QueryAllQuestions() { using (var dataContext = new QuizGeneratorContext()) { var questionRepository = new Repository <Question>(dataContext); IQueryable <Question> questions = questionRepository .GetAll(); Assert.AreEqual(2, questions.Count()); } }
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(); } }
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(); } }