public void TestCommandMatch() { 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, "increment 6", false, false, true, false, null, null) ); AllowedModules.Add(module); ConSim.Lib.Classes.clsLesson lesson = new ConSim.Lib.Classes.clsLesson(Name, Version, Tasks, AllowedModules, lessonDir); string[] args = new string[1]; //Fail Test args[0] = "4"; Assert.AreEqual(lesson.attemptTask("increment", args, lesson.clsToiMod(module)), false); //Success Test args[0] = "6"; Assert.AreEqual(lesson.attemptTask("increment", args, lesson.clsToiMod(module)), true); }
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); }
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"); }
public void TestCommandMatch() { 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, "increment 6",false,false,true, false, null, null) ); AllowedModules.Add (module); ConSim.Lib.Classes.clsLesson lesson = new ConSim.Lib.Classes.clsLesson (Name, Version, Tasks, AllowedModules, lessonDir); string[] args = new string[1]; //Fail Test args[0] = "4"; Assert.AreEqual (lesson.attemptTask ("increment", args, lesson.clsToiMod (module)), false); //Success Test args[0] = "6"; Assert.AreEqual (lesson.attemptTask ("increment", args, lesson.clsToiMod (module)), true); }
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"); }
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); }