CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Unit Testing in Silverlight

rated by 0 users
Answered (Not Verified) This post has 0 verified answers | 1 Reply | 2 Followers

Not Ranked
1 Posts
Peabody posted on Mon, May 21 2012 2:07 PM

I am trying to test a viewmodel in my silverlight project.  The problem I am running into is that I cannot make any calls to the business layer until I have authenticated the user identity.  My plan was to authenticate in the test class initialization using AutoResetEvent to wait until authentication had happened before continuing with the unit tests like the following:

 

        [ClassInitialize]

        public void InitializeClass()

        {

            AutoResetEvent finishedEvent = new AutoResetEvent(false);

            Security.SLPrincipal.Login("testuser", "testpassword", (o, e) =>

            {

               finishedEvent.Set();

            });

            finishedEvent.WaitOne();

        }

 

In this code the loging method calls the async dataportal BeginFetch method.  The problem is that as soon as the code hits finishedEvent.WaitOne() the application freezes and never unfreezes.  I also set breakpoints in the server side code and confirmed that they are never being hit.  It is as if the client side is never getting off the call to the server before the WaitOne method is called.   I must have some fundamental misunderstanding of either the AutoResetEvent object or how exactly the async BeginFetch method works.   Can anybody clarify what I am doing wrong in this scenario?

 

All Replies

Top 10 Contributor
9,270 Posts

You really can't use that type of synchronization primitive in Silverlight, because a lot of things marshal back to the UI thread and you end up blocking yourself.

This is why we wrote and use UnitDriven (www.codeplex.com/unitdriven) for the CSLA unit tests - it provides a way to manage async test code that is the same on .NET and Silverlight.

Rocky

Page 1 of 1 (2 items) | RSS

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