예제 #1
0
        public IEnumerable <QuestionBase> Map(IDataReader r)
        {
            while (r.Read())
            {
                var          questionType = (QuestionType)r.GetByte("QuestionType_ID");
                QuestionBase result;
                switch (questionType)
                {
                case QuestionType.Open:
                    result = new OpenQuestion();
                    break;

                case QuestionType.Checkboxed:
                    result = new CheckedQuestion();
                    break;

                default:
                    throw new NotImplementedException();
                }
                result.ID       = r.GetInt32("ID");
                result.Question = r.GetString("Question");
                result.PoolID   = r.GetInt16("Pool_ID");
                yield return(result);
            }
        }
예제 #2
0
        // updateing
        public void Update(Exam entityToUpdate)
        {
            string titleNoSpace = entityToUpdate.Title;

            foreach (var c in titleNoSpace)
            {
                titleNoSpace = titleNoSpace.Replace(" ", string.Empty);
            }
            XElement xEntity    = new XElement($"{titleNoSpace}_{entityToUpdate.Id}");
            XElement xQuestions = new XElement("Questions");

            foreach (var question in entityToUpdate.Questions)
            {
                if (question is MultipleChoiceTextQuestion)
                {
                    MultipleChoiceTextQuestion multipleText = question as MultipleChoiceTextQuestion;
                    XElement xAnswers = new XElement("Answers");
                    int      i        = 0;
                    foreach (string answer in multipleText.Answers)
                    {
                        xAnswers.Add(new XElement($"Answer_{i}", answer));
                        i++;
                    }
                    XElement xQuestion = new XElement("MultipleChoiseTextQuestion", new object[] {
                        new XElement("QuestionDescription", multipleText.QuestionDescription),
                        new XElement("QuestionText", multipleText.QuestionText),
                        xAnswers,
                        new XElement("RightAnswer", multipleText.RightAnswer),
                        new XElement("Points", multipleText.Points)
                    });
                    xQuestions.Add(xQuestion);
                }
                else if (question is OpenQuestion)
                {
                    OpenQuestion openQuestion = question as OpenQuestion;
                    XElement     xQuestion    = new XElement("OpenQuestion", new object[] {
                        new XElement("QuestionDescription", openQuestion.QuestionDescription),
                        new XElement("QuestionText", openQuestion.QuestionText),
                        new XElement("RightAnswer", openQuestion.RightAnswer),
                        new XElement("Points", openQuestion.Points)
                    });
                    xQuestions.Add(xQuestion);
                }
            }
            xEntity.Add(xQuestions);
            var    dirPath  = Directory.GetCurrentDirectory();
            string fileName = ($"{titleNoSpace}_{entityToUpdate.Id}.xml");

            if (!Directory.Exists($"{dirPath}\\ExamsQuestions"))
            {
                Directory.CreateDirectory($"{dirPath}\\ExamsQuestions");
            }
            var filePath = $"{dirPath}\\ExamsQuestions\\{fileName}";

            xEntity.Save(filePath);
            entityToUpdate.QuestionsPath = fileName;


            GetById(entityToUpdate.Id);
        }
예제 #3
0
        public static Question LoadQuestion(int id, string question_type)
        {
            Question question;

            if (question_type == "open")
            {
                question = new OpenQuestion();
            }
            else
            {
                question = new CloseQuestion();
            }

            connection.Open();
            var command = new SQLiteCommand("select * from Question where ID = @id", connection);

            command.Parameters.AddWithValue("@id", id);
            var reader = command.ExecuteReader();

            while (reader.Read())
            {
                question.ID       = reader.GetInt32(0);
                question.question = (string)reader.GetValue(1);
                question.answer   = (string)reader.GetValue(2);
            }

            connection.Close();
            return(question);
        }
        public void Init()
        {
            openQ     = new OpenQuestion();
            QuestMock = new Mock <IQuestionRepository>();

            _questionnaire = new Questionnaire()
            {
                Id = Guid.Empty.ToString()
            };

            OpenQuestion = new OpenQuestionViewModel(openQ, QuestMock.Object);
            QfactoryMock = new Mock <IQuestionFactory>();
            ListMock     = new Mock <IAddableList <Questionnaire> >();
            MapperMock   = new Mock <IMapper>();
            EditMock     = new Mock <IEditViewModel <EventViewModel> >();
            festiClient  = new Mock <IFestiClient>().Object;
            QfactoryMock.Setup(mock => mock.Create(_questionnaire, "Open", It.IsAny <int>())).Returns(OpenQuestion);
            EditMock.Setup(mock => mock.Entity.Id).Returns("ff");
            AddQVM = new AddQuestionnaireViewModel(QfactoryMock.Object, ListMock.Object, MapperMock.Object, EditMock.Object, festiClient);


            //MockRepo.Setup(elem => elem.InsertAsync(Question)).Returns(Task.CompletedTask);
            //QfactoryMock.Setup(mock => mock.QuestionTypes== "open");
            //FestiMClientMock = new Mock<FestiMSClient>();
        }
예제 #5
0
        public void WhenQuestionIsNew_ThenItIsNotComplete()
        {
            var question = new OpenQuestion {
                MaxLength = 10
            };

            Assert.IsFalse(question.IsComplete);
        }
예제 #6
0
        public void WhenQuestionIsNew_ThenTemplateValuesAreCopied()
        {
            var question = new OpenQuestion {
                MaxLength = 10
            };

            Assert.AreEqual(10, question.MaxLength);
        }
        /// <summary>
        /// Update open question
        /// </summary>
        /// <param name="model"></param>
        public void Update(OpenQuestion model)
        {
            var question = this.context.OpenQuestions.Find(model.Id);

            question.Content = model.Content;
            question.Points  = model.Points;
            this.context.SaveChanges();
        }
예제 #8
0
    public void setOpenQuestion(int index)
    {
        this.index = index;
        OpenQuestion question = englishQuestions[index];

        questionText.text = question.question;
        sceneSwitcher.newElement(openQuestion);
    }
예제 #9
0
 internal void PickValues(OpenQuestion openQuestion)
 {
     _openQuestion = openQuestion;
     comboBoxDataType.DataSource   = Enum.GetValues(typeof(DataTypes));
     textBoxQuestionText.Text      = _openQuestion.QuestionText;
     textBoxName.Text              = _openQuestion.Name;
     checkBoxIsBinary.Checked      = _openQuestion.IsBinaryAnswer;
     comboBoxDataType.SelectedItem = _openQuestion.DataType;
 }
예제 #10
0
        public void ViewModelHasMaxLengthAsTheAvailableLength()
        {
            var question = new OpenQuestion {
                QuestionText = "Question", MaxLength = 25
            };
            var viewModel = new OpenQuestionViewModel(question);

            Assert.AreEqual(25, viewModel.AvailableLength);
        }
예제 #11
0
        private void AddOpenQuestion()
        {
            OpenQuestion     openQuestion = _subSection.Questions.AddOpenQuestion();
            OpenQuestionForm form         = new OpenQuestionForm();

            form.PickValues(openQuestion);
            form.ShowDialog();
            RefreshQuestions();
        }
예제 #12
0
        public void WhenQuestionHasEmptyValue_ThenItIsNotComplete()
        {
            var question = new OpenQuestion {
                MaxLength = 10
            };

            question.Response = "";

            Assert.IsFalse(question.IsComplete);
        }
예제 #13
0
        public void WhenQuestionHasValidValue_ThenItIsComplete()
        {
            var question = new OpenQuestion {
                MaxLength = 10
            };

            question.Response = "aaaa";

            Assert.IsTrue(question.IsComplete);
        }
예제 #14
0
        private void AddOpenQuestion()
        {
            OpenQuestion     openQuestion = _section.Questions.AddOpenQuestion();
            OpenQuestionForm form         = new OpenQuestionForm();

            form.PickValues(openQuestion);
            if (form.ShowDialog() == DialogResult.OK)
            {
                RefreshQuestions();
            }
        }
예제 #15
0
        public void WhenSettingTheResponseTextPropertyOnTheModel_ThenAvailableLengthIsUpdatedOnTheViewModel()
        {
            var question = new OpenQuestion {
                QuestionText = "Question", MaxLength = 25
            };
            var viewModel = new OpenQuestionViewModel(question);

            question.Response = "1234567890";

            Assert.AreEqual(15, viewModel.AvailableLength);
        }
예제 #16
0
        public void WhenCreatingTheViewModel_ThenHasChangesIsFalse()
        {
            var question = new OpenQuestion {
                QuestionText = "Question", MaxLength = 25
            };
            var  viewModel  = new OpenQuestionViewModel(question);
            bool hasChanges = false;

            viewModel.ResponseChanged += (o, e) => { hasChanges = true; };
            Assert.IsFalse(hasChanges);
        }
예제 #17
0
        public void WhenResponseLengthExceedsMaxLength_ThenIndicatesErrorOnResponse()
        {
            var question = new OpenQuestion {
                MaxLength = 10
            };
            var notifyErrorInfo = (INotifyDataErrorInfo)question;

            question.Response = "ThisIsLongerThanTenCharacters";

            Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast <string>().Any());
        }
        public IHttpActionResult Create(OpenQuestion openQst)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            this.data.OpenQuestions.Add(openQst);
            this.data.SaveChanges();

            return(Ok(openQst));
        }
예제 #19
0
        public void WhenSettingResponseToNull_ThenIndicatesErrorOnResponse()
        {
            var question = new OpenQuestion {
                MaxLength = 10
            };
            var notifyErrorInfo = (INotifyDataErrorInfo)question;

            question.Response = "valid";
            Assert.IsFalse(notifyErrorInfo.GetErrors("Response").Cast <string>().Any());

            question.Response = null;
            Assert.IsTrue(notifyErrorInfo.GetErrors("Response").Cast <string>().Any());
        }
예제 #20
0
        public void WhenSettingTheResponseTextPropertyOnTheModel_ThenAChangeOnAvailableLengthIsNotifiedOnTheViewModel()
        {
            var question = new OpenQuestion {
                QuestionText = "Question", MaxLength = 25
            };
            var viewModel = new OpenQuestionViewModel(question);

            var changeTracker = new PropertyChangeTracker(viewModel);

            question.Response = "1234567890";

            Assert.IsTrue(changeTracker.ChangedProperties.Contains("AvailableLength"));
        }
 public void Init()
 {
     Question = new OpenQuestion()
     {
         Questionnaire = new Questionnaire()
         {
             Id = Guid.Empty.ToString()
         }
     };
     MockRepo = new Mock <IQuestionRepository>();
     MockRepo.Setup(elem => elem.InsertAsync(Question)).Returns(Task.CompletedTask);
     OpenVM = new OpenQuestionViewModel(Question, MockRepo.Object);
 }
예제 #22
0
        public void WhenSettingTheResponseTextPropertyOnTheModel_ThenTheViewModelNotifiesAResponseChange()
        {
            var question = new OpenQuestion {
                QuestionText = "Question", MaxLength = 25
            };
            var viewModel = new OpenQuestionViewModel(question);

            bool responseChanged = false;

            viewModel.ResponseChanged += (s, e) => responseChanged = true;
            question.Response          = "1234567890";

            Assert.IsTrue(responseChanged);
        }
예제 #23
0
        public async Task <IActionResult> GeneralTestAsync(int index = 0)
        {
            var listQuestions = await repository.GetAllQuestions();

            var listAnswers = await repository.GetAllAnswers();

            var listSpelling    = new List <Question>(listQuestions.Where(a => a.Category == "Орфография" && !a.IsOpen));
            var listPunctuation = new List <Question>(listQuestions.Where(a => a.Category == "Пунктуация" && !a.IsOpen));
            var listSyntax      = new List <Question>(listQuestions.Where(a => a.Category == "Синтаксис" && !a.IsOpen));
            var listMorphology  = new List <Question>(listQuestions.Where(a => a.Category == "Морфология" && !a.IsOpen));
            var listOpen        = new List <Question>(listQuestions.Where(a => a.IsOpen));

            Test test = new Test
            {
                CloseQuestions = new List <CloseQuestion>(),
                OpenQuestions  = new List <OpenQuestion>()
            };

            test.Name = $"Общий тест {index + 1}";

            for (int i = 0; i < SPELLING_QUESTION_NUMBER; i++)
            {
                var cq = new CloseQuestion(listSpelling.ElementAt(index * SPELLING_QUESTION_NUMBER + i));
                test.CloseQuestions.Add(cq);
            }

            for (int i = 0; i < PUNCT_QUESTION_NUMBER; i++)
            {
                var cq = new CloseQuestion(listPunctuation.ElementAt(index * PUNCT_QUESTION_NUMBER + i));
                test.CloseQuestions.Add(cq);
            }

            test.CloseQuestions.Add(new CloseQuestion(listMorphology.ElementAt(index + 1)));
            test.CloseQuestions.Add(new CloseQuestion(listSyntax.ElementAt(index + 1)));

            foreach (var q in test.CloseQuestions)
            {
                q.Answers = new List <Answer>(listAnswers.Where(a => a.QuestionId == q.Id));
            }

            for (int i = 0; i < OPEN_QUESTION_NUMBER; i++)
            {
                var cq = new OpenQuestion(listOpen.ElementAt(index * OPEN_QUESTION_NUMBER + i));
                cq.RightAnswer = listAnswers.Where(a => a.QuestionId == cq.Id).ElementAt(0);
                test.OpenQuestions.Add(cq);
            }

            return(View(test));
        }
예제 #24
0
        public static void LoadExamQuestions(Exam exam)
        {
            string dirpath  = Directory.GetCurrentDirectory();
            string filePath = dirpath + "\\" + exam.QuestionsPath;

            try
            {
                var      xml        = XDocument.Load(filePath);
                XElement elementXml = XElement.Parse(xml.ToString());
                //   exam.Title = elementXml.Name.ToString().Replace("_", " ");
                var questionsElement = elementXml.Elements();
                foreach (var xQuestion in questionsElement.Elements())
                {
                    IQuestion question;
                    if (xQuestion.Name == "MultipleChoiseTextQuestion")
                    {
                        question = new MultipleChoiceTextQuestion();
                        var answers = xQuestion.Element("Answers");
                        foreach (var answer in answers.Elements())
                        {
                            (question as MultipleChoiceTextQuestion).Answers.Add(answer.Value);
                        }
                    }
                    else
                    {
                        question = new OpenQuestion();
                    }
                    question.Points              = double.Parse(xQuestion.Element("Points").Value);
                    question.RightAnswer         = xQuestion.Element("RightAnswer").Value;
                    question.QuestionDescription = xQuestion.Element("QuestionDescription").Value;
                    question.QuestionText        = xQuestion.Element("QuestionText").Value;
                    if (xQuestion.Element("Image_Id") != null)
                    {
                        using (var unit = new UnitOfWork(new ExamContext()))
                        {
                            int    imageId   = int.Parse(xQuestion.Element("Image_Id").Value);
                            QImage qImgModel = unit.QImages
                                               .Find(img => (img.ExamId == exam.Id) && (img.Id == imageId))
                                               .ToList()[0];
                            question.QuestionImage = ByteArrayToImage(qImgModel.QuestionImage);
                        }
                    }
                    exam.Questions.Add(question);
                }
            }
            catch
            {
            }
        }
예제 #25
0
        public void WhenSettingTheResponseOntheModel_ThenViewModelHasChanges()
        {
            var question = new OpenQuestion {
                QuestionText = "Question", MaxLength = 25
            };
            var viewModel = new OpenQuestionViewModel(question);

            bool hasChanges = false;

            viewModel.ResponseChanged += (o, e) => { hasChanges = true; };

            question.Response = "1234567890";

            Assert.IsTrue(hasChanges);
        }
예제 #26
0
        // getting
        public Exam GetById(object id)
        {
            Exam exam     = new Exam();
            var  dirPath  = Directory.GetCurrentDirectory();
            var  filePath = Directory.GetFiles($"{dirPath}\\ExamsQuestions", $"*{id}*");

            if (filePath.Count() != 0)
            {
                var      xml        = XDocument.Load(filePath[0]);
                XElement elementXml = XElement.Parse(xml.ToString());
                exam.Title = elementXml.Name.ToString().Replace("_", " ");
                var questionsElement = elementXml.Elements();
                foreach (var question in questionsElement.Elements())
                {
                    if (question.Name == "MultipleChoiseTextQuestion")
                    {
                        MultipleChoiceTextQuestion multipleChoise = new MultipleChoiceTextQuestion();
                        multipleChoise.QuestionText = question.Element("QuestionText").Value;
                        multipleChoise.Points       = double.Parse(question.Element("Points").Value);
                        multipleChoise.RightAnswer  = question.Element("RightAnswer").Value;
                        var answers = question.Element("Answers");
                        foreach (var answer in answers.Elements())
                        {
                            multipleChoise.Answers.Add(answer.Value);
                        }
                        exam.Questions.Add(multipleChoise);
                    }
                    else if (question.Name == "OpenQuestion")
                    {
                        OpenQuestion openQuestion = new OpenQuestion();
                        openQuestion.QuestionText        = question.Element("QuestionText").Value;
                        openQuestion.Points              = double.Parse(question.Element("Points").Value);
                        openQuestion.RightAnswer         = question.Element("RightAnswer").Value;
                        openQuestion.QuestionDescription = question.Element("QuestionDescription").Value;
                        exam.Questions.Add(openQuestion);
                    }
                }
            }
            return(exam);
        }
예제 #27
0
파일: Main.cs 프로젝트: lulzzz/DCAnalytics
        private void AddOpenQuestion()
        {
            if (!(Tree.SelectedNode.Tag is Questions))
            {
                return;
            }
            Questions        questions    = Tree.SelectedNode.Tag as Questions;
            OpenQuestion     openQuestion = (OpenQuestion)questions.Add(QuestionTypes.Open);
            OpenQuestionForm openQnFrm    = new OpenQuestionForm();

            openQnFrm.PickValues(openQuestion);
            if (openQnFrm.ShowDialog() == DialogResult.OK)
            {
                TreeNode questionsNode = Tree.SelectedNode;
                if (questionsNode != null)
                {
                    var questionNode = AddToParentNode(questionsNode, openQuestion, openQuestion.Name);
                    questionNode.ImageIndex         = 3;
                    questionNode.SelectedImageIndex = 3;
                }
            }
        }
예제 #28
0
        public static Question CreateQuestion(DCAnalyticsObject parent, QuestionTypes qtype)
        {
            Question question = null;

            switch (qtype)
            {
            case QuestionTypes.Closed:
                question = new ClosedQuestion(parent);
                break;

            case QuestionTypes.MultipleChoice:
                question = new MultipleChoiceQuestion(parent);
                break;

            case QuestionTypes.Open:
                question = new OpenQuestion(parent);
                break;

            case QuestionTypes.Map:
                question = new MapQuestion(parent);
                break;

            case QuestionTypes.Location:
                question = new LocationQuestion(parent);
                break;

            case QuestionTypes.Other:
                question = new OtherQuestion(parent);
                break;
            }
            if (question != null)
            {
                question.QuestionType = qtype;
            }
            return(question);
        }
예제 #29
0
 public override Question CreateNewQuestion()
 {
     var question = new OpenQuestion(this);
     return question;
 }
예제 #30
0
 public OpenQuestionViewModel(OpenQuestion model) : base(model)
 {
 }
예제 #31
0
 public OpenQuestionDTO(OpenQuestion question)
 {
     this.Id = question.Id;
     this.Text = question.Text;
     this.Pincode_Id = question.Pincode_Id;
 }
 /// <summary>
 /// Add open question
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Add(OpenQuestion model)
 {
     this.context.OpenQuestions.Add(model);
     this.context.SaveChanges();
     return(model.Id);
 }
예제 #33
0
 public void MarkAsModified(OpenQuestion item)
 {
     Entry(item).State = EntityState.Modified;
 }