Created
June 2, 2014 16:43
-
-
Save renestein/b251977a1cb9cae3e2d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void RunOne_When_More_Tasks_Added_Then_Only_First_Task_Is_Executed() | |
{ | |
bool wasTask1Called = false; | |
bool wasTask2Called = false; | |
m_scheduler.Dispatch(() => | |
{ | |
wasTask1Called = true; | |
}); | |
m_scheduler.Dispatch(() => | |
{ | |
wasTask2Called = true; | |
}); | |
m_scheduler.RunOne(); | |
Assert.IsTrue(wasTask1Called && !wasTask2Called); | |
} | |
[TestMethod] | |
public void RunOne_When_Two_Tasks_Added_Then_Returns_One() | |
{ | |
const int NUMBER_OF_SCHEDULED_TASKS = 2; | |
const int NUMBER_OF_RUNNED_TASKS = 1; | |
Enumerable.Range(0, NUMBER_OF_SCHEDULED_TASKS) | |
.Select(_ => m_scheduler.Dispatch(() => | |
{ | |
})).ToArray(); | |
var executedTasksCount = m_scheduler.RunOne(); | |
Assert.AreEqual(NUMBER_OF_RUNNED_TASKS, executedTasksCount); | |
} | |
[TestMethod] | |
public void RunOne_When_More_Tasks_Added_And_Cancel_Work_Then_Only_First_Task_Is_Executed() | |
{ | |
bool wasTask1Called = false; | |
bool wasTask2Called = false; | |
m_scheduler.Dispatch(() => | |
{ | |
wasTask1Called = true; | |
}); | |
m_scheduler.Dispatch(() => | |
{ | |
wasTask2Called = true; | |
}); | |
cancelWorkAfterTimeout(); | |
m_scheduler.RunOne(); | |
Assert.IsTrue(wasTask1Called && !wasTask2Called); | |
} | |
[TestMethod] | |
public void RunOne_When_Two_Tasks_Added_And_Cancel_Work_Then_Returns_One() | |
{ | |
const int NUMBER_OF_SCHEDULED_TASKS = 2; | |
const int RUNNED_TASKS = 1; | |
Enumerable.Range(0, NUMBER_OF_SCHEDULED_TASKS) | |
.Select(_ => m_scheduler.Dispatch(() => | |
{ | |
})).ToArray(); | |
cancelWorkAfterTimeout(); | |
var executedTasksCount = m_scheduler.RunOne(); | |
Assert.AreEqual(RUNNED_TASKS, executedTasksCount); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment