I am writing a class that I know that needs a lock, because the class must be thread safe. But as I am Test-Driven-Developing I know that I can't write a line of code before creating a test for it. And I find very difficult to do since the tests will get very complex in the end. What do you usually do in those cases? There is any tool to help with that?
This question is .NET specific
Someone asked for the code:
public class StackQueue
{
private Stack<WebRequestInfo> stack = new Stack<WebRequestInfo>();
private Queue<WebRequestInfo> queue = new Queue<WebRequestInfo>();
public int Count
{
get
{
return this.queue.Count + this.stack.Count;
}
}
public void Enqueue(WebRequestInfo requestInfo)
{
this.queue.Enqueue(requestInfo);
}
public void Push(WebRequestInfo requestInfo)
{
this.stack.Push(requestInfo);
}
private WebRequestInfo Next()
{
if (stack.Count > 0)
{
return stack.Pop();
}
else if (queue.Count > 0)
{
return queue.Dequeue();
}
return null;
}
}