May 2, 2012 at 4:44 PM


First of all, THANKS FOR STATLIGHT!  Great effort that allowed us to have silveright unit test running on our build machine! 

Here's my situation... I've got some unit tests that communicates with a web service.  The web service adress is usually sent to the client through InitParams by the .aspx file.  It's sent though a configuration file as the url changes depending on the build configuration (Local, dev, beta, etc...)

  <param name="InitParams" value="<%=String.Format("WcfProxy={0}", 
				ConfigurationManager.AppSettings["WcfProxy"]) %>" />

Then, in my silverlight unit test project, I use something like that to set the url

  private void Application_Startup(object sender, StartupEventArgs e)
            Params = e.InitParams;
            if (!Params.ContainsKey(ParamsConstants.WcfProxyParam))
                throw new ArgumentNullException(string.Format("InitParams doesn't contain a value for key {0}.", ParamsConstants.WcfProxyParam));

            WcfProxy.DefaultUrl = e.InitParams[ParamsConstants.WcfProxyParam];

Now, I'm aware that StatLight, not only doesn't use our .aspx file to execute tests, but that it also grabs his own app.xaml file. 

Is there any suggestion on how I could achieve such a goal without hardcoding values in my unit tests initialization?

Thanks for your advices!

May 2, 2012 at 6:28 PM

Holy moly - first time seeing the new codeplex Metro design (minor shock).

Thanks for the kind words about StatLight.


Regarding your question.

One option you have is in your build script you can leverage the --QueryString option of Statlight. This will essentially tack whatever you pass in there to the querystring of the browser request made by StatLight's front end.

The documentation here should help you. In the docs there is a link to an integration test where StatLight pulls out of the querystring a 'config' value that was passed in by a build script.

Hope this helps.

May 2, 2012 at 8:18 PM
Edited May 2, 2012 at 8:38 PM

Thanks for the advice.  Unfortunately (or fortunately, depending on your point of view ; ) ), I'm using some generic tests to invoke Statlight.  I find it easier to get some build result and consequently I didn't had to modify my build script...

Unfortunately, variables like $(ConfigurationName) are not available in GenericTests, so no way to specify, as a QueryString argument, which Url to use depending on configuration 

I think I found a solution though and here it is, maybe it could help others...

I was able to achieve my goal by implementing a silverlight app.config Configuration reader.  I felt inspired by this post (  I added multiple app.(ConfigName).config in a specific folder and created a pre-build action that overrides the required app.config file with the appropriate app.(ConfigName).config file. 

copy "$(ProjectDir)Config\app.$(ConfigurationName).config" "$(ProjectDir)app.config" /Y

That way, my app.config file content changes automatically following my build configuration. 

So now, the silverlight configuration is not handle anymore by the InitParams and  I was able to remove the specific logic out of my App.xaml file.

Thanks again for your great contribution to the Silverlight TDD community!