public void TestExamResult() { int userId = 1; QuestionAnswer answer1 = new QuestionAnswer("Ostrava", true); QuestionAnswer answer2 = new QuestionAnswer("Praha", false); Question question = QuestionTable.InsertQuestion(this.connection, userId, "test", "closed", new List <QuestionAnswer>() { answer1, answer2 }); Exam exam = ExamTable.InsertExam(this.connection, userId, "test exam", 10, 1, 1, DateTime.Now.AddDays(-1), DateTime.Now.AddDays(1)); exam.AddQuestion(question.Id, 20); ExamTable.UpdateExam(this.connection, exam); int examResultId = ExamResultTable.InsertExamResult(this.connection, exam.Id, userId); ExamResult examResult = ExamResultTable.GetExamResultById(this.connection, examResultId); Assert.AreEqual(examResultId, examResult.Id); Assert.AreEqual(userId, examResult.OwnerId); Assert.AreEqual("created", examResult.State); ExamAnswer answer = new ExamAnswer(question.Id, "Ostrava"); Assert.IsTrue(ExamResultTable.HandInExamResult(this.connection, examResult, new List <ExamAnswer>() { answer })); examResult = ExamResultTable.GetExamResultById(this.connection, examResult.Id); Assert.AreEqual("finished", examResult.State); Assert.AreEqual(exam.Questions[0].Points, examResult.Points); }
private void createExamFile_Click(object sender, EventArgs e) { var invalid = Questions.Any(q => q.Score == 0); if (invalid) { lblMessage.ForeColor = Color.Red; lblMessage.Text = "نمره برخی سوالها وارد نشده است"; return; } Exam exam = new Exam(); exam.Id = Guid.NewGuid().ToString(); var st = faDatePicker1.SelectedDateTime; if (st.HasValue) { var s = st.Value.ToUniversalTime(); st = PersianDateConverter.ToMiladi(s); st = new DateTime(s.Year, s.Month, s.Day, int.Parse(comboStartHour.Text), int.Parse(comboStartMinute.Text), 0); } exam.StartTime = st; exam.Time = new TimeSpan(int.Parse(comboHour.Text), int.Parse(comboMinute.Text), 0); exam.ExamName = txtName.Text; exam.PasswordForExamTime = txtPassword.Text; exam.PasswordForEvaluationTime = txtEPass.Text; int i = 0; foreach (var q in Questions) { exam.AddQuestion(q, i++); } IFormatter formatter = new BinaryFormatter(); SaveFileDialog save = new SaveFileDialog(); save.Filter = "آزمون پرسان(*.pex)|*.pex"; if (save.ShowDialog() == DialogResult.OK) { FileStream fileStream = new FileStream(save.FileName, FileMode.Create, FileAccess.Write, FileShare.None); //MemoryStream ms = new MemoryStream(); RijndaelManaged rmCrypto = new RijndaelManaged(); byte[] key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 }; byte[] iv = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 }; //Create a CryptoStream, pass it the NetworkStream, and encrypt //it with the Rijndael class. CryptoStream cryptStream = new CryptoStream(fileStream, rmCrypto.CreateEncryptor(key, iv), CryptoStreamMode.Write); formatter.Serialize(cryptStream, exam); cryptStream.Close(); fileStream.Close(); } }
public Exam GetExam() { var exam = new Exam() { ID = 100, Name = "Матура по география" }; exam.AddQuestion(GetQuestions()); return(exam); }
internal static Exam DeepClone(this Exam exam) { var clone = new Exam(exam.Id, exam.Name, exam.Type, exam.Category, exam.CreatedBy, exam.CreatedDate, exam.IsConfirmed); foreach (var q in exam.Questions) { clone.AddQuestion(q.Order, q.Text, q.A, q.B, q.C, q.D, q.CorrectAnswer, q.Explanation); } return(clone); }
public Exam GetExam() { var exam = new Exam() { Id = 100, Name = "중간 고사" }; exam.AddQuestion(GetQuestions()); return(exam); }
public async Task <Result> HandleAsync(AddExamCommand command) { var exam = new Exam(Guid.NewGuid(), command.Name, command.Type, command.Category, _user.Identity.Name, DateTime.Now, false); foreach (var q in command.Questions) { exam.AddQuestion(q.Order, q.Text, q.A, q.B, q.C, q.D, q.CorrectAnswer, q.Explanation); } await _examsRepository.AddAsync(exam); return(Result.Success()); }
public ExamBuilder WithQuestion(string text, CorrectAnswer correctAnswer) { _prototype.AddQuestion( order: _prototype.Questions.Count + 1, text: text, a: "a1", b: "b1", c: "c1", d: "d1", correctAnswer: correctAnswer, explanation: Guid.NewGuid().ToString() ); return(this); }
public void AddQuestionTest() { //Arrange Exam exam = new Exam("Exam", 1, 3, 1); Question question = new Question("Question", "Correct answer", new List <String> { "Answer1", "Answer2" }); //Act exam.AddQuestion(question); //Assert Assert.AreSame(question, exam.questions[0]); }
public void TestExamQuestions() { Exam exam = ExamTable.InsertExam(this.connection, 1, "test", 10, 10, 10, DateTime.Now, DateTime.Now.AddDays(1)); exam.AddQuestion(new ExamQuestion(1, exam.Id, 0, 5.5m)); ExamTable.UpdateExam(this.connection, exam); Exam dbExam = ExamTable.GetExamById(this.connection, exam.Id); Assert.AreEqual(exam.Questions.Count, dbExam.Questions.Count); Assert.AreEqual(exam.Questions[0].Points, dbExam.Questions[0].Points); Assert.IsTrue(ExamTable.DeleteExam(this.connection, exam, exam.OwnerId)); }
public Exam GetExamByID(int id) { DataTable dataTable = dbaccess.SQLGetTableData("SELECT * FROM EXAMS WHERE ID = " + id + ";"); if (dataTable.Rows.Count > 0) { Exam exam = new Exam(Convert.ToInt32(dataTable.Rows[0].ItemArray[0]), Convert.ToString(dataTable.Rows[0].ItemArray[1]), Convert.ToInt32(dataTable.Rows[0].ItemArray[2]), Convert.ToInt32(dataTable.Rows[0].ItemArray[3]), Convert.ToInt32(dataTable.Rows[0].ItemArray[4])); List <Question> questions = questionAccess.GetQuestionsOfExam(exam.id); for (int j = 0; j < questions.Count; j++) { exam.AddQuestion(questions[j]); } return(exam); } return(null); }
public bool CreateExam(string Title, int NumberOfQuestions, int Attempts, List <Question> Questions, Subject subject) { if (Questions.Count < NumberOfQuestions) { return(false); } else { List <object> param = new List <object>(); param.Add(Title); param.Add(NumberOfQuestions); param.Add(Attempts); Exam exam = IoC.ResolveObject(typeof(Exam), param) as Exam; for (int i = 0; i < Questions.Count; i++) { exam.AddQuestion(Questions[i]); } examAccess.InsertExamToDB(exam, subject.id); return(true); } }
public static Exam ConvertXmlToExam(string path) { Exam exam = new Exam(); Question question = null; XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNode examNode = doc.SelectSingleNode("Exam"); exam.Title = (examNode.Attributes["title"] as XmlAttribute).Value; XmlNodeList nodeQuestions = doc.SelectNodes("Exam/Questions/Question"); foreach (XmlNode nodeQuestion in nodeQuestions) { question = new Question(); question.Text = (nodeQuestion.Attributes["text"] as XmlAttribute).Value; question.Point = Convert.ToDouble((nodeQuestion.Attributes["point"] as XmlAttribute).Value); XmlNodeList nodeChoices = nodeQuestion.SelectNodes("Choices/Choice"); foreach (XmlNode nodeChoice in nodeChoices) { Choice choice = new Choice(); choice.Text = (nodeChoice.Attributes["text"] as XmlAttribute).Value; choice.IsCorrect = Convert.ToBoolean((nodeChoice.Attributes["isCorrect"] as XmlAttribute).Value); question.AddChoice(choice); } exam.AddQuestion(question); } return(exam); }