Created
March 27, 2009 07:21
-
-
Save jschementi/86587 to your computer and use it in GitHub Desktop.
Add this to your Silverlight app to run tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add the following to your usings. | |
using System.Reflection; | |
using System.Windows.Browser; | |
using System.Windows.Resources; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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