Skip to content

Instantly share code, notes, and snippets.

@jschementi
Created March 27, 2009 07:21
Show Gist options
  • Save jschementi/86587 to your computer and use it in GitHub Desktop.
Save jschementi/86587 to your computer and use it in GitHub Desktop.
Add this to your Silverlight app to run tests
// Add the following to your App.xaml.cs's
// Application_Startup method.
var queryString = HtmlPage.Document.QueryString;
if (queryString.ContainsKey("test")) {
var xap = new Uri(
"eggs.xap", UriKind.Relative
);
WebClient wcXap = new WebClient();
wcXap.OpenReadCompleted +=
new OpenReadCompletedEventHandler(
wcXap_OnOpenReadCompleted
);
wcXap.OpenReadAsync(xap);
}
// Add the following to your usings.
using System.Reflection;
using System.Windows.Browser;
using System.Windows.Resources;
// Add this method to your App class. It is
// called when eggs.xap is downloaded. It
// defines where the tests are, and starts
// running them.
private void
wcXap_OnOpenReadCompleted
(object sender, OpenReadCompletedEventArgs e) {
if ((e.Error == null) &&
(e.Cancelled == false)){
var xap =
new StreamResourceInfo(e.Result, null);
Assembly asm = new AssemblyPart().Load(
Application.GetResourceStream(
xap, new Uri(
"Eggs.dll", UriKind.Relative
)
).Stream
);
asm.GetType("Eggs")
.GetMethod("Start")
.Invoke(null, new object[] {
(object) new Uri(
"http://localhost:35863/Sample.Tests.xap"
),
(object) xap
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment