public void TestAdd() { Threadnaught handler = new Threadnaught(); int task1 = handler.AddTask(new Task(() => AddWasteTime(1))); int task2 = handler.AddTask(new Task(() => AddWasteTime(2))); int task3 = handler.AddTask(new Task(() => AddWasteTime(3))); handler.WaitForTask(task1); handler.WaitForTask(task2); handler.WaitForTask(task3); // if any of the stats havent ran to completion, this test failed if (new List <TaskStatus>() { handler.GetTask(task1).Status, handler.GetTask(task2).Status, handler.GetTask(task3).Status }.Any(m => m != TaskStatus.RanToCompletion)) { Assert.Fail(); } }
public void TextAutoExecute() { Threadnaught handler = new Threadnaught(false); int task1 = handler.AddTask(new Task(() => ExecuteWasteTime(1))); int task2 = handler.AddTask(new Task(() => ExecuteWasteTime(2))); int task3 = handler.AddTask(new Task(() => ExecuteWasteTime(3))); handler.StartTask(task1); handler.StartTask(task3); handler.WaitForTask(task1); handler.WaitForTask(task3); // if task two rant o completion or ran, it failed Task taskTwo = handler.GetTask(task2); if (taskTwo.Status == TaskStatus.RanToCompletion || taskTwo.Status == TaskStatus.Running) { Assert.Fail(); } }
public void TestWait() { // create the task handler Threadnaught handler = new Threadnaught(false); // false to check the auto start on the wait // setup a list to get the task keys List <int> taskKeys = new List <int>(); // add the tasks to the handler newTasks.ForEach(m => taskKeys.Add(handler.AddTask(m))); // pick a task to run int taskToRun = PickRandomTaskKey(taskKeys); handler.WaitForTask(taskToRun); Assert.AreEqual(handler.GetTask(taskToRun).Status, TaskStatus.RanToCompletion); taskKeys.Where(m => m != taskToRun).ToList().ForEach(m => Assert.AreEqual(handler.GetTask(m).Status, TaskStatus.Created)); }