public void AddAnswerMax3Test() { using (var _Transaction = _DbContext.Database.BeginTransaction()) { var _Question = new Mock <DAO.Question>(); var _QuestionAnswers = new Mock <DAO.QuestionAnswers>(); List <DAO.QuestionAnswers> _Answers = new List <DAO.QuestionAnswers>() { _QuestionAnswers.Object, _QuestionAnswers.Object, _QuestionAnswers.Object }; _Question.Setup(x => x.Answers).Returns(_Answers); Assert.Throws <Exception>(() => _QuestionManagement.AddAnswer(_Question.Object, new DAO.Answer() { })); _Transaction.Rollback(); } }
public void AddAswerToQuestionTest() { QuestionManagement _QuestionManagement = new QuestionManagement(); IAnswerManagement _AnswerManagement = AnswerManagement.Instance(); DAO.Question _Question = _QuestionManagement.GetQuestion(StaticQuestions.Q1); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A1)); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A2)); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A3)); _Question = _QuestionManagement.GetQuestion(StaticQuestions.Q2); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A4)); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A5)); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A6)); _Question = _QuestionManagement.GetQuestion(StaticQuestions.Q3); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A7)); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A8)); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A9)); _Question = _QuestionManagement.GetQuestion(StaticQuestions.Q4); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A10)); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A11)); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A12)); _Question = _QuestionManagement.GetQuestion(StaticQuestions.Q5); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A13)); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A14)); _QuestionManagement.AddAnswer(_Question, _AnswerManagement.GetAnswer(StaticAnswers.A15)); _DbContext.SaveChanges(); Assert.True(_Question.Answers.Count() == 3); Assert.True(_Question.Answers.Where(x => x.AnswerId == _AnswerManagement.GetAnswer(StaticAnswers.A14).Id).Count() == 1); }