Unit testing async factory methods

Unit testing async factory methods

Old forum URL: forums.lhotka.net/forums/t/8645.aspx

triplea posted on Thursday, March 11, 2010

What is the best way/practice/pattern of writing unit tests when the async factories are used? E.g. lets say I have a test for my Customer object and for simplicity sake I want to assert that:

GetCustomer(int id, EventHandler<DataPortalResult<Customer>> handler)

returns a customer with name "X". How do I make sure my test waits for the factory method to complete before asserting and of course exiting the test?

skagen00 replied on Thursday, March 11, 2010

Have you looked at the Silverlight Unit Testing framework?

If you go here:


Session CL32

CL32 - Developing Testable Silverlight Applications (Keith Jones)

This one talked a little bit about how actions are "queued" up to where certain asynch operations / etc can have a condition that is waited on. I confess I haven't used the unit test framework, but I thought I'd mention it.


tmg4340 replied on Thursday, March 11, 2010

You might also check this thread:


The main thrust is that Rocky/Magenic ended up solving this problem by creating UnitDriven, their own testing framework.  It might prove useful for what you're doing.


- Scott

triplea replied on Thursday, March 11, 2010

Thanks to both, I will check the links and get back to mark an answer.

One thing I did forget to mention is that I am not actually doing any SL development aty the moment so not using CSLA Light . I have a WPF client and am using standard CSLA.

RockfordLhotka replied on Thursday, March 11, 2010

UnitDriven works in nunit and mstest as well.

That was half the point actually. We needed three things:

UnitDriven on the SL side is a complete (if relatively simple) unit test framework that meets those needs.

UnitDriven on the .NET side is an "add-in" to nunit or mstest that enables async tests to be written in exactly the same way we write them on the SL side - so the same tests can be used for both platforms.

triplea replied on Friday, March 12, 2010

Thanks for the clarification. I didn't even look at UnitDriven because I thought it was only addressing SL issues around unit testing but all is clear now.


Copyright (c) Marimer LLC