I have a class in .NET which creates and starts a new System.Threading.Tasks.Task
as follows:
public class ScheduledTask
{
private IFoo _foo;
public ScheduledTask(IFoo foo)
{
_foo = foo;
}
public void Start()
{
_task = new Task(() => Run());
_task.Start();
}
public void Stop(TimeSpan timeout)
{
var taskCompletedNormally = _task.Wait(timeout);
if (taskCompletedNormally)
{
_task.Dispose();
_task = null;
}
}
private void Run(){ // Do some work}
}
How do I unit test the ScheduledTask.Start
and ScheduledTask.Stop
methods in C#.Net? Which are the frameworks available for such unit tests and which are the best practices for unit testing threading (or task parallelism)?