Beispiel #1
0
        public void TestSaveReadingTargetExisting()
        {
            var db = new CSALDatabase(DB_URL);

            db.SaveRawStudentLessonAct(Properties.Resources.SampleRawAct);
            var students = db.FindStudents();

            Assert.AreEqual(1, students.Count);
            Assert.IsNotNull(students[0].ReadingURLs);

            DateTime preWrite = DateTime.Now.AddSeconds(-1);

            db.SaveStudentReadingTarget("{UserID:'" + SAMPLE_RAW_USER + "', TargetURL:'http://test/a'}");
            students = db.FindStudents();
            Assert.AreEqual(1, students.Count);
            var student = students[0];

            Assert.AreEqual(1, student.TurnCount);
            Assert.AreEqual(SAMPLE_RAW_USER.ToLowerInvariant(), student.UserID);

            Assert.AreEqual(1, student.ReadingURLs.Count);
            var visit = student.ReadingURLs[0];

            Assert.AreEqual(visit.TargetURL, "http://test/a");
            Assert.IsTrue(preWrite < visit.VisitTime);
        }
Beispiel #2
0
        public void TestStudentModel()
        {
            var db = new CSALDatabase(DB_URL);

            db.SaveRawStudentLessonAct(Properties.Resources.SampleRawAct);

            var origStudent = db.FindStudents()[0];
            var student1    = db.FindStudents()[0];
            var student2    = db.FindStudents()[0];

            Assert.AreEqual(SAMPLE_RAW_USER.ToLowerInvariant(), student1.Id);
            Assert.AreEqual(SAMPLE_RAW_USER.ToLowerInvariant(), student1.UserID);
            Assert.AreEqual(SAMPLE_RAW_USER.ToLowerInvariant(), student2.Id);
            Assert.AreEqual(SAMPLE_RAW_USER.ToLowerInvariant(), student2.UserID);

            //Need to verify that lesson ID and _id are tied together
            student1.Id     = "changed2";
            student2.UserID = "changed2";

            Assert.AreEqual("changed2", student1.Id);
            Assert.AreEqual("changed2", student1.UserID);
            Assert.AreEqual("changed2", student2.Id);
            Assert.AreEqual("changed2", student2.UserID);

            //Also need to check that we didn't somehow break JSON compat
            student2.Id     = SAMPLE_RAW_USER;
            student1.UserID = SAMPLE_RAW_USER;
            Assert.AreEqual(GetJSON(origStudent), GetJSON(student1));
            Assert.AreEqual(GetJSON(student1), GetJSON(student2));
        }
Beispiel #3
0
        public void TestRawActSave()
        {
            var db = new CSALDatabase(DB_URL);

            const int ITS = 128;

            for (int i = 0; i < ITS; ++i)
            {
                db.SaveRawStudentLessonAct(Properties.Resources.SampleRawAct);
            }

            var lessons = db.FindLessons();

            Assert.AreEqual(1, lessons.Count);
            Assert.AreEqual(ITS, lessons[0].TurnCount);
            Assert.AreEqual(SAMPLE_RAW_LESSON.ToLowerInvariant(), lessons[0].LessonID);
            CollectionAssert.AreEquivalent(new string[] { SAMPLE_RAW_USER.ToLowerInvariant() }, lessons[0].Students);

            var students = db.FindStudents();

            Assert.AreEqual(1, students.Count);
            Assert.AreEqual(ITS, students[0].TurnCount);
            Assert.AreEqual(SAMPLE_RAW_USER.ToLowerInvariant(), students[0].UserID);

            //Raw has "simple" user ID, so no class/location information
            var classes = db.FindClasses();

            Assert.AreEqual(0, classes.Count);

            var turns = db.FindTurns(null, null);

            Assert.AreEqual(1, turns.Count);
            Assert.AreEqual(1, db.FindTurns(SAMPLE_RAW_LESSON, null).Count);
            Assert.AreEqual(1, db.FindTurns(null, SAMPLE_RAW_USER).Count);
            Assert.AreEqual(1, db.FindTurns(SAMPLE_RAW_LESSON, SAMPLE_RAW_USER).Count);

            Assert.AreEqual(SAMPLE_RAW_USER, turns[0].UserID);
            Assert.AreEqual(SAMPLE_RAW_LESSON, turns[0].LessonID);
            Assert.AreEqual(ITS, turns[0].Turns.Count);

            //The sample act has no completion action and is turn ID 4 - so no attempts and no completions
            Assert.AreEqual(0, turns[0].Attempts);
            Assert.AreEqual(0, turns[0].Completions);
        }
Beispiel #4
0
        public void Post()
        {
            var controller = new TurnController();

            controller.AppSettings = this.AppSettings;

            const int ITS = 128;

            for (int i = 0; i < ITS; ++i)
            {
                controller.Post(GetSampleRawAct());
            }

            var db = new CSALDatabase(DB_URL);

            var lessons = db.FindLessons();

            Assert.AreEqual(1, lessons.Count);
            Assert.AreEqual(ITS, lessons[0].TurnCount);
            Assert.AreEqual(SAMPLE_RAW_LESSON, lessons[0].LessonID);
            CollectionAssert.AreEquivalent(new string[] { SAMPLE_RAW_USER }, lessons[0].Students);

            var students = db.FindStudents();

            Assert.AreEqual(1, students.Count);
            Assert.AreEqual(ITS, students[0].TurnCount);
            Assert.AreEqual(SAMPLE_RAW_USER.ToLowerInvariant(), students[0].UserID.ToLowerInvariant());

            //Raw has "simple" user ID, so no class/location information
            var classes = db.FindClasses();

            Assert.AreEqual(0, classes.Count);

            var turns = db.FindTurns(null, null);

            Assert.AreEqual(1, turns.Count);
            Assert.AreEqual(1, db.FindTurns(SAMPLE_RAW_LESSON, null).Count);
            Assert.AreEqual(1, db.FindTurns(null, SAMPLE_RAW_USER).Count);
            Assert.AreEqual(1, db.FindTurns(SAMPLE_RAW_LESSON, SAMPLE_RAW_USER).Count);

            Assert.AreEqual(SAMPLE_RAW_USER.ToLowerInvariant(), turns[0].UserID.ToLowerInvariant());
            Assert.AreEqual(SAMPLE_RAW_LESSON.ToLowerInvariant(), turns[0].LessonID.ToLowerInvariant());
            Assert.AreEqual(ITS, turns[0].Turns.Count);
        }
Beispiel #5
0
        public void TestSaveReadingTargetMissing()
        {
            var db       = new CSALDatabase(DB_URL);
            var students = db.FindStudents();

            Assert.AreEqual(0, students.Count);

            DateTime preWrite = DateTime.Now.AddSeconds(-1);

            db.SaveStudentReadingTarget("{UserID:'" + SAMPLE_RAW_USER + "', TargetURL:'http://test/a'}");
            students = db.FindStudents();
            Assert.AreEqual(1, students.Count);
            var student = students[0];

            Assert.AreEqual(0, student.TurnCount);
            Assert.AreEqual(SAMPLE_RAW_USER.ToLowerInvariant(), student.UserID);

            Assert.AreEqual(1, student.ReadingURLs.Count);
            var visit = student.ReadingURLs[0];

            Assert.AreEqual(visit.TargetURL, "http://test/a");
            Assert.IsTrue(preWrite < visit.VisitTime);

            db.SaveStudentReadingTarget("{UserID:'" + SAMPLE_RAW_USER + "', TargetURL:'http://test/b'}");
            students = db.FindStudents();
            Assert.AreEqual(1, students.Count);
            student = students[0];

            Assert.AreEqual(0, student.TurnCount);
            Assert.AreEqual(SAMPLE_RAW_USER.ToLowerInvariant(), student.UserID);

            Assert.AreEqual(2, student.ReadingURLs.Count);

            Assert.AreEqual(student.ReadingURLs[0].TargetURL, "http://test/a");
            Assert.AreEqual(student.ReadingURLs[1].TargetURL, "http://test/b");

            Assert.IsTrue(preWrite < student.ReadingURLs[0].VisitTime);
            Assert.IsTrue(preWrite < student.ReadingURLs[1].VisitTime);
        }