Unit Testing with Silverlight/CSLA

Unit Testing with Silverlight/CSLA

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


smims posted on Thursday, April 09, 2009

I'm trying to setup a TestMethod (via Visual Studio Unit Testing) to test operations in my CSLA business objects. I seem to be having problems trying to call my CRUD operations .. i.e. DataPortal_Update(), etc... I understand I don't have access to a CslaDataProvider outside XAML so I'm not sure how I intiate any type of save?

Please advise.

Thanks,
SMIMS

RockfordLhotka replied on Thursday, April 09, 2009

There are a couple things to remember.

First, the CslaDataProvider is just calling the factory method on your business class. A unit test should probably be calling the factory method directly, not worrying so much about testing UI elements.

Second, and more importantly, all server interactions in Silverlight are asynchronous. This means that any tests that trigger server interaction must be written to handle async behaviors.

I don't know if the VS unit test framework handles this async issue or not. I believe it does though, so you'll have to research that.

When building the tests for CSLA itself, we wrote our own unit test framework and also a helper DLL for nunit on the .NET side. This was because we wanted to have the exact same test code run on the Silverlight and .NET sides to ensure parity between CSLA .NET for Windows and CSLA .NET for Silverlight. Our test framework handles async operations in a specific way, so it is compatible with running those same tests in nunit.

Copyright (c) Marimer LLC