I have a C # method that will be called multiple times using different threads. So I want to create a unit test that will test this method on multiple threads, but I'm not sure if I am doing this correctly.
This is my unit test without streaming:
[TestMethod]
public void FromLocalPoints()
{
var projectedCoordinates = this.ConvertFromLocalPoints();
foreach (var projectedCoordinate in projectedCoordinates)
{
Debug.Write(projectedCoordinate.X);
Debug.Write("; ");
Debug.WriteLine(projectedCoordinate.Y);
}
}
this.ConvertFromLocalPoints () calls the actual method I want to test.
I created a delegate, event, and handler:
public delegate void ReprojectCompleteHandler(IEnumerable<Coordinate> projectedCoordinates);
public event ReprojectCompleteHandler ReprojectCompleteEvent;
private void ReprojectHandler(IEnumerable<Coordinate> projectedCoordinates)
{
Debug.WriteLine("Conversion is complete");
}
In my TestSetup, I listen to my event:
[TestInitialize]
public void TestSetup()
{
this.ReprojectCompleteEvent += this.ReprojectHandler;
}
My unit test:
[TestMethod]
public void FromLocalPointsThreaded()
{
for (var i = 0; i < 10; i++)
{
var myThread = new Thread(this.ConvertFromLocalPointsThreaded);
}
Debug.WriteLine("FromLocalPointsThreaded is done");
}
private void ConvertFromLocalPointsThreaded()
{
var projectedCoordinates = this.ConvertFromLocalPoints();
if (this.ReprojectCompleteEvent != null)
{
this.ReprojectCompleteEvent(projectedCoordinates);
}
}
When I run this unit test, I get "FromLocalPointsThreaded is done" once in my output, but "Conversion is not completed."
What am I missing to get this to work? Or should I use a different approach?
, . , . , . unit test, , .