예제 #1
0
        private void FillAnswers(Question question, XmlNode nodes)
        {
            //Перебираем все ответы для вопроса
            foreach (XmlNode node in nodes.ChildNodes)
            {
                //Текст ответа
                string text = node.Attributes["Text"].Value; //Текст вопроса

                //Загружаем картинку, если она есть
                Image image = null;
                XmlNode n = node.Attributes.GetNamedItem("Image");
                if (n != null)
                    image = Image.FromFile(n.Value);

                //Создаём ответ
                Answer answer = new Answer(text, image);

                //Если ответ помечен как правильный, то устанавливаем его для вопроса
                XmlNode right = node.Attributes.GetNamedItem("IsRight");
                if (right != null)
                    question.SetRightAnswer(answer);

                //Добавляем ответ в вопрос
                question.AddAnswer(answer);
            }
        }
예제 #2
0
        /// <summary>
        /// Добавить ответ
        /// </summary>
        /// <param name="answer">ответ</param>
        public void AddAnswer(Answer answer)
        {
            if (answer == null)
                throw new ArgumentException("Некорректный аргумент");

            _answers.Add(answer);
        }
예제 #3
0
 public static RadioButtonWithAnswer CreateRadioButton(Answer answer)
 {
     return new RadioButtonWithAnswer()
     {
         AutoSize = false,
         Width = 650,
         Height = 65,
         Font = new Font("Microsoft Sans Serif", 10F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(204))),
         Text = answer.Text,
         UseVisualStyleBackColor = true,
         Answer = answer
     };
 }
예제 #4
0
        /// <summary>
        /// Задаёт правильный ответ к вопросу
        /// </summary>
        /// <param name="a">правильный ответ</param>
        public void SetRightAnswer(Answer a)
        {
            if (RightAnswer != null)
                throw new InvalidOperationException("Попытка переустановить правильный ответ");

            if (a == null)
                throw new ArgumentNullException();

            RightAnswer = a;
        }
        public void AnswerSheetsControllerReturnsNoContentAsync()
        {
            //initialize
            Answer answer = new Answer {
                Id = 1, AnswerText = "Отговор 1", Correct = 1, WrongText = ""
            };
            Answer answer2 = new Answer {
                Id = 2, AnswerText = "Отговор 2", Correct = 0, WrongText = ""
            };
            Answer answer3 = new Answer {
                Id = 3, AnswerText = "Отговор 3", Correct = 0, WrongText = ""
            };
            List <Answer> answers = new List <Answer> {
                answer, answer2, answer3
            };
            Question question = new Question {
                Answers = answers, Id = 1, QuestionText = "Въпрос", Score = 2, WrongText = ""
            };
            List <Question> questions = new List <Question> {
                question
            };
            var questionResponse = new QuestionResponse {
                Id = 1, Question = question, SelectedAnswers = new List <Answer> {
                    answer
                }, TextAnswer = ""
            };
            List <QuestionResponse> questionResponses = new List <QuestionResponse> {
                questionResponse
            };
            Score score = new Score {
                Id = 1, CurrentScore = 2, MaxScore = 2, Note = ""
            };
            Test test = new Test {
                Id = 1, Test_Name = "Начално ниво", Questions = questions
            };

            Answer answer4 = new Answer {
                Id = 4, AnswerText = "Отговор 4", Correct = 0, WrongText = ""
            };
            Answer answer5 = new Answer {
                Id = 5, AnswerText = "Отговор 5", Correct = 1, WrongText = ""
            };
            Answer answer6 = new Answer {
                Id = 6, AnswerText = "Отговор 6", Correct = 0, WrongText = ""
            };
            List <Answer> answers2 = new List <Answer> {
                answer4, answer5, answer6
            };
            Question question2 = new Question {
                Answers = answers2, Id = 2, QuestionText = "Въпрос", Score = 2, WrongText = ""
            };
            List <Question> questions2 = new List <Question> {
                question2
            };
            var questionResponse2 = new QuestionResponse {
                Id = 2, Question = question2, SelectedAnswers = new List <Answer> {
                    answer5
                }, TextAnswer = ""
            };
            List <QuestionResponse> questionResponses2 = new List <QuestionResponse> {
                questionResponse2
            };
            Score score2 = new Score {
                Id = 2, CurrentScore = 2, MaxScore = 2, Note = ""
            };
            Test test2 = new Test {
                Id = 2, Test_Name = "Средно ниво", Questions = questions2
            };

            var answerSheet = new AnswerSheet {
                Id = 0, QuestionResponses = questionResponses, Score = score, Test = test, UserId = "1", UserName = "******"
            };
            var answerSheet2 = new AnswerSheet {
                Id = 0, QuestionResponses = questionResponses2, Score = score2, Test = test2, UserId = "1", UserName = "******"
            };

            var data = new List <AnswerSheet> {
                answerSheet
            }.AsQueryable();

            var mockSet = new Mock <DbSet <AnswerSheet> >();

            mockSet.As <IQueryable <AnswerSheet> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <AnswerSheet> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <AnswerSheet> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <AnswerSheet> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <Brainzzler_DBContext>();

            mockContext.Setup(set => set.AnswerSheet).Returns(mockSet.Object);

            //act
            var controller = new AnswerSheetsController(mockContext.Object);

            controller.PutAnswerSheet(0, answerSheet2);
            mockContext.Object.SaveChanges();

            //assert
            Assert.AreEqual(answerSheet2, mockContext.Object.AnswerSheet.Find(0));
        }