I’m new when it comes to using VS2010’s unit tests. I tried making a unit test that makes a call to the WCF hosted. The code looks like this:
...
[TestMethod]
public void TestMethod1()
{
WcfClient client = new WcfClient("BasicHttpBinding_IWcf");
client.GetDataCompleted += new EventHandler<GetDataCompletedEventArgs>(OnGetDataCompleted);
client.GetDataAsync(arg1, arg2);
}
void OnGetDataCompleted(object sender, GetDataCompletedEventArgs e)
{
Assert.IfNull(e.Error);
}
...
It seems like it’s never started or completed when I run it. I was thinking of adding this to a load test. Am I missing anything to test async calls to the WCF? I’ve heard of WCF Load Test in codeplex but I’ll leave that for another time.
a variation to peer’s answer: http://justgeeks.blogspot.com/2010/05/unit-testing-asynchronous-calls-in.html
The following code will test you async method, you have to wait in you main thead and do the asserts there: