Exemplo n.º 1
0
        public void Update()
        {
            Question     question  = new Question();
            QuestionList questions = new QuestionList();

            questions.LoadQuestions();
            question = questions.FirstOrDefault(q => q.Text == "TestQuestion");

            question.Text = "UpdatedQuestion";


            HttpClient client = InitializeClient();
            //Serialize a question object that we're trying to insert
            string serializedQuestion = JsonConvert.SerializeObject(question);
            var    content            = new StringContent(serializedQuestion);

            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = client.PutAsync("Question/" + question.Id, content).Result;

            Question newQuestion = new Question {
                Id = question.Id
            };
            HttpResponseMessage responseRetrieved = client.GetAsync("Question/" + question.Id).Result;
            string result = responseRetrieved.Content.ReadAsStringAsync().Result;

            newQuestion = JsonConvert.DeserializeObject <Question>(result);


            Assert.IsTrue(newQuestion.Text == "UpdatedQuestion");
        }
        // GET: api/Question
        public IEnumerable <Question> Get()
        {
            QuestionList questions = new QuestionList();

            questions.LoadQuestions();
            return(questions);
        }
Exemplo n.º 3
0
        public void LoadTest()
        {
            QuestionList questions = new QuestionList();

            questions.LoadQuestions();

            int expected = 6;
            int actual   = questions.Count;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 4
0
        public void DeleteTest()
        {
            //Load all questions and then get the question
            QuestionList questions = new QuestionList();

            questions.LoadQuestions();
            Question question = questions.FirstOrDefault(q => q.Text == "ChangedText");

            int actual = question.DeleteQuestion();

            Assert.IsTrue(actual > 0);
        }
Exemplo n.º 5
0
        public void LoadByQuestionId()
        {
            QuestionList questions = new QuestionList();

            questions.LoadQuestions();
            Question question = questions.FirstOrDefault(q => q.Text == "Who sprouts mung beans in their desk drawers?");

            Activation activation = new Activation();

            activation.LoadByQuestionId(question.Id);

            Assert.AreEqual(activation.ActivationCode, "test2");
        }
Exemplo n.º 6
0
        public void LoadAnswers()
        {
            //Load all questions and then get the question
            QuestionList questions = new QuestionList();

            //Load answers is executed in LoadQuestions, check that they are populated
            questions.LoadQuestions();

            Question question = questions.FirstOrDefault(q => q.Text == "Who sprouts mung beans in their desk drawers?");

            int expected = 4;
            int actual   = question.Answers.Count;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 7
0
        public MainWindow()
        {
            try
            {
                InitializeComponent();
                questions = new QuestionList();
                questions.LoadQuestions();


                LoadComboBoxes();
            }
            catch (Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
        }
Exemplo n.º 8
0
        public void UpdateTest()
        {
            //Load all questions and then get the question
            QuestionList questions = new QuestionList();

            questions.LoadQuestions();
            Question question = questions.FirstOrDefault(q => q.Text == "TestQuestion");

            //Change the properties
            question.Text = "ChangedText";

            //Update the question
            question.UpdateQuestion();

            //Load it
            question.LoadQuestionById();

            Assert.AreEqual(question.Text, "ChangedText");
        }
Exemplo n.º 9
0
        public ManageQAs(QAMode mode)
        {
            try
            {
                InitializeComponent();

                //Adjust labels and title for the mode
                lblQOrA.Content = mode.ToString() + "s:";
                Title           = "Manage " + mode.ToString() + "s";

                //save the mode in a modular level variable
                qaMode = mode;

                //Instantiate the proper list
                switch (mode)
                {
                case QAMode.Answer:
                    answers = new AnswerList();
                    answers.Load();
                    break;

                case QAMode.Question:
                    questions = new QuestionList();
                    questions.LoadQuestions();

                    break;

                default:
                    break;
                }

                rebindComboBox(mode);

                //Select the first item in the combobox
                cboQorAs.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
        }
Exemplo n.º 10
0
        public void Delete()
        {
            Question     question  = new Question();
            QuestionList questions = new QuestionList();

            questions.LoadQuestions();
            question = questions.FirstOrDefault(q => q.Text == "UpdatedQuestion");

            HttpClient client = InitializeClient();
            //Serialize a question object that we're trying to insert
            HttpResponseMessage response = client.DeleteAsync("Question/" + question.Id).Result;

            Question newQuestion = new Question {
                Id = question.Id
            };
            HttpResponseMessage responseRetrieved = client.GetAsync("Question/" + question.Id).Result;
            string result = responseRetrieved.Content.ReadAsStringAsync().Result;

            newQuestion = JsonConvert.DeserializeObject <Question>(result);


            Assert.IsNull(newQuestion.Text);
        }