public void TestMinimalRawAct() { //Note our use of the "extended" user id var db = new CSALDatabase(DB_URL); const int TURN_ID_START = CSALMongo.Model.StudentLessonActs.TURN_ID_START; db.SaveRawStudentLessonAct("{'LessonID': 'lesson', 'UserID': 'memphis-semiotics-fozzy-bear', 'TurnID': " + TURN_ID_START.ToString() + "}"); var lessons = db.FindLessons(); Assert.AreEqual(1, lessons.Count); Assert.AreEqual(1, lessons[0].TurnCount); Assert.AreEqual("lesson", lessons[0].LessonID); CollectionAssert.AreEquivalent(new string[] { "fozzy-bear" }, lessons[0].Students); var students = db.FindStudents(); Assert.AreEqual(1, students.Count); Assert.AreEqual(1, students[0].TurnCount); Assert.AreEqual("fozzy-bear", students[0].UserID); var classes = db.FindClasses(); Assert.AreEqual(1, classes.Count); Assert.AreEqual("semiotics", classes[0].ClassID); Assert.AreEqual("memphis", classes[0].Location); CollectionAssert.AreEquivalent(new string[] { "fozzy-bear" }, classes[0].Students); CollectionAssert.AreEquivalent(new string[] { "lesson" }, classes[0].Lessons); var turns = db.FindTurns(null, null); Assert.AreEqual(1, turns.Count); Assert.AreEqual(1, db.FindTurns("lesson", null).Count); Assert.AreEqual(1, db.FindTurns(null, "fozzy-bear").Count); Assert.AreEqual(1, db.FindTurns("lesson", "fozzy-bear").Count); Assert.AreEqual("fozzy-bear", turns[0].UserID); Assert.AreEqual("lesson", turns[0].LessonID); Assert.AreEqual(1, turns[0].Turns.Count); //Turn ID of 0 - we should show one attempt and 0 completions Assert.AreEqual(1, turns[0].Attempts); Assert.AreEqual(0, turns[0].Completions); }
public void TestAttemptedRawActs() { var db = new CSALDatabase(DB_URL); var turns = db.FindTurns(null, null); Assert.AreEqual(0, turns.Count); const int TURN_ID_START = CSALMongo.Model.StudentLessonActs.TURN_ID_START; var attempted = new CSALMongo.TurnModel.ConvLog { UserID = "memphis-semiotics-fozzy-bear", LessonID = "lesson", TurnID = TURN_ID_START }; var completion = new CSALMongo.TurnModel.ConvLog { UserID = "memphis-semiotics-fozzy-bear", LessonID = "lesson", TurnID = TURN_ID_START + 1, Transitions = new List <CSALMongo.TurnModel.TransitionLog> { new CSALMongo.TurnModel.TransitionLog { StateID = "TestEnding", RuleID = "TestHint", Actions = new List <CSALMongo.TurnModel.ActionLog> { new CSALMongo.TurnModel.ActionLog { Agent = "System", Act = "End", Data = "Doesn't Matter" } } } } }; db.SaveRawStudentLessonAct(attempted.ToJson()); turns = db.FindTurns(null, null); Assert.AreEqual(1, turns.Count); Assert.AreEqual(1, turns[0].Attempts); Assert.AreEqual(0, turns[0].Completions); db.SaveRawStudentLessonAct(completion.ToJson()); turns = db.FindTurns(null, null); Assert.AreEqual(1, turns.Count); Assert.AreEqual(1, turns[0].Attempts); Assert.AreEqual(1, turns[0].Completions); db.SaveRawStudentLessonAct(attempted.ToJson()); turns = db.FindTurns(null, null); Assert.AreEqual(1, turns.Count); Assert.AreEqual(2, turns[0].Attempts); Assert.AreEqual(1, turns[0].Completions); completion.TurnID++; db.SaveRawStudentLessonAct(completion.ToJson()); turns = db.FindTurns(null, null); Assert.AreEqual(1, turns.Count); Assert.AreEqual(2, turns[0].Attempts); Assert.AreEqual(2, turns[0].Completions); completion.TurnID = TURN_ID_START; db.SaveRawStudentLessonAct(completion.ToJson()); turns = db.FindTurns(null, null); Assert.AreEqual(1, turns.Count); Assert.AreEqual(3, turns[0].Attempts); Assert.AreEqual(3, turns[0].Completions); //We have saved five turns Assert.AreEqual(5, turns[0].Turns.Count); //Final test - make sure that we don't break on poorly formed transitions/actions //Note that now we need to start checking stuff with raw turn access db.SaveRawStudentLessonAct(@"{ 'UserID': 'memphis-semiotics-fozzy-bear', 'LessonID': 'lesson', 'TurnID': $TURN_ID_START, 'Transitions': 42 }".Replace("$TURN_ID_START", TURN_ID_START.ToString())); var rawTurns = db.FindTurnsRaw(null, null); Assert.AreEqual(1, rawTurns.Count); Assert.AreEqual(4, rawTurns[0].GetValue("Attempts", -1).AsInt32); Assert.AreEqual(3, rawTurns[0].GetValue("Completions", -1).AsInt32); Assert.AreEqual(6, rawTurns[0].GetValue("Turns").AsBsonArray.Count); db.SaveRawStudentLessonAct(@"{ 'UserID': 'memphis-semiotics-fozzy-bear', 'LessonID': 'lesson', 'TurnID': 10, 'Transitions': [42] }"); rawTurns = db.FindTurnsRaw(null, null); Assert.AreEqual(1, rawTurns.Count); Assert.AreEqual(4, rawTurns[0].GetValue("Attempts", -1).AsInt32); Assert.AreEqual(3, rawTurns[0].GetValue("Completions", -1).AsInt32); Assert.AreEqual(7, rawTurns[0].GetValue("Turns").AsBsonArray.Count); db.SaveRawStudentLessonAct(@"{ 'UserID': 'memphis-semiotics-fozzy-bear', 'LessonID': 'lesson', 'TurnID': 12, 'Transitions': [{'Actions': 42}] }"); rawTurns = db.FindTurnsRaw(null, null); Assert.AreEqual(1, rawTurns.Count); Assert.AreEqual(4, rawTurns[0].GetValue("Attempts", -1).AsInt32); Assert.AreEqual(3, rawTurns[0].GetValue("Completions", -1).AsInt32); Assert.AreEqual(8, rawTurns[0].GetValue("Turns").AsBsonArray.Count); db.SaveRawStudentLessonAct(@"{ 'UserID': 'memphis-semiotics-fozzy-bear', 'LessonID': 'lesson', 'TurnID': 12, 'Transitions': [{'Actions': [42]}] }"); rawTurns = db.FindTurnsRaw(null, null); Assert.AreEqual(1, rawTurns.Count); Assert.AreEqual(4, rawTurns[0].GetValue("Attempts", -1).AsInt32); Assert.AreEqual(3, rawTurns[0].GetValue("Completions", -1).AsInt32); Assert.AreEqual(9, rawTurns[0].GetValue("Turns").AsBsonArray.Count); db.SaveRawStudentLessonAct(@"{ 'UserID': 'memphis-semiotics-fozzy-bear', 'LessonID': 'lesson', 'TurnID': 13, 'Transitions': [{'Actions': [{'Agent':'system', 'Act':'end'}]}] }"); rawTurns = db.FindTurnsRaw(null, null); Assert.AreEqual(1, rawTurns.Count); Assert.AreEqual(4, rawTurns[0].GetValue("Attempts", -1).AsInt32); Assert.AreEqual(4, rawTurns[0].GetValue("Completions", -1).AsInt32); Assert.AreEqual(10, rawTurns[0].GetValue("Turns").AsBsonArray.Count); //Make sure fozzy bear is in memphis bool foundFozzy = false; foreach (var student in db.FindStudentsByLocation("memphis")) { if (student.UserID == "fozzy-bear") { foundFozzy = true; break; } } Assert.IsTrue(foundFozzy); }
// POST api/maketestdata/42 public Dictionary <string, string> Post(int id, [FromBody] string value) { if (id != 42) { throw new Exception("Nice Try!"); } Debug.Print("Received " + value); DateTime now = DateTime.Now; const int TURN_ID_START = StudentLessonActs.TURN_ID_START; var db = DBConn(); db.SaveClass(new Class { ClassID = "funky/class!", Location = "loc1", Students = new List <string> { "good/student*", "s2", "s3" }, Lessons = new List <string> { "l1", "l2", "l3" }, TeacherName = "teach" }); db.SaveClass(new Class { ClassID = "c2", Location = "loc2", Students = new List <string> { "good/student*", "s2", "s3" }, Lessons = new List <string> { "l1", "l2", "l3" }, TeacherName = "teach" }); db.SaveClass(new Class { ClassID = "c3", Location = "loc3", Students = new List <string> { "good/student*", "s2", "s3" }, Lessons = new List <string> { "l1", "l2", "l3" }, TeacherName = "teach" }); db.SaveLesson(new Lesson { LessonID = "http://10.0.0.1/lesson/one", Students = new List <string> { "good/student*", "s2", "s2" }, TurnCount = 0, AttemptTimes = new List <DateTime>(), StudentsAttempted = new List <string>(), StudentsCompleted = new List <string>() }); db.SaveLesson(new Lesson { LessonID = "l2", Students = new List <string> { "good/student*", "s2", "s2" }, TurnCount = 0, AttemptTimes = new List <DateTime>(), StudentsAttempted = new List <string>(), StudentsCompleted = new List <string>() }); db.SaveLesson(new Lesson { LessonID = "l3", Students = new List <string> { "good/student*", "s2", "s2" }, TurnCount = 0, AttemptTimes = new List <DateTime>(), StudentsAttempted = new List <string>(), StudentsCompleted = new List <string>() }); db.SaveStudent(new Student { UserID = "good/student*", FirstName = "First", LastName = "Student", TurnCount = 0 }); db.SaveStudent(new Student { UserID = "s2", FirstName = "Middle", LastName = "Student", TurnCount = 0 }); db.SaveStudent(new Student { UserID = "s3", FirstName = "Last", LastName = "Student", TurnCount = 0 }); db.SaveRawStudentLessonAct(SAMPLE_RAW.Replace("$LESSONID$", "http://10.0.0.1/lesson/one").Replace("$USERID$", "good/student*").Replace("$TURNID$", TURN_ID_START.ToString())); db.SaveRawStudentLessonAct(SAMPLE_RAW.Replace("$LESSONID$", "l2").Replace("$USERID$", "good/student*").Replace("$TURNID$", TURN_ID_START.ToString())); db.SaveRawStudentLessonAct(SAMPLE_RAW.Replace("$LESSONID$", "l2").Replace("$USERID$", "good/student*").Replace("$TURNID$", (TURN_ID_START + 1).ToString())); db.SaveRawStudentLessonAct(SAMPLE_RAW_COMPLETE.Replace("$LESSONID$", "http://10.0.0.1/lesson/one").Replace("$USERID$", "good/student*").Replace("$TURNID$", (TURN_ID_START + 1).ToString())); //Turn saved with no matching class, student, or lesson db.SaveRawStudentLessonAct(SAMPLE_RAW.Replace("$LESSONID$", "LMISS").Replace("$USERID$", "LOCMISS-CMISS-SMISS").Replace("$TURNID$", TURN_ID_START.ToString())); db.SaveRawStudentLessonAct(SAMPLE_RAW.Replace("$LESSONID$", "LMISS").Replace("$USERID$", "LOCMISS-CMISS-SMISS").Replace("$TURNID$", (TURN_ID_START + 1).ToString())); return(new Dictionary <string, string> { { "val", "woo hoo" }, { "success", "true" } }); }