Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling Async With Specflow for Silverlight

The Silverlight Unit test Framework defines a process for dealing with Async calls (derive test class from Microsoft.Silverlight.Testing.SilverlightTest, add Asynchronous attribute, use EnqueueXXX methods.) Considering the separation that SpecFlow presents between the test class and the steps:

  • Can these tools be brought to bear to wait on Silverlight method calls within the test that behave asynchronously (such as making web service calls)?
  • If they cannot, what is the guidance for handling this behavior in SpecFlow test files? (Perhaps use an AutoResetEvent that gets tripped in an event handler and wait on it?)
like image 607
John Garland Avatar asked Aug 02 '10 03:08

John Garland


2 Answers

Using an AutoResetEvent won't work because the WaitOne call will block the UI thread. Silverlight makes use of the UI thread even when making async calls to a data services (see this post - Thead is blocked using WebClient and ManualResetEvent) so the WaitOne will actually stop the service from being called.

like image 148
David Fevre Avatar answered Oct 21 '22 21:10

David Fevre


I know this is probably to late but here goes.

For silverlight async calls you can use the Specflow AsyncContext api

https://github.com/techtalk/SpecFlow/wiki/Testing-Silverlight-Asynchronous-Code

I blogged about this when it was being developed here

http://rburnham.wordpress.com/2011/05/13/testing-silverlight-asynchronous-code-with-specflow/

It helps to explain the concept.

like image 45
Ryan Burnham Avatar answered Oct 21 '22 20:10

Ryan Burnham