Esempio n. 1
0
        public void TestLessonWrite()
        {
            List <ConSim.Lib.Classes.clsTask> Tasks =
                new List <ConSim.Lib.Classes.clsTask> ();
            List <ConSim.Lib.Classes.clsModule> AllowedModules =
                new List <ConSim.Lib.Classes.clsModule> ();

            Tasks.Add(task);
            AllowedModules.Add(module);

            ConSim.Lib.Classes.clsLesson lesson =
                new ConSim.Lib.Classes.clsLesson(Name, Version, Tasks, AllowedModules, lessonDir);
            lesson.save(lessonJSON);

            lesson = new ConSim.Lib.Classes.clsLesson(lessonJSON);

            // Test that the lesson was read back correctly
            Assert.AreEqual(lesson.Name, Name);
            Assert.AreEqual(lesson.Version, Version);
            Assert.AreEqual(lesson.activeTask.ExpectedResult,
                            Tasks [0].ExpectedResult);
            Assert.AreEqual(lesson.activeTask.LongDescription,
                            Tasks [0].LongDescription);
            Assert.AreEqual(lesson.activeTask.Name, Tasks [0].Name);
            Assert.AreEqual(lesson.activeTask.ShortDescription,
                            Tasks [0].ShortDescription);
            Assert.AreEqual(lesson.AllowedModules [0].filename, module.filename);
            Assert.AreEqual(lesson.AllowedModules [0].gettype, module.gettype);
        }
Esempio n. 2
0
        public void TestLessonFlow()
        {
            List <ConSim.Lib.Classes.clsTask> Tasks =
                new List <ConSim.Lib.Classes.clsTask> ();

            List <ConSim.Lib.Classes.clsModule> AllowedModules =
                new List <ConSim.Lib.Classes.clsModule> ();

            Tasks.Add(
                new ConSim.Lib.Classes.clsTask(task.Name, task.ShortDescription,
                                               task.LongDescription, "2")
                );

            Tasks.Add(
                new ConSim.Lib.Classes.clsTask(task.Name, task.ShortDescription,
                                               task.LongDescription, "3")
                );

            AllowedModules.Add(module);

            ConSim.Lib.Classes.clsLesson lesson =
                new ConSim.Lib.Classes.clsLesson(Name, Version, Tasks, AllowedModules,
                                                 lessonDir);

            lesson.save(lessonJSON);

            lesson = new ConSim.Lib.Classes.clsLesson(lessonJSON);

            string[] args = new string[1];

            //Test a failed try returns false
            args[0] = lesson.activeTask.ExpectedResult.ToString();
            Assert.AreEqual(lesson.attemptTask("increment", args,
                                               lesson.clsToiMod(module)), false);

            //Test a weird value still returns false
            args[0] = "random";
            Assert.AreEqual(lesson.attemptTask("increment", args,
                                               lesson.clsToiMod(module)), false);

            //Test the right value returns false but advances the task
            args[0] = (Convert.ToInt32(lesson.activeTask.ExpectedResult) - 1).
                      ToString();
            Assert.AreEqual(lesson.attemptTask("increment", args,
                                               lesson.clsToiMod(module)), false);

            Assert.AreNotEqual(lesson.activeTask.ExpectedResult, 2);

            //Test the final task completion returns true
            args[0] = (Convert.ToInt32(lesson.activeTask.ExpectedResult) - 1).
                      ToString();

            Assert.AreEqual(lesson.attemptTask("increment", args,
                                               lesson.clsToiMod(module)), true);
        }
Esempio n. 3
0
        public void TestSandboxLessonFlow()
        {
            // Copy the module file for sandbox tests
            if (Directory.Exists(sandboxLessonDir + ps + "Modules" + ps) == false)
            {
                Directory.CreateDirectory(sandboxLessonDir + ps + "Modules" + ps);
            }

            File.Copy(lessonModule, sandboxLessonDir + ps + "Modules" +
                      ps + DLLName, true);

            List <ConSim.Lib.Classes.clsTask> Tasks =
                new List <ConSim.Lib.Classes.clsTask> ();

            List <ConSim.Lib.Classes.clsModule> AllowedModules =
                new List <ConSim.Lib.Classes.clsModule> ();

            AllowedModules.Add(module);

            ConSim.Lib.Classes.clsLesson lesson =
                new ConSim.Lib.Classes.clsLesson(Name, Version, Tasks, AllowedModules,
                                                 sandboxLessonDir);

            lesson.save(sandboxLessonJSON);

            lesson = new ConSim.Lib.Classes.clsLesson(sandboxLessonJSON);

            string[] args = new string[1];

            //Test multiple commands and ensure the expected output
            args[0] = "1";
            Assert.AreEqual(lesson.attemptTask("increment", args,
                                               lesson.clsToiMod(module)), false);
            Assert.AreEqual(lesson.lastStandardOutput, "2");
            args[0] = "random";
            Assert.AreEqual(lesson.attemptTask("increment", args,
                                               lesson.clsToiMod(module)), false);
            Assert.AreEqual(lesson.lastErrorOutput,
                            "Unexpected format in arguments");
        }
Esempio n. 4
0
        public void TestSandboxLessonFlow()
        {
            // Copy the module file for sandbox tests
              if (Directory.Exists (sandboxLessonDir + ps + "Modules" + ps) == false)
            Directory.CreateDirectory (sandboxLessonDir + ps + "Modules" + ps);

              File.Copy (lessonModule, sandboxLessonDir + ps + "Modules" +
            ps + DLLName, true);

              List<ConSim.Lib.Classes.clsTask> Tasks =
            new List<ConSim.Lib.Classes.clsTask> ();

              List<ConSim.Lib.Classes.clsModule> AllowedModules =
            new List<ConSim.Lib.Classes.clsModule> ();

              AllowedModules.Add (module);

              ConSim.Lib.Classes.clsLesson lesson =
            new ConSim.Lib.Classes.clsLesson (Name, Version, Tasks, AllowedModules,
              sandboxLessonDir);

              lesson.save (sandboxLessonJSON);

              lesson = new ConSim.Lib.Classes.clsLesson  (sandboxLessonJSON);

              string[] args = new string[1];

              //Test multiple commands and ensure the expected output
              args[0] = "1";
              Assert.AreEqual(lesson.attemptTask("increment", args,
            lesson.clsToiMod(module)), false);
              Assert.AreEqual (lesson.lastStandardOutput, "2");
              args[0] = "random";
              Assert.AreEqual (lesson.attemptTask ("increment", args,
            lesson.clsToiMod(module)), false);
              Assert.AreEqual (lesson.lastErrorOutput,
            "Unexpected format in arguments");
        }
Esempio n. 5
0
        public void TestLessonWrite()
        {
            List<ConSim.Lib.Classes.clsTask> Tasks =
            new List<ConSim.Lib.Classes.clsTask> ();
              List<ConSim.Lib.Classes.clsModule> AllowedModules =
            new List<ConSim.Lib.Classes.clsModule> ();

              Tasks.Add (task);
              AllowedModules.Add (module);

              ConSim.Lib.Classes.clsLesson lesson =
            new ConSim.Lib.Classes.clsLesson (Name, Version, Tasks, AllowedModules,lessonDir);
              lesson.save (lessonJSON);

              lesson = new ConSim.Lib.Classes.clsLesson (lessonJSON);

              // Test that the lesson was read back correctly
              Assert.AreEqual (lesson.Name, Name);
              Assert.AreEqual (lesson.Version, Version);
              Assert.AreEqual (lesson.activeTask.ExpectedResult,
            Tasks [0].ExpectedResult);
              Assert.AreEqual (lesson.activeTask.LongDescription,
            Tasks [0].LongDescription);
              Assert.AreEqual (lesson.activeTask.Name, Tasks [0].Name);
              Assert.AreEqual (lesson.activeTask.ShortDescription,
            Tasks [0].ShortDescription);
              Assert.AreEqual (lesson.AllowedModules [0].filename, module.filename);
              Assert.AreEqual (lesson.AllowedModules [0].gettype, module.gettype);
        }
Esempio n. 6
0
        public void TestLessonFlow()
        {
            List<ConSim.Lib.Classes.clsTask> Tasks =
            new List<ConSim.Lib.Classes.clsTask> ();

              List<ConSim.Lib.Classes.clsModule> AllowedModules =
            new List<ConSim.Lib.Classes.clsModule> ();

              Tasks.Add (
            new ConSim.Lib.Classes.clsTask (task.Name, task.ShortDescription,
              task.LongDescription, "2")
              );

              Tasks.Add (
            new ConSim.Lib.Classes.clsTask (task.Name, task.ShortDescription,
              task.LongDescription, "3")
              );

              AllowedModules.Add (module);

              ConSim.Lib.Classes.clsLesson lesson =
            new ConSim.Lib.Classes.clsLesson (Name, Version, Tasks, AllowedModules,
              lessonDir);

              lesson.save (lessonJSON);

              lesson = new ConSim.Lib.Classes.clsLesson (lessonJSON);

              string[] args = new string[1];

              //Test a failed try returns false
              args[0] = lesson.activeTask.ExpectedResult.ToString();
              Assert.AreEqual(lesson.attemptTask("increment", args,
            lesson.clsToiMod(module)), false);

              //Test a weird value still returns false
              args[0] = "random";
              Assert.AreEqual (lesson.attemptTask ("increment", args,
            lesson.clsToiMod(module)), false);

              //Test the right value returns false but advances the task
              args[0] = (Convert.ToInt32(lesson.activeTask.ExpectedResult) - 1).
            ToString();
              Assert.AreEqual (lesson.attemptTask ("increment", args,
            lesson.clsToiMod(module)), false);

              Assert.AreNotEqual (lesson.activeTask.ExpectedResult, 2);

              //Test the final task completion returns true
              args[0] = (Convert.ToInt32(lesson.activeTask.ExpectedResult) - 1).
            ToString();

              Assert.AreEqual (lesson.attemptTask ("increment", args,
            lesson.clsToiMod(module)), true);
        }