Webcontext not available

Sep 8, 2010 at 5:57 PM

Hi there,

When I run my silverlight unit tests on visual studio 2010, all passes. However, when I run them using statlight an exception is thrown saying " the current instance of webcontext is not available.You must instantiate a webcontext and add it to Application.Applicationlifetimeobjects within the default app constructor." I have already a webcontext  instantiated and added to app lifetime objects within my silverlight unit test project.

Any idea why this happens?

Cheers

Onder

 

Coordinator
Sep 8, 2010 at 8:40 PM

I'm totally guessing here (based on your small description and error message) but if you're trying to run full integration testing (where your silverlight tests talk back to a remote web service (RIA Services?) Unless you are running a specific web server to host RIA services, and you configure your test xap to talk to it - you're stuck (without making changes on your side to support this).

Your test application (when run under StatLight) is running in the context of the StatLight host silverlight application. "Home base" in this case is the StatLight web server, which only exposes StatLight specific web methods. So if you have something trying to talk back to "HomeBase" the location it came from - you will run into issues.

I did, however recently make a change to demonstrate how you could possibly run StatLight with a remote web service call. If you look at the following integration test in the StatLight source http://github.com/staxmanade/StatLight/blob/master/default.ps1#L687 This demonstrates spinning up a CassiniDev instance to host the remote web service. Start StatLight with the port of that instance. And stopping cassiniDev when the test is complete.

You can then look at the following to find out how to call the remote service (based on the given querystring metadata passed in from statlight) http://github.com/staxmanade/StatLight/blob/master/src/StatLight.RemoteIntegration/StatLight.ExternalWebTest/Tests.cs#L46

You can't get this functionality in the v1.1 version. Go download the v1.2 version (which is still in the "Planning" stage) on codeplex).

When I get around to it - I will try to post a wiki article in the documentation area of this project site explaining in detail these steps. 

Hope this helps.

Sep 10, 2010 at 11:32 AM

Hi,

Thanks for the response. 

I am not running full integration tests. Basically, I try to test my viewmodel mocking model. So, Silverlight test app does not talk back to RIA Services. However, I use PRISM framework and the eventaggregator publish an event and subscribe to it within different assemblies. Would that have any affect on the issue???    

Cheers

Onder

Coordinator
Sep 10, 2010 at 2:54 PM

After reading this post http://connect.microsoft.com/VisualStudio/feedback/details/574316/webcontext-not-available - Is there some code in your test App code that runs and sets up some special code?

StatLight's App.cs is the only App code executed. http://github.com/staxmanade/StatLight/blob/master/src/StatLight.Client.Harness/App.xaml.cs

If you have any special setup code - you need to move it out somewhere else and possibly call it on a test setup method.

Hope this helps.

Oct 3, 2010 at 12:04 AM

Staxmanade - I see you are using CassiniDev console with statlight. How is that working out?

Coordinator
Oct 3, 2010 at 12:58 AM

Hello Sky,

Moved the discussion over to - 

http://statlight.codeplex.com/Thread/View.aspx?ThreadId=229425