CSLA .NET

From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books

Unit testing async factory methods

rated by 0 users
Answered (Verified) This post has 3 verified answers | 5 Replies | 2 Followers

Top 25 Contributor
232 Posts
triplea posted on Thu, Mar 11 2010 4:49 AM

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?

Answered (Verified) Verified Answer

Top 10 Contributor
518 Posts
Verified by triplea

Have you looked at the Silverlight Unit Testing framework?

If you go here:

http://feeds.timheuer.com/timheuer/pdc/silverlight/wmv

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.

 

Top 25 Contributor
306 Posts
Verified by triplea

You might also check this thread:

http://forums.lhotka.net/forums/t/8620.aspx

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.

HTH

- Scott

Top 10 Contributor
7,107 Posts
Verified by triplea

UnitDriven works in nunit and mstest as well.

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

  • a unit test framework that worked in SL (because nothing existed when we started)
  • a unit test framework that handled async operations
  • a unit test framework that allowed the exact same test code to run on SL and .NET

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.

Rocky

All Replies

Top 10 Contributor
518 Posts
Verified by triplea

Have you looked at the Silverlight Unit Testing framework?

If you go here:

http://feeds.timheuer.com/timheuer/pdc/silverlight/wmv

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.

 

Top 25 Contributor
306 Posts
Verified by triplea

You might also check this thread:

http://forums.lhotka.net/forums/t/8620.aspx

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.

HTH

- Scott

Top 25 Contributor
232 Posts
triplea replied on Thu, Mar 11 2010 10:40 AM

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.

Top 10 Contributor
7,107 Posts
Verified by triplea

UnitDriven works in nunit and mstest as well.

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

  • a unit test framework that worked in SL (because nothing existed when we started)
  • a unit test framework that handled async operations
  • a unit test framework that allowed the exact same test code to run on SL and .NET

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.

Rocky

Top 25 Contributor
232 Posts

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.

Thanks!

Page 1 of 1 (6 items) | RSS

Please contact Magenic for your .NET consulting
and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems