public ResponseJson Create(ExaminationTask model) { using (TransactionScope scope = new TransactionScope()) { Int32 id; ResponseJson resJson; resJson = new ResponseJson(ResponseStatus.Success, now); id = GetETId(); try { model.ET_Id = id; olsEni.ExaminationTasks.Add(model); olsEni.SaveChanges(); try { // 添加参与人员 AddAttendees(model); // 添加试卷模板与试题模板 AddPaperTemplateAndQuestionTemplate(model); } catch (Exception ex1) { throw ex1; } scope.Complete(); return resJson; } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return resJson; } } }
public ActionResult Create(ExaminationTask m) { ResponseJson resJson; if (ModelState.IsValid) { resJson = um.Create(m); if (ResponseStatus.Success == resJson.status) { return Redirect("/Contents/html/parent_reload.htm"); } ModelState.AddModelError("", resJson.message); } ViewBag.DepartmentsAndUsers = new UDepartment().GetZTreeJsonWithUsers(); ViewBag.ExaminationTaskTemplates = um.GetTemplateList(); ViewBag.QuestionClassifies = new UQuestionClassify().GetZTreeJson(Status.Available); return View(m); }
public String Edit(ExaminationTask model) { using (TransactionScope scope = new TransactionScope()) { try { ExaminationTask et; et = olsEni.ExaminationTasks.SingleOrDefault(m => m.ET_Id == model.ET_Id); // 已开始/已结束的手动任务不允许编辑 if (et.ET_Mode == 0 && et.ET_Enabled != 0) { return "不允许修改进行中或已结束的手动任务。"; } // 已开始的自动任务不允许编辑 else if (et.ET_Mode == 1 && et.ET_Enabled == 1) { return "不允许修改进行中自动任务。"; } // 已开始/已结束的预定任务不允许编辑 else if (et.ET_Mode == 2 && et.ET_Enabled != 0) { return "不允许修改进行中或已结束的预定任务。"; } olsEni.Entry(et).State = EntityState.Detached; olsEni.Entry(model).State = EntityState.Modified; if (0 == olsEni.SaveChanges()) { throw new Exception(ResponseMessage.SaveChangesError); } try { // 删除试卷模板与试题模板 DeletePaperTemplateAndQuestionTemplate(model); // 添加试卷模板与试题模板 AddPaperTemplateAndQuestionTemplate(model); // 添加参与人员 AddAttendees(model); } catch (Exception ex1) { throw ex1; } scope.Complete(); return null; } catch (Exception ex) { StaticHelper.RecordSystemLog(ex); return ex.Message; } } }
public ActionResult Edit(ExaminationTask m) { String returnMessage; if (ModelState.IsValid) { returnMessage = um.Edit(m); if (returnMessage == null) { return Redirect("/Contents/html/parent_reload.htm"); } ModelState.AddModelError("", returnMessage); } ViewBag.DepartmentsAndUsers = new UDepartment().GetZTreeJsonWithUsers(); ViewBag.ExaminationTaskTemplates = um.GetTemplateList(); ViewBag.QuestionClassifies = new UQuestionClassify().GetZTreeJson(Status.Available); return View(m); }
private Boolean CreatePaperTemplate(ExaminationTask et, List<Question> readyQs) { Int32 eptId, eptqId; String eptQs; DateTime startTime, endTime; Int32[] eptQsAry; ExaminationPaperTemplate ept; ExaminationPaperTemplateQuestion eptq; ExaminationQuestionDone eqd; List<ExaminationPaperTemplateQuestion> tmpEPTQ = new List<ExaminationPaperTemplateQuestion>(); eptId = GetEPTId(); eptQsAry = readyQs.Select(m => m.Q_Id).ToArray(); eptQs = JsonConvert.SerializeObject(eptQsAry); startTime = et.ET_StartTime; startTime = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day, startTime.Hour, startTime.Minute, startTime.Second); endTime = et.ET_EndTime; endTime = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day, endTime.Hour, endTime.Minute, endTime.Second); ept = new ExaminationPaperTemplate { EPT_Id = eptId, ET_Id = et.ET_Id, ET_Type = et.ET_Type, EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Undone, EPT_StartDate = nowDate, EPT_StartTime = startTime, EPT_EndTime = endTime, EPT_TimeSpan = et.ET_TimeSpan, EPT_Questions = eptQs, EPT_Remark = "本试卷模板由系统于" + now.ToString("yyyy年MM月dd日") + "自动生成。", EPT_AddTime = now, EPT_Status = 1 }; olsEni.Entry(ept).State = EntityState.Added; if (0 == olsEni.SaveChanges()) { throw new Exception(ResponseMessage.SaveChangesError); } eptqId = GetEPTQId(); foreach (var q in readyQs) { eptq = new ExaminationPaperTemplateQuestion { EPTQ_Id = eptqId, EPT_Id = eptId, EPTQ_Type = q.Q_Type, EPTQ_Classify = q.QC_Id, EPTQ_Score = q.Q_Score, EPTQ_Content = q.Q_Content, EPTQ_OptionalAnswer = q.Q_OptionalAnswer, EPTQ_ModelAnswer = q.Q_ModelAnswer, EPTQ_Remark = q.Q_Remark, EPTQ_AddTime = now, EPTQ_Status = 1 }; tmpEPTQ.Add(eptq); olsEni.Entry(eptq).State = EntityState.Added; // 添加已出题记录 eqd = new ExaminationQuestionDone { ET_Id = et.ET_Id, EPT_Id = ept.EPT_Id, Q_Id = q.Q_Id }; olsEni.Entry(eqd).State = EntityState.Added; eptqId += 1; } if (0 == olsEni.SaveChanges()) { throw new Exception(ResponseMessage.SaveChangesError); } return true; }
private ResponseJson SetCustomTypeStatus(ExaminationTask et, ExaminationTaskStatus etStatus) { Int32 eptId, continueDays; DateTime startTime, endTime; ResponseJson resJson; UExaminationPaperTemplate uept; List<ExaminationPaperTemplate> epts; List<ExaminationPaper> eps; resJson = new ResponseJson(ResponseStatus.Success, now); epts = olsEni .ExaminationPaperTemplates .Where(m => m.ET_Id == et.ET_Id) .ToList(); // 验证类型为“考试”的任务 if (epts.Count != 1 && et.ET_Type == (Byte)ExaminationTaskType.Examination) { resJson.status = ResponseStatus.Error; resJson.message = "试卷模板不匹配。"; return resJson; } else if (et.ET_Type == (Byte)ExaminationTaskType.Exercise) { resJson.status = ResponseStatus.Success; return resJson; } epts[0].EPT_PaperTemplateStatus = (Byte)etStatus; // 开始任务及试卷模板 if (ExaminationTaskStatus.Enabled == etStatus) { startTime = et.ET_StartTime; epts[0].EPT_StartTime = startTime; epts[0].EPT_StartDate = startTime.Date; continueDays = et.ET_ContinuedDays > 0 ? et.ET_ContinuedDays - 1 : 0; startTime = startTime.AddDays(continueDays); endTime = et.ET_EndTime; endTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, endTime.Hour, endTime.Minute, endTime.Second); epts[0].EPT_EndTime = endTime; } // 终止任务及试卷模板、试卷 else if (ExaminationTaskStatus.Disabled == etStatus) { uept = new UExaminationPaperTemplate(); epts[0].EPT_EndTime = DateTime.Now; // 终止试卷 eptId = epts[0].EPT_Id; eps = olsEni.ExaminationPapers .Where(m => m.EPT_Id == eptId) .ToList(); foreach (var ep in eps) { ep.EP_PaperStatus = (Byte)PaperStatus.Done; uept.GradePaper(ep); uept.SaveChanges(); } } return resJson; }
private void DeletePaperTemplateAndQuestionTemplate(ExaminationTask model) { ExaminationPaperTemplate ept; List<ExaminationPaperTemplateQuestion> eptqs; // 任务类型为“练习”或自动类型为“自动”,则不删除试卷模板 if ((Byte)ExaminationTaskType.Exercise == model.ET_Type || (Byte)ExaminationTaskMode.Auto == model.ET_Mode) { return; } ept = olsEni.ExaminationPaperTemplates.Single(m => m.ET_Id == model.ET_Id); eptqs = olsEni.ExaminationPaperTemplateQuestions.Where(m => m.EPT_Id == ept.EPT_Id).ToList(); foreach (var eptq in eptqs) { olsEni.Entry(eptq).State = EntityState.Deleted; } if (0 == olsEni.SaveChanges()) { throw new Exception(ResponseMessage.SaveChangesError); } olsEni.Entry(ept).State = EntityState.Deleted; if (0 == olsEni.SaveChanges()) { throw new Exception(ResponseMessage.SaveChangesError); } }
private void AddAttendees(ExaminationTask model) { User_Department ud; ExaminationTaskAttendee eta; Int32[] uIds; List<ExaminationTaskAttendee> etas; etas = olsEni.ExaminationTaskAttendees.Where(m => m.ET_Id == model.ET_Id).ToList(); foreach (var eta1 in etas) { olsEni.Entry(eta1).State = EntityState.Deleted; } olsEni.SaveChanges(); etas = new List<ExaminationTaskAttendee>(); uIds = JsonConvert.DeserializeObject<Int32[]>(model.ET_Attendee); foreach (var uId in uIds) { ud = olsEni.User_Department.SingleOrDefault(m => m.U_Id == uId); if (null == ud) { continue; } eta = new ExaminationTaskAttendee { ET_Id = model.ET_Id, U_Id = uId, D_Id = ud.D_Id }; if (etas.Where(m => m.U_Id == uId).Count() == 0) { etas.Add(eta); olsEni.Entry(eta).State = EntityState.Added; } } if (0 == olsEni.SaveChanges()) { throw new Exception(ResponseMessage.SaveChangesError); } }
public void Test2() { int id, epId; DateTime now, startTime, endTime; ExaminationTask et; ExaminationPaper ep; ExaminationPaperTemplate ept; UExaminationTask_Accessor uet; UExaminationPaperTemplate_Accessor uept; GeneratePaperTemplate_Accessor gpt = new GeneratePaperTemplate_Accessor(); ResponseJson resJson; Object expected, actual; #region 部署测试数据 now = DateTime.Now; uet = new UExaminationTask_Accessor(); startTime = now.AddSeconds(5); endTime = startTime.AddSeconds(5); endTime = new DateTime(1970, 1, 1, endTime.Hour, endTime.Minute, endTime.Second); id = new Utility().GetETId(); et = new ExaminationTask { ET_Id = id, ET_Name = "单元测试预定任务" + id, ET_Enabled = (Byte)ExaminationTaskStatus.Disabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[6,9]", ET_Attendee = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]", ET_StatisticType = (Byte)StatisticType.Score, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Custom, ET_AutoType = (Byte)AutoType.Custom, ET_AutoOffsetDay = 0, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[]", ET_AutoRatio = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0.1},{\"type\":\"计算题\",\"percent\":0.1},{\"type\":\"案例分析题\",\"percent\":0.1},{\"type\":\"问答题\",\"percent\":0.1}]", ET_StartTime = startTime, ET_EndTime = endTime, ET_ContinuedDays = 1, ET_TimeSpan = 1, ET_PaperTemplates = "[]", ET_Questions = "[3,4,5,6,7,8,9,10,11,12]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; olsEni.Entry(et).State = EntityState.Added; if (0 == olsEni.SaveChanges()) { Assert.Fail("部署测试数据失败1。"); } uet.AddPaperTemplateAndQuestionTemplate(et); #endregion // 测试开始任务操作是否正常 expected = ResponseStatus.Success; resJson = uet.SetExaminationTaskStatus(et.ET_Id, ExaminationTaskStatus.Enabled); actual = resJson.status; Assert.AreEqual(expected, actual); // 任务是否开启 Thread.Sleep(6 * 1000); new ChangePaperTemplateStatus_Accessor().Change(); ept = olsEni.ExaminationPaperTemplates.Where(m => m.ET_Id == et.ET_Id).Take(1).ToList()[0]; expected = (Byte)PaperTemplateStatus.Doing; actual = ept.EPT_PaperTemplateStatus; Assert.AreEqual(expected, actual); // 结束时间设置是否正常 startTime = startTime.AddDays(et.ET_ContinuedDays - 1); expected = new DateTime(startTime.Year, startTime.Month, startTime.Day, endTime.Hour, endTime.Minute, endTime.Second); actual = ept.EPT_EndTime; Assert.AreEqual(expected, actual); // 添加试卷 uept = new UExaminationPaperTemplate_Accessor(); resJson = uept.EnterExamination(ept.EPT_Id, 1); // 任务是否正常自动结束 Thread.Sleep(5 * 1000); et = olsEni.ExaminationTasks.Single(m => m.ET_Id == et.ET_Id); expected = (Byte)ExaminationTaskStatus.Disabled; actual = et.ET_Enabled; Assert.AreEqual(expected, actual); // 试卷是否自动关闭 Thread.Sleep(56 * 1000); new ChangePaperTemplateStatus_Accessor().Change(); new ChangePaperStatus_Accessor().Change(); epId = (Int32)resJson.addition; ep = olsEni.ExaminationPapers.Single(m => m.EP_Id == epId); expected = (Byte)PaperStatus.Done; actual = ep.EP_PaperStatus; Assert.AreEqual(expected, actual); }
public void ChangeTest1() { int id; DateTime now, startTime; ExaminationTask et; ExaminationPaperTemplate ept; UExaminationTask uet; GeneratePaperTemplate_Accessor gpt = new GeneratePaperTemplate_Accessor(); ChangePaperTemplateStatus target; ResponseJson resJson; Object expected, actual; // 获取状态为“未做”、“进行中”的试卷模板 #region 部署测试数据 now = DateTime.Now; uet = new UExaminationTask(); startTime = new DateTime(1970, 1, 1, now.AddHours(1).Hour, now.Minute, 0); id = new Utility().GetETId(); et = new ExaminationTask { ET_Id = id, ET_Name = "单元测试每日任务" + id, ET_Enabled = (Byte)ExaminationTaskStatus.Enabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[6,9]", ET_Attendee = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]", ET_StatisticType = (Byte)StatisticType.Score, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Auto, ET_AutoType = (Byte)AutoType.Day, ET_AutoOffsetDay = 0, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[\"综合、公文、绩效知识(90题)\",\"所得税知识(180题)\",\"营业税知识(60题)\",\"其他地方税知识(180题)\",\"税收征管法、相关法律法规及征管制度(253题)\",\"规费知识(130题)\",\"纳税服务知识(95题)\"]", ET_AutoRatio = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0.1},{\"type\":\"计算题\",\"percent\":0.1},{\"type\":\"案例分析题\",\"percent\":0.1},{\"type\":\"问答题\",\"percent\":0.1}]", ET_StartTime = startTime, ET_EndTime = startTime, ET_TimeSpan = 0, ET_PaperTemplates = "[]", ET_Questions = "[]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; olsEni.Entry(et).State = EntityState.Added; startTime = new DateTime(1970, 1, 1, now.Hour, now.Minute, now.AddSeconds(5).Second); id += 1; et = new ExaminationTask { ET_Id = id, ET_Name = "单元测试每日任务" + id, ET_Enabled = (Byte)ExaminationTaskStatus.Enabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[6,9]", ET_Attendee = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]", ET_StatisticType = (Byte)StatisticType.Score, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Auto, ET_AutoType = (Byte)AutoType.Day, ET_AutoOffsetDay = 0, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[\"综合、公文、绩效知识(90题)\",\"所得税知识(180题)\",\"营业税知识(60题)\",\"其他地方税知识(180题)\",\"税收征管法、相关法律法规及征管制度(253题)\",\"规费知识(130题)\",\"纳税服务知识(95题)\"]", ET_AutoRatio = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0.1},{\"type\":\"计算题\",\"percent\":0.1},{\"type\":\"案例分析题\",\"percent\":0.1},{\"type\":\"问答题\",\"percent\":0.1}]", ET_StartTime = startTime, ET_EndTime = startTime, ET_TimeSpan = 0, ET_PaperTemplates = "[]", ET_Questions = "[]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; olsEni.Entry(et).State = EntityState.Added; if (0 == olsEni.SaveChanges()) { Assert.Fail("部署测试数据失败1。"); } // 生成试卷模板数据 uet = new UExaminationTask(); resJson = gpt.Generate(); if (ResponseStatus.Error == resJson.status || resJson.message != "") { Assert.Fail("部署测试数据失败3。" + resJson.message); } Thread.Sleep(10 * 1000); ept = olsEni.ExaminationPaperTemplates.SingleOrDefault(m => m.ET_Id == id); if (null == ept) { Assert.Fail("部署测试数据失败4。"); } ept.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Doing; if (0 == olsEni.SaveChanges()) { Assert.Fail("部署测试数据失败2。"); } #endregion expected = "共有 2条记录。其中“未做” 1条;“进行中” 1条。"; target = new ChangePaperTemplateStatus(); actual = target.Change(); Assert.AreEqual(expected, ((Dictionary<String, String>)(((ResponseJson)actual).data))["RecordInfo"]); }
/// <summary> /// 判断是否需要生成试卷模板 /// </summary> /// <param name="et"></param> /// <returns></returns> private Boolean WhetherGenerate(ExaminationTask et) { Int32 eptCount, dayOfWeek, dayOfMonth; Boolean whether; DateTime startTime; whether = true; startTime = et.ET_StartTime; startTime = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day, startTime.Hour, startTime.Minute, startTime.Second); // 当前时间已超过开始时间,则当次不生成 if (now > startTime) { return false; } switch (et.ET_AutoType) { case (Byte)AutoType.Day: break; case (Byte)AutoType.Week: dayOfWeek = (Int32)now.DayOfWeek; if (0 == dayOfWeek) { dayOfWeek = 7; } if (et.ET_AutoOffsetDay != dayOfWeek) { whether = false; } break; case (Byte)AutoType.Month: dayOfMonth = now.Day; if (et.ET_AutoOffsetDay != dayOfMonth) { whether = false; } break; default: break; } if (whether) { eptCount = olsEni .ExaminationPaperTemplates .Where(m => m.EPT_StartDate == nowDate && m.ET_Id == et.ET_Id && (m.EPT_PaperTemplateStatus == (Byte)PaperTemplateStatus.Undone || m.EPT_PaperTemplateStatus == (Byte)PaperTemplateStatus.Doing)) .Count(); if (0 != eptCount) { whether = false; } } return whether; }
// 去除已出试题 private List<Question> removeQuestionDone(ExaminationTask et, List<Question> qs) { List<ExaminationQuestionDone> eqds; List<Question> filteredQs; Int32 count; eqds = olsEni.ExaminationQuestionDones.Where(m => m.ET_Id == et.ET_Id).ToList(); filteredQs = new List<Question>(); foreach (var q in qs) { count = eqds.Where(m => m.U_Id == uId && m.Q_Id == q.Q_Id).Count(); if (count == 0) { filteredQs.Add(q); } } return filteredQs; }
private List<Question> GenerateWithScore(ExaminationTask et) { Int32 diffCoef, optionTotalScore, totalScore; String[] classifies; List<Question> qs, readyQs; List<AutoRatio> ratios; diffCoef = et.ET_DifficultyCoefficient; classifies = JsonConvert.DeserializeObject<String[]>(et.ET_AutoClassifies); qs = GetQuestions(classifies, diffCoef, true); qs = removeQuestionDone(et, qs); optionTotalScore = GetTotalScore(qs); totalScore = et.ET_TotalScore; // “备选试题总分”必须大于等于“出题总分”,才能保证有足够试题可供选择 if (optionTotalScore >= totalScore) { // 选题 ratios = JsonConvert.DeserializeObject<List<AutoRatio>>(et.ET_AutoRatio); ratios = AdjustRatios(ratios); readyQs = SelectQuestionsWithScore(ratios, totalScore, qs); } else// if (optionTotalScore < totalScore) { // 退出 throw new Exception("备选试题总分小于出题总分。"); } return readyQs; }
private List<Question> Generate(ExaminationTask et) { Byte statisticType; List<Question> readyQs; statisticType = et.ET_StatisticType; if ((Byte)StatisticType.Score == statisticType) { readyQs = GenerateWithScore(et); } else if ((Byte)StatisticType.Number == statisticType) { readyQs = GenerateWithNumber(et); } else { var e = new Exception("未设置成绩计算方式。"); e.Data.Add("Info", "任务Id:" + et.ET_Id); throw e; } return readyQs; }
public Int32 CreatePaperTemplateOfExercise(ExaminationTask et, List<Question> readyQs) { Int32 eptId, eptqId; String eptQs; Int32[] eptQsAry; ExaminationPaperTemplate ept; ExaminationPaperTemplateQuestion eptq; ExaminationQuestionDone eqd; eptId = GetEPTId(); eptQsAry = readyQs.Select(m => m.Q_Id).ToArray(); eptQs = JsonConvert.SerializeObject(eptQsAry); ept = new ExaminationPaperTemplate { EPT_Id = eptId, ET_Id = et.ET_Id, ET_Type = et.ET_Type, EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Undone, EPT_StartDate = et.ET_StartTime.Date, EPT_StartTime = et.ET_StartTime, // 练习试卷模板,无需开启,故“开始时间”设置为任务定义的“开始时间”。 EPT_EndTime = et.ET_StartTime, // 同上 EPT_TimeSpan = et.ET_TimeSpan, EPT_Questions = eptQs, EPT_Remark = "本试卷模板由系统于" + now.ToString("yyyy年MM月dd日") + "自动生成。", EPT_AddTime = now, EPT_Status = 1 }; olsEni.Entry(ept).State = EntityState.Added; if (0 == olsEni.SaveChanges()) { throw new Exception(ResponseMessage.SaveChangesError); } eptqId = GetEPTQId(); foreach (var q in readyQs) { eptq = new ExaminationPaperTemplateQuestion { EPTQ_Id = eptqId, EPT_Id = eptId, EPTQ_Type = q.Q_Type, EPTQ_Classify = q.QC_Id, EPTQ_Score = q.Q_Score, EPTQ_Content = q.Q_Content, EPTQ_OptionalAnswer = q.Q_OptionalAnswer, EPTQ_ModelAnswer = q.Q_ModelAnswer, EPTQ_Remark = q.Q_Remark, EPTQ_AddTime = now, EPTQ_Status = 1 }; olsEni.Entry(eptq).State = EntityState.Added; // 添加已出题记录 eqd = new ExaminationQuestionDone { ET_Id = et.ET_Id, EPT_Id = ept.EPT_Id, U_Id = uId, Q_Id = q.Q_Id }; olsEni.Entry(eqd).State = EntityState.Added; eptqId += 1; } if (0 == olsEni.SaveChanges()) { throw new Exception(ResponseMessage.SaveChangesError); } return eptId; }
public ExaminationTask GetNew() { DateTime initDateTime; ExaminationTask model; initDateTime = new DateTime(1970, 1, 1); model = new ExaminationTask() { ET_Id = 0, ET_Name = "", ET_Enabled = (Byte)ExaminationTaskStatus.Disabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[]", ET_Attendee = "[]", ET_StatisticType = (Byte)StatisticType.Unset, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Manual, ET_AutoType = (Byte)AutoType.Manual, ET_AutoOffsetDay = 0, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[]", ET_AutoRatio = "[]", ET_StartTime = initDateTime, ET_EndTime = initDateTime, ET_TimeSpan = 0, ET_PaperTemplates = "[]", ET_Questions = "[]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; return model; }
public void WhetherGenerateTest3_1() { int id; bool expected, actual; DateTime now, startTime; ExaminationTask et; UExaminationTask uet; GeneratePaperTemplate_Accessor target = new GeneratePaperTemplate_Accessor(); #region 添加测试数据 now = DateTime.Now; startTime = new DateTime(1970, 1, 1, now.AddHours(1).Hour, now.Minute, 0); uet = new UExaminationTask(); id = new Utility().GetETId(); et = new ExaminationTask { ET_Id = id, ET_Name = "单元测试每月任务1", ET_Enabled = (Byte)ExaminationTaskStatus.Enabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[6,9]", ET_Attendee = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]", ET_StatisticType = (Byte)StatisticType.Score, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Auto, ET_AutoType = (Byte)AutoType.Month, ET_AutoOffsetDay = 1, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[\"综合、公文、绩效知识(90题)\",\"所得税知识(180题)\",\"营业税知识(60题)\",\"其他地方税知识(180题)\",\"税收征管法、相关法律法规及征管制度(253题)\",\"规费知识(130题)\",\"纳税服务知识(95题)\"]", ET_AutoRatio = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0.1},{\"type\":\"计算题\",\"percent\":0.1},{\"type\":\"案例分析题\",\"percent\":0.1},{\"type\":\"问答题\",\"percent\":0.1}]", ET_StartTime = startTime, ET_EndTime = startTime, ET_TimeSpan = 0, ET_PaperTemplates = "[]", ET_Questions = "[]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; olsEni.Entry(et).State = EntityState.Added; if (0 == olsEni.SaveChanges()) { Assert.Fail("添加测试数据失败。"); } #endregion expected = false; actual = target.WhetherGenerate(et); #region 删除测试数据 olsEni.Entry(et).State = EntityState.Deleted; if (0 == olsEni.SaveChanges()) { Assert.Fail("删除测试数据失败。id值为 " + id + " 。"); } #endregion Assert.AreEqual(expected, actual); }
public void GenerateEtTest() { int id; Object expected, actual; DateTime now, startTime; ExaminationTask et; UExaminationTask uet; GeneratePaperTemplate_Accessor target = new GeneratePaperTemplate_Accessor(); actual = null; // 成绩计算方式为得分 #region 添加测试数据 now = DateTime.Now; startTime = new DateTime(1970, 1, 1, now.AddHours(1).Hour, now.Minute, 0); uet = new UExaminationTask(); id = new Utility().GetETId(); et = new ExaminationTask { ET_Id = id, ET_Name = "单元测试每日任务1", ET_Enabled = (Byte)ExaminationTaskStatus.Enabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[6,9]", ET_Attendee = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]", ET_StatisticType = (Byte)StatisticType.Score, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Auto, ET_AutoType = (Byte)AutoType.Day, ET_AutoOffsetDay = 0, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[\"综合、公文、绩效知识(90题)\",\"所得税知识(180题)\",\"营业税知识(60题)\",\"其他地方税知识(180题)\",\"税收征管法、相关法律法规及征管制度(253题)\",\"规费知识(130题)\",\"纳税服务知识(95题)\"]", ET_AutoRatio = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0.1},{\"type\":\"计算题\",\"percent\":0.1},{\"type\":\"案例分析题\",\"percent\":0.1},{\"type\":\"问答题\",\"percent\":0.1}]", ET_StartTime = startTime, ET_EndTime = startTime, ET_TimeSpan = 0, ET_PaperTemplates = "[]", ET_Questions = "[]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; olsEni.Entry(et).State = EntityState.Added; #endregion expected = et.ET_TotalScore; actual = target.Generate(et); Assert.AreEqual(expected, ((List<Question>)actual).Sum(m => m.Q_Score)); actual = null; // 成绩计算方式为正确率 #region 添加测试数据 now = DateTime.Now; startTime = new DateTime(1970, 1, 1, now.AddHours(1).Hour, now.Minute, 0); uet = new UExaminationTask(); id = new Utility().GetETId(); et = new ExaminationTask { ET_Id = id, ET_Name = "单元测试每日任务1", ET_Enabled = (Byte)ExaminationTaskStatus.Enabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[6,9]", ET_Attendee = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]", ET_StatisticType = (Byte)StatisticType.Number, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Auto, ET_AutoType = (Byte)AutoType.Day, ET_AutoOffsetDay = 0, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[\"综合、公文、绩效知识(90题)\",\"所得税知识(180题)\",\"营业税知识(60题)\",\"其他地方税知识(180题)\",\"税收征管法、相关法律法规及征管制度(253题)\",\"规费知识(130题)\",\"纳税服务知识(95题)\"]", ET_AutoRatio = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0.1},{\"type\":\"计算题\",\"percent\":0.1},{\"type\":\"案例分析题\",\"percent\":0.1},{\"type\":\"问答题\",\"percent\":0.1}]", ET_StartTime = startTime, ET_EndTime = startTime, ET_TimeSpan = 0, ET_PaperTemplates = "[]", ET_Questions = "[]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; olsEni.Entry(et).State = EntityState.Added; #endregion expected = et.ET_TotalNumber; actual = target.Generate(et); Assert.AreEqual(expected, ((List<Question>)actual).Count); actual = null; // 未设置成绩计算方式 #region 添加测试数据 now = DateTime.Now; startTime = new DateTime(1970, 1, 1, now.AddHours(1).Hour, now.Minute, 0); uet = new UExaminationTask(); id = new Utility().GetETId(); et = new ExaminationTask { ET_Id = id, ET_Name = "单元测试每日任务1", ET_Enabled = (Byte)ExaminationTaskStatus.Enabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[6,9]", ET_Attendee = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]", ET_StatisticType = (Byte)StatisticType.Unset, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Auto, ET_AutoType = (Byte)AutoType.Day, ET_AutoOffsetDay = 0, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[\"综合、公文、绩效知识(90题)\",\"所得税知识(180题)\",\"营业税知识(60题)\",\"其他地方税知识(180题)\",\"税收征管法、相关法律法规及征管制度(253题)\",\"规费知识(130题)\",\"纳税服务知识(95题)\"]", ET_AutoRatio = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0.1},{\"type\":\"计算题\",\"percent\":0.1},{\"type\":\"案例分析题\",\"percent\":0.1},{\"type\":\"问答题\",\"percent\":0.1}]", ET_StartTime = startTime, ET_EndTime = startTime, ET_TimeSpan = 0, ET_PaperTemplates = "[]", ET_Questions = "[]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; olsEni.Entry(et).State = EntityState.Added; #endregion expected = "未设置成绩计算方式。任务Id:"+ et.ET_Id; try { target.Generate(et); } catch (Exception ex) { actual = ex; } Assert.AreEqual(expected, ((Exception)actual).Message + ((Exception)actual).Data["Info"]); actual = null; }
private void AddPaperTemplateAndQuestionTemplate(ExaminationTask model) { Int32 id, tmpId, continueDays; Question q; ExaminationPaperTemplate ept; ExaminationPaperTemplateQuestion eptq; List<ExaminationPaperTemplateQuestion> eptqs; Int32[] qs; DateTime startDate, startTime, endTime; // 任务类型为“练习”或自动类型为“自动”,则不添加手动试卷模板 if ((Byte)ExaminationTaskType.Exercise == model.ET_Type || (Byte)ExaminationTaskMode.Auto == model.ET_Mode) { return; } id = GetEPTId(); // 设置“预定考试任务”的时间 if ((Byte)ExaminationTaskMode.Custom == model.ET_Mode) { // - [201608191537] startDate = model.ET_StartTime.Date; startTime = model.ET_StartTime; startTime = new DateTime(startDate.Year, startDate.Month, startDate.Day, startTime.Hour, startTime.Minute, startTime.Second); startTime = startTime.AddMinutes(3); endTime = model.ET_EndTime; endTime = new DateTime(startDate.Year, startDate.Month, startDate.Day, endTime.Hour, endTime.Minute, endTime.Second); continueDays = model.ET_ContinuedDays > 0 ? model.ET_ContinuedDays - 1 : 0; endTime = endTime.AddDays(continueDays).AddMinutes(3); } else { startDate = now.Date; startTime = now; endTime = now; } ept = new ExaminationPaperTemplate { EPT_Id = id, ET_Id = model.ET_Id, ET_Type = model.ET_Type, EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Undone, EPT_StartDate = startDate, EPT_StartTime = startTime, EPT_EndTime = endTime, EPT_TimeSpan = model.ET_TimeSpan, EPT_Questions = model.ET_Questions, EPT_AddTime = now, EPT_Status = (Byte)Status.Available }; olsEni.ExaminationPaperTemplates.Add(ept); qs = JsonConvert.DeserializeObject<Int32[]>(model.ET_Questions); eptqs = new List<ExaminationPaperTemplateQuestion>(); // 获取试题模板Id id = GetEPTQId(); for (var i = 0; i < qs.Length; i++) { tmpId = qs[i]; q = olsEni.Questions.SingleOrDefault(m => m.Q_Id == tmpId); if (null != q) { eptq = new ExaminationPaperTemplateQuestion { EPTQ_Id = id, EPT_Id = ept.EPT_Id, EPTQ_Type = q.Q_Type, EPTQ_Classify = q.QC_Id, EPTQ_DifficultyCoefficient = q.Q_DifficultyCoefficient, EPTQ_Score = q.Q_Score, EPTQ_Content = q.Q_Content, EPTQ_OptionalAnswer = q.Q_OptionalAnswer, EPTQ_ModelAnswer = q.Q_ModelAnswer, EPTQ_Remark = q.Q_Remark, EPTQ_AddTime = now, EPTQ_Status = q.Q_Status }; eptqs.Add(eptq); id += 1; } } eptqs = AdjustScore(eptqs, model.ET_StatisticType, model.ET_TotalScore); if (0 == olsEni.SaveChanges()) { throw new Exception(ResponseMessage.SaveChangesError); } foreach (var eptq1 in eptqs) { olsEni.Entry(eptq1).State = EntityState.Added; } if (0 == olsEni.SaveChanges()) { throw new Exception(ResponseMessage.SaveChangesError); } }
public void GenerateTest() { int id, dboResult; Object expected, actual; DateTime now, startTime; ExaminationTask et; UExaminationTask uet; GeneratePaperTemplate_Accessor target = new GeneratePaperTemplate_Accessor(); actual = null; #region 部署测试数据 now = DateTime.Now; startTime = new DateTime(1970, 1, 1, now.AddHours(1).Hour, now.Minute, 0); uet = new UExaminationTask(); id = new Utility().GetETId(); et = new ExaminationTask { ET_Id = id, ET_Name = "单元测试每日任务1", ET_Enabled = (Byte)ExaminationTaskStatus.Enabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[6,9]", ET_Attendee = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]", ET_StatisticType = (Byte)StatisticType.Score, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Auto, ET_AutoType = (Byte)AutoType.Day, ET_AutoOffsetDay = 0, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[\"综合、公文、绩效知识(90题)\",\"所得税知识(180题)\",\"营业税知识(60题)\",\"其他地方税知识(180题)\",\"税收征管法、相关法律法规及征管制度(253题)\",\"规费知识(130题)\",\"纳税服务知识(95题)\"]", ET_AutoRatio = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0.1},{\"type\":\"计算题\",\"percent\":0.1},{\"type\":\"案例分析题\",\"percent\":0.1},{\"type\":\"问答题\",\"percent\":0.1}]", ET_StartTime = startTime, ET_EndTime = startTime, ET_TimeSpan = 0, ET_PaperTemplates = "[]", ET_Questions = "[]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; olsEni.Entry(et).State = EntityState.Added; if (0 == olsEni.SaveChanges()) { Assert.Fail("添加测试数据失败。"); } dboResult = olsDbo.ExecuteSql("UPDATE Questions SET Q_Status = @status", new SqlParameter("@status", (Byte)Status.Recycle)); if (0 == dboResult) { Assert.Fail("更新试题数据失败。"); } #endregion expected = "单元测试每日任务1:备选试题总分小于出题总分。\\r\\n"; actual = target.Generate(); Assert.AreEqual(expected, ((ResponseJson)actual).message); actual = null; #region 恢复试题数据 dboResult = olsDbo.ExecuteSql("UPDATE Questions SET Q_Status = @status", new SqlParameter("@status", (Byte)Status.Available)); if (0 == dboResult) { Assert.Fail("更新试题数据失败。"); } #endregion // 正常情况 #region 部署测试数据 now = DateTime.Now; startTime = new DateTime(1970, 1, 1, now.AddHours(1).Hour, now.Minute, 0); uet = new UExaminationTask(); id = new Utility().GetETId(); et = new ExaminationTask { ET_Id = id, ET_Name = "单元测试每日任务1", ET_Enabled = (Byte)ExaminationTaskStatus.Enabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[6,9]", ET_Attendee = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]", ET_StatisticType = (Byte)StatisticType.Score, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Auto, ET_AutoType = (Byte)AutoType.Day, ET_AutoOffsetDay = 0, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[\"综合、公文、绩效知识(90题)\",\"所得税知识(180题)\",\"营业税知识(60题)\",\"其他地方税知识(180题)\",\"税收征管法、相关法律法规及征管制度(253题)\",\"规费知识(130题)\",\"纳税服务知识(95题)\"]", ET_AutoRatio = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0.1},{\"type\":\"计算题\",\"percent\":0.1},{\"type\":\"案例分析题\",\"percent\":0.1},{\"type\":\"问答题\",\"percent\":0.1}]", ET_StartTime = startTime, ET_EndTime = startTime, ET_TimeSpan = 0, ET_PaperTemplates = "[]", ET_Questions = "[]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; olsEni.Entry(et).State = EntityState.Added; if (0 == olsEni.SaveChanges()) { Assert.Fail("添加测试数据失败。"); } dboResult = olsDbo.ExecuteSql("UPDATE Questions SET Q_Status = @status", new SqlParameter("@status", (Byte)Status.Available)); if (0 == dboResult) { Assert.Fail("更新试题数据失败。"); } #endregion expected = "成功处理 1个考试任务。"; actual = target.Generate(); Assert.AreEqual(expected, ((ResponseJson)actual).addition); actual = null; }
private ResponseJson SetAutoTypeStatus(ExaminationTask et, ExaminationTaskStatus etStatus) { ResponseJson resJson; UExaminationPaperTemplate uept; List<ExaminationPaperTemplate> epts; List<ExaminationPaper> eps; resJson = new ResponseJson(ResponseStatus.Success, now); // 终止自动任务时,同时终止进行中的试卷模板、试卷。 if (ExaminationTaskStatus.Disabled == etStatus) { epts = olsEni .ExaminationPaperTemplates .Where(m => m.ET_Id == et.ET_Id) .ToList(); foreach (var ept in epts) { uept = new UExaminationPaperTemplate(); ept.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Done; // 终止试卷 eps = olsEni.ExaminationPapers .Where(m => m.EPT_Id == ept.EPT_Id) .ToList(); foreach (var ep in eps) { ep.EP_PaperStatus = (Byte)PaperStatus.Done; uept.GradePaper(ep); uept.SaveChanges(); } } } return resJson; }
public void GenerateWithScoreTest() { int id, dboResult; Object expected, actual; DateTime now, startTime; ExaminationTask et; UExaminationTask uet; GeneratePaperTemplate_Accessor target = new GeneratePaperTemplate_Accessor(); List<Question> qs; actual = null; // 备选试题总分小于出题总分 #region 部署测试数据 now = DateTime.Now; startTime = new DateTime(1970, 1, 1, now.AddHours(1).Hour, now.Minute, 0); uet = new UExaminationTask(); id = new Utility().GetETId(); et = new ExaminationTask { ET_Id = id, ET_Name = "单元测试每日任务1", ET_Enabled = (Byte)ExaminationTaskStatus.Enabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[6,9]", ET_Attendee = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]", ET_StatisticType = (Byte)StatisticType.Score, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Auto, ET_AutoType = (Byte)AutoType.Day, ET_AutoOffsetDay = 0, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[\"综合、公文、绩效知识(90题)\",\"所得税知识(180题)\",\"营业税知识(60题)\",\"其他地方税知识(180题)\",\"税收征管法、相关法律法规及征管制度(253题)\",\"规费知识(130题)\",\"纳税服务知识(95题)\"]", ET_AutoRatio = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0.1},{\"type\":\"计算题\",\"percent\":0.1},{\"type\":\"案例分析题\",\"percent\":0.1},{\"type\":\"问答题\",\"percent\":0.1}]", ET_StartTime = startTime, ET_EndTime = startTime, ET_TimeSpan = 0, ET_PaperTemplates = "[]", ET_Questions = "[]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; olsEni.Entry(et).State = EntityState.Added; dboResult = olsDbo.ExecuteSql("UPDATE Questions SET Q_Status = @status", new SqlParameter("@status", (Byte)Status.Recycle)); if (0 == dboResult) { Assert.Fail("更新试题数据失败。"); } qs = olsEni.Questions.Where(m => m.Q_Type == "单选题").Take(1).ToList(); qs.AddRange(olsEni.Questions.Where(m => m.Q_Type == "多选题").Take(1).ToList()); qs.AddRange(olsEni.Questions.Where(m => m.Q_Type == "判断题").Take(1).ToList()); qs.AddRange(olsEni.Questions.Where(m => m.Q_Type == "公文改错题").Take(1).ToList()); qs.AddRange(olsEni.Questions.Where(m => m.Q_Type == "计算题").Take(1).ToList()); qs.AddRange(olsEni.Questions.Where(m => m.Q_Type == "案例分析题").Take(1).ToList()); qs.AddRange(olsEni.Questions.Where(m => m.Q_Type == "问答题").Take(1).ToList()); foreach (var q in qs) { q.Q_Status = (Byte)Status.Available; } if (0 == olsEni.SaveChanges()) { Assert.Fail("部署测试数据失败。"); } #endregion expected = "备选试题总分小于出题总分。"; try { target.GenerateWithScore(et); } catch (Exception ex) { actual = ex; } Assert.AreEqual(expected, ((Exception)actual).Message); actual = null; #region 恢复试题状态 dboResult = olsDbo.ExecuteSql("UPDATE Questions SET Q_Status = @status", new SqlParameter("@status", (Byte)Status.Available)); if (0 == dboResult) { Assert.Fail("更新试题数据失败。"); } #endregion // 备选试题总分大于出题总分 #region 部署测试数据 now = DateTime.Now; startTime = new DateTime(1970, 1, 1, now.AddHours(1).Hour, now.Minute, 0); uet = new UExaminationTask(); id = new Utility().GetETId(); et = new ExaminationTask { ET_Id = id, ET_Name = "单元测试每日任务1", ET_Enabled = (Byte)ExaminationTaskStatus.Enabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[6,9]", ET_Attendee = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]", ET_StatisticType = (Byte)StatisticType.Score, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Auto, ET_AutoType = (Byte)AutoType.Day, ET_AutoOffsetDay = 0, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[\"综合、公文、绩效知识(90题)\",\"所得税知识(180题)\",\"营业税知识(60题)\",\"其他地方税知识(180题)\",\"税收征管法、相关法律法规及征管制度(253题)\",\"规费知识(130题)\",\"纳税服务知识(95题)\"]", ET_AutoRatio = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0.1},{\"type\":\"计算题\",\"percent\":0.1},{\"type\":\"案例分析题\",\"percent\":0.1},{\"type\":\"问答题\",\"percent\":0.1}]", ET_StartTime = startTime, ET_EndTime = startTime, ET_TimeSpan = 0, ET_PaperTemplates = "[]", ET_Questions = "[]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; olsEni.Entry(et).State = EntityState.Added; if (0 == olsEni.SaveChanges()) { Assert.Fail("部署测试数据失败。"); } #endregion expected = et.ET_TotalScore; actual = target.GenerateWithScore(et); Assert.AreEqual(expected, ((List<Question>)actual).Sum(m => m.Q_Score)); }
private ResponseJson SetManualTypeStatus(ExaminationTask et, ExaminationTaskStatus etStatus) { Int32 eptId; ResponseJson resJson; UExaminationPaperTemplate uept; List<ExaminationPaperTemplate> epts; List<ExaminationPaper> eps; resJson = new ResponseJson(ResponseStatus.Success, now); epts = olsEni .ExaminationPaperTemplates .Where(m => m.ET_Id == et.ET_Id) .ToList(); if (epts.Count != 1) { resJson.status = ResponseStatus.Error; resJson.message = "试卷模板不匹配。"; return resJson; } epts[0].EPT_PaperTemplateStatus = (Byte)etStatus; // 开始任务及试卷模板 if (ExaminationTaskStatus.Enabled == etStatus) { epts[0].EPT_StartTime = now; epts[0].EPT_StartDate = now.Date; epts[0].EPT_EndTime = now.AddMinutes(epts[0].EPT_TimeSpan); } // 终止任务及试卷模板、试卷 else if (ExaminationTaskStatus.Disabled == etStatus) { uept = new UExaminationPaperTemplate(); epts[0].EPT_EndTime = DateTime.Now; // 终止试卷 eptId = epts[0].EPT_Id; eps = olsEni.ExaminationPapers .Where(m => m.EPT_Id == eptId) .ToList(); foreach (var ep in eps) { ep.EP_PaperStatus = (Byte)PaperStatus.Done; uept.GradePaper(ep); uept.SaveChanges(); } } return resJson; }
public void ChangeTest() { Int32 id, epId, epqId; DateTime now, startTime; ExaminationTask et; ExaminationPaperTemplate ept; UExaminationTask uet; GeneratePaperTemplate_Accessor gpt = new GeneratePaperTemplate_Accessor(); ChangePaperStatus target = new ChangePaperStatus(); ResponseJson resJson; ExaminationPaper ep; ExaminationPaperQuestion epq; Object expected, actual; List<ExaminationPaperTemplateQuestion> eptqs; #region 部署测试数据 now = DateTime.Now; uet = new UExaminationTask(); startTime = new DateTime(1970, 1, 1, now.AddHours(1).Hour, now.Minute, 0); id = new Utility().GetETId(); et = new ExaminationTask { ET_Id = id, ET_Name = "单元测试每日任务" + id, ET_Enabled = (Byte)ExaminationTaskStatus.Enabled, ET_Type = (Byte)ExaminationTaskType.Examination, ET_ParticipatingDepartment = "[6,9]", ET_Attendee = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]", ET_StatisticType = (Byte)StatisticType.Score, ET_TotalScore = 100, ET_TotalNumber = 10, ET_Mode = (Byte)ExaminationTaskMode.Auto, ET_AutoType = (Byte)AutoType.Day, ET_AutoOffsetDay = 0, ET_DifficultyCoefficient = 0, ET_AutoClassifies = "[\"综合、公文、绩效知识(90题)\",\"所得税知识(180题)\",\"营业税知识(60题)\",\"其他地方税知识(180题)\",\"税收征管法、相关法律法规及征管制度(253题)\",\"规费知识(130题)\",\"纳税服务知识(95题)\"]", ET_AutoRatio = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0},{\"type\":\"计算题\",\"percent\":0},{\"type\":\"案例分析题\",\"percent\":0},{\"type\":\"问答题\",\"percent\":0}]", ET_StartTime = startTime, ET_EndTime = startTime, ET_TimeSpan = 0, ET_PaperTemplates = "[]", ET_Questions = "[]", ET_Remark = "", ET_AddTime = now, ET_Status = (Byte)Status.Available }; olsEni.Entry(et).State = EntityState.Added; if (0 == olsEni.SaveChanges()) { Assert.Fail("部署测试数据失败1。"); } // 生成试卷模板数据 uet = new UExaminationTask(); resJson = gpt.Generate(); if (ResponseStatus.Error == resJson.status || resJson.message != "") { Assert.Fail("部署测试数据失败3。" + resJson.message); } Thread.Sleep(10 * 1000); ept = olsEni.ExaminationPaperTemplates.SingleOrDefault(m => m.ET_Id == id); if (null == ept) { Assert.Fail("部署测试数据失败4。"); } ept.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Done; if (0 == olsEni.SaveChanges()) { Assert.Fail("部署测试数据失败2。"); } // 添加试卷 epId = new Utility().GetEPId(); ep = new ExaminationPaper { EP_Id = epId, ET_Id = ept.ET_Id, EPT_Id = ept.EPT_Id, EP_PaperStatus = (Byte)PaperStatus.Doing, EP_EndTime = ept.EPT_EndTime, EP_TimeSpan = ept.EPT_TimeSpan, EP_UserId = 1, EP_UserName = "", EP_Score = -1, EP_Remark = "", EP_AddTime = now, EP_Status = (Byte)Status.Available }; olsEni.Entry(ep).State = EntityState.Added; olsEni.SaveChanges(); // 添加答题数据 epqId = new Utility().GetEPQId(); eptqs = olsEni.ExaminationPaperTemplateQuestions.Where(m => m.EPT_Id == ept.EPT_Id).ToList(); foreach (var eptq in eptqs) { epq = new ExaminationPaperQuestion { EPQ_Id = epqId, EPQ_Answer = eptq.EPTQ_ModelAnswer, EPQ_Exactness = (Byte)AnswerStatus.Unset, EPQ_Critique = null, EPQ_AddTime = now, EP_Id = epId, EPTQ_Id = eptq.EPTQ_Id }; olsEni.Entry(epq).State = EntityState.Added; epqId += 1; } olsEni.SaveChanges(); #endregion expected = ResponseStatus.Success; actual = target.Change(); Assert.AreEqual(expected, ((ResponseJson)actual).status); olsEni.Entry(ep).State = EntityState.Detached; ep = null; ep = olsEni.ExaminationPapers.Single(m => m.EP_Id == epId); expected = (Byte)PaperStatus.Done; actual = ep.EP_PaperStatus; Assert.AreEqual(expected, actual); expected = 100; actual = ep.EP_Score; Assert.AreEqual(expected, actual); }