public void CreateQuestionTest()
        {
            QuestionManagement _QuestionManagement = new QuestionManagement();

            _QuestionManagement.CreateQuestion(new DAO.Question()
            {
                Text = StaticQuestions.Q1
            });
            _QuestionManagement.CreateQuestion(new DAO.Question()
            {
                Text = StaticQuestions.Q2
            });
            _QuestionManagement.CreateQuestion(new DAO.Question()
            {
                Text = StaticQuestions.Q3
            });
            _QuestionManagement.CreateQuestion(new DAO.Question()
            {
                Text = StaticQuestions.Q4
            });
            _QuestionManagement.CreateQuestion(new DAO.Question()
            {
                Text = StaticQuestions.Q5
            });

            _DbContext.SaveChanges();

            var _Result = _QuestionManagement.GetQuestion(StaticQuestions.Q4);

            Assert.True(_Result != null & _Result.Id > 0);
        }
Beispiel #2
0
        public void SetCorrectAnswerTest()
        {
            using (var _Transaction = _DbContext.Database.BeginTransaction())
            {
                // Создаем вопрос.
                DAO.Question _Question = new DAO.Question()
                {
                    Text = "SetCorrectAnswerTest?"
                };
                _QuestionManagement.CreateQuestion(_Question);
                _DbContext.SaveChanges();

                // Получаем сущность из БД - если не получить, то EF подумает, что надо создать новую.
                _Question = _DbContext.Questions.Include("Answers").Single(x => x.Text == _Question.Text);

                // Выбираем ответы для заполнения.
                DAO.Answer[] _Answers = new DAO.Answer[] {
                    _DbContext.Answers.Single(x => x.Text == "Венера"),
                    _DbContext.Answers.Single(x => x.Text == "Меркурий"),
                    _DbContext.Answers.Single(x => x.Text == "Земля")
                };
                _QuestionManagement.AddAnswer(_Question, _Answers);
                _DbContext.SaveChanges();

                Assert.DoesNotThrow(() => _QuestionManagement.SetCorrectAnswer(_Question, _DbContext.Answers.Single(x => x.Text == "Венера")));

                var _UnCorrectAnswer = _DbContext.Answers.Single(x => x.Text == "101010");
                Assert.Throws <Exception>(() => _QuestionManagement.SetCorrectAnswer(_Question, _UnCorrectAnswer));

                _Transaction.Rollback();
            }
        }