public void popJob_popVeryLongJob()
        {
            Owner ow = new Owner("Nicolai");
            Job j1 = new Job(1, 30000, ow, s => "Hello world");
            Job j2 = new Job(1, 30002, ow, s => "Hello world");
            Job j3 = new Job(1, 3000000, ow, s => "Hello world");

            Scheduler sh = new Scheduler();

            sh.addJob(j3);
            sh.addJob(j1);
            sh.addJob(j2);

            Assert.AreEqual(j3, sh.PopJob());
        }
        public void Test_PopJobWhileMaxed()
        {
            Scheduler s = new Scheduler(3, 10);
            Func<string[], int> funk = st => { Thread.Sleep(1); return 0; };
            Mutex mutex = new Mutex(false, "Test_PopJobWhileMaxed");

            for (int i = 1; i <= 30+1; i++)
            {
                s.AddJob(new Job(new User("test" + i, ""), 100, 1, funk));
            }

            bool ready = false;
            bool mutexReleased = false;
            Thread blocker = new Thread(new ThreadStart(() =>
            {
                mutex.WaitOne();
                while (!ready) { Thread.Sleep(500); }
                mutex.ReleaseMutex();
                mutexReleased = true;
            }));

            try
            {
                blocker.Start();
                Job job = null;
                for (int i = 0; i < 3; i++)
                {
                    job = s.PopJob();
                    Thread t = new Thread(new ThreadStart(() => job.Process(new String[] { "Test", "stuff" })));
                    t.Start();
                    while (t.ThreadState != ThreadState.WaitSleepJoin) { Thread.Sleep(500); }
                }
                try
                {
                    s.PopJob();
                    Assert.Fail("It was possible to pop a job from scheduler while at maximum capacity. NOTE: this test does not work in release mode.");
                }
                catch (MaxedOutException)
                {
                    // This is good
                }
            }
            catch
            {
                // To the finally block!
            }
            finally
            {
                ready = true;
                while (!mutexReleased) { Thread.Sleep(500); }
            }
        }
 /// <summary>
 /// Helper method. Checks that the sequence of jobs returned is in the same order as they were added
 /// </summary>
 /// <param name="s">The scheduler</param>
 /// <param name="first">Job to add first</param>
 /// <param name="second">Job to add second</param>
 /// <param name="third">Job to add last</param>
 private void AssertSequence(Scheduler s, Job first, Job second, Job third)
 {
     s.AddJob(first);
     s.AddJob(second);
     s.AddJob(third);
     Assert.AreEqual(first, s.PopJob());
     Assert.AreEqual(second, s.PopJob());
     Assert.AreEqual(third, s.PopJob());
 }
 public void Test_PopJobWithNoJobs()
 {
     Scheduler s = new Scheduler(3, 10);
     try
     {
         s.PopJob();
         Assert.Fail("It was possible to pop a job when there were no jobs to pop");
     }
     catch (JobsDepletedException)
     {
         // This is good
     }
 }