From 52a1e54792fdac1d3b462b639a7e5a1b37f7613d Mon Sep 17 00:00:00 2001 From: Jason Jarrett Date: Fri, 7 May 2010 23:07:13 -0700 Subject: [PATCH] Fixed Issue #10792. Created an Out Of Browser enabled integration test project. Fixed some poor XML parsing of the AppManifest.xaml (there's prob better way to parse it than this fix - but it seems to work) --- TODO.txt | 6 +- src/StatLight.Client.Harness/LoadedXapData.cs | 8 +- .../App.xaml | 8 ++ .../App.xaml.cs | 60 ++++++++++ .../Properties/AppManifest.xml | 6 + .../Properties/AssemblyInfo.cs | 35 ++++++ .../Properties/OutOfBrowserSettings.xml | 7 ++ ...Light.IntegrationTests.OutOfBrowser.csproj | 111 ++++++++++++++++++ .../Tests.cs | 14 +++ src/StatLight.sln | 9 ++ 10 files changed, 261 insertions(+), 3 deletions(-) create mode 100644 src/StatLight.IntegrationTests.OutOfBrowser/App.xaml create mode 100644 src/StatLight.IntegrationTests.OutOfBrowser/App.xaml.cs create mode 100644 src/StatLight.IntegrationTests.OutOfBrowser/Properties/AppManifest.xml create mode 100644 src/StatLight.IntegrationTests.OutOfBrowser/Properties/AssemblyInfo.cs create mode 100644 src/StatLight.IntegrationTests.OutOfBrowser/Properties/OutOfBrowserSettings.xml create mode 100644 src/StatLight.IntegrationTests.OutOfBrowser/StatLight.IntegrationTests.OutOfBrowser.csproj create mode 100644 src/StatLight.IntegrationTests.OutOfBrowser/Tests.cs diff --git a/TODO.txt b/TODO.txt index 31548a3..7e8d813 100644 --- a/TODO.txt +++ b/TODO.txt @@ -7,4 +7,8 @@ look into replacing Default testing framework version - also the string file nam wrap real unit tests around the XapReader -cleanup logger passed into XapReader \ No newline at end of file +cleanup logger passed into XapReader + + +OOB notes: +http://debuggingblog.com/wp/2009/07/17/silverlight-3-outofbrowseroob-explained-and-how-to-host-any-xap-package-by-modifying-the-metadata/ \ No newline at end of file diff --git a/src/StatLight.Client.Harness/LoadedXapData.cs b/src/StatLight.Client.Harness/LoadedXapData.cs index fb0c902..9c9a69d 100644 --- a/src/StatLight.Client.Harness/LoadedXapData.cs +++ b/src/StatLight.Client.Harness/LoadedXapData.cs @@ -43,7 +43,11 @@ public LoadedXapData(Stream xapStream) if (root != null) { string entryPoint = root.Attribute("EntryPointAssembly").Value; - var partsElement = root.FirstNode as XElement; + + //TODO: There has to be a better way to get the Deployment.Parts out of the xml than this... + var partsElement = root.Elements() + .Where(w => w.Name.LocalName.Equals("Deployment.Parts", StringComparison.OrdinalIgnoreCase)) + .SingleOrDefault(); if (partsElement != null) { @@ -82,7 +86,7 @@ public LoadedXapData(Stream xapStream) } } else - throw new InvalidOperationException("The application manifest did not contain any assembly part xml nodes."); + throw new InvalidOperationException("The application manifest does not contain a Deployment.Parts xml element."); if (_testAssemblies.Count == 0) throw new InvalidOperationException("Could not find the entry poing assembly [{0}].".FormatWith(entryPoint)); diff --git a/src/StatLight.IntegrationTests.OutOfBrowser/App.xaml b/src/StatLight.IntegrationTests.OutOfBrowser/App.xaml new file mode 100644 index 0000000..ba8a688 --- /dev/null +++ b/src/StatLight.IntegrationTests.OutOfBrowser/App.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/src/StatLight.IntegrationTests.OutOfBrowser/App.xaml.cs b/src/StatLight.IntegrationTests.OutOfBrowser/App.xaml.cs new file mode 100644 index 0000000..7f3159e --- /dev/null +++ b/src/StatLight.IntegrationTests.OutOfBrowser/App.xaml.cs @@ -0,0 +1,60 @@ +using System; +using System.Windows; +using Microsoft.Silverlight.Testing; + +namespace StatLight.IntegrationTests.OutOfBrowser +{ + public partial class App : Application + { + + public App() + { + this.Startup += this.Application_Startup; + this.Exit += this.Application_Exit; + this.UnhandledException += this.Application_UnhandledException; + + InitializeComponent(); + } + + private void Application_Startup(object sender, StartupEventArgs e) + { + this.RootVisual = UnitTestSystem.CreateTestPage(); + } + + private void Application_Exit(object sender, EventArgs e) + { + + } + + private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) + { + // If the app is running outside of the debugger then report the exception using + // the browser's exception mechanism. On IE this will display it a yellow alert + // icon in the status bar and Firefox will display a script error. + if (!System.Diagnostics.Debugger.IsAttached) + { + + // NOTE: This will allow the application to continue running after an exception has been thrown + // but not handled. + // For production applications this error handling should be replaced with something that will + // report the error to the website and stop the application. + e.Handled = true; + Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); + } + } + + private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) + { + try + { + string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; + errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); + + System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");"); + } + catch (Exception) + { + } + } + } +} diff --git a/src/StatLight.IntegrationTests.OutOfBrowser/Properties/AppManifest.xml b/src/StatLight.IntegrationTests.OutOfBrowser/Properties/AppManifest.xml new file mode 100644 index 0000000..a955232 --- /dev/null +++ b/src/StatLight.IntegrationTests.OutOfBrowser/Properties/AppManifest.xml @@ -0,0 +1,6 @@ + + + + diff --git a/src/StatLight.IntegrationTests.OutOfBrowser/Properties/AssemblyInfo.cs b/src/StatLight.IntegrationTests.OutOfBrowser/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..bd5bb9d --- /dev/null +++ b/src/StatLight.IntegrationTests.OutOfBrowser/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("StatLight.IntegrationTests.OutOfBrowser")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("StatLight.IntegrationTests.OutOfBrowser")] +[assembly: AssemblyCopyright("Copyright © 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("08c5d1b0-afd1-4025-b5bb-ec86610a6d38")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/StatLight.IntegrationTests.OutOfBrowser/Properties/OutOfBrowserSettings.xml b/src/StatLight.IntegrationTests.OutOfBrowser/Properties/OutOfBrowserSettings.xml new file mode 100644 index 0000000..0e583fa --- /dev/null +++ b/src/StatLight.IntegrationTests.OutOfBrowser/Properties/OutOfBrowserSettings.xml @@ -0,0 +1,7 @@ + + StatLight.IntegrationTests.OutOfBrowser Application on your desktop; at home, at work or on the go. + + + + + \ No newline at end of file diff --git a/src/StatLight.IntegrationTests.OutOfBrowser/StatLight.IntegrationTests.OutOfBrowser.csproj b/src/StatLight.IntegrationTests.OutOfBrowser/StatLight.IntegrationTests.OutOfBrowser.csproj new file mode 100644 index 0000000..a2664d3 --- /dev/null +++ b/src/StatLight.IntegrationTests.OutOfBrowser/StatLight.IntegrationTests.OutOfBrowser.csproj @@ -0,0 +1,111 @@ + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {CB2B6883-2461-4115-848C-DA79D20A3E0A} + {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + StatLight.IntegrationTests.OutOfBrowser + StatLight.IntegrationTests.OutOfBrowser + Silverlight + v4.0 + $(TargetFrameworkVersion) + true + + + true + true + StatLight.IntegrationTests.OutOfBrowser.xap + Properties\AppManifest.xml + StatLight.IntegrationTests.OutOfBrowser.App + StatLight.IntegrationTests.OutOfBrowserTestPage.html + true + true + true + Properties\OutOfBrowserSettings.xml + false + true + + + + + + v3.5 + + + true + full + false + Bin\Debug + DEBUG;TRACE;SILVERLIGHT + true + true + prompt + 4 + + + pdbonly + true + Bin\Release + TRACE;SILVERLIGHT + true + true + prompt + 4 + + + + ..\..\lib\Silverlight\Microsoft\April2010\Microsoft.Silverlight.Testing.dll + + + ..\..\lib\Silverlight\Microsoft\April2010\Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll + + + + + + + + + + + + App.xaml + + + + + + + Designer + MSBuild:Compile + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/StatLight.IntegrationTests.OutOfBrowser/Tests.cs b/src/StatLight.IntegrationTests.OutOfBrowser/Tests.cs new file mode 100644 index 0000000..f632d45 --- /dev/null +++ b/src/StatLight.IntegrationTests.OutOfBrowser/Tests.cs @@ -0,0 +1,14 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace StatLight.IntegrationTests.OutOfBrowser +{ + [TestClass] + public class Tests + { + [TestMethod] + public void Should_Run_this_passing_test() + { + + } + } +} \ No newline at end of file diff --git a/src/StatLight.sln b/src/StatLight.sln index d9efdb7..8644235 100644 --- a/src/StatLight.sln +++ b/src/StatLight.sln @@ -49,6 +49,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StatLight.Client.Harness.Un EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StatLight.IntegrationTests.Silverlight.LotsOfTests", "StatLight.IntegrationTests.Silverlight.LotsOfTests\StatLight.IntegrationTests.Silverlight.LotsOfTests.csproj", "{6454A8DE-C1E8-4A34-86B0-89E364861BAC}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StatLight.IntegrationTests.OutOfBrowser", "StatLight.IntegrationTests.OutOfBrowser\StatLight.IntegrationTests.OutOfBrowser.csproj", "{CB2B6883-2461-4115-848C-DA79D20A3E0A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -193,6 +195,12 @@ Global {6454A8DE-C1E8-4A34-86B0-89E364861BAC}.Release|Any CPU.Build.0 = Release|Any CPU {6454A8DE-C1E8-4A34-86B0-89E364861BAC}.Release|x86.ActiveCfg = Release|Any CPU {6454A8DE-C1E8-4A34-86B0-89E364861BAC}.Release|x86.Build.0 = Release|Any CPU + {CB2B6883-2461-4115-848C-DA79D20A3E0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CB2B6883-2461-4115-848C-DA79D20A3E0A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CB2B6883-2461-4115-848C-DA79D20A3E0A}.Debug|x86.ActiveCfg = Debug|Any CPU + {CB2B6883-2461-4115-848C-DA79D20A3E0A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CB2B6883-2461-4115-848C-DA79D20A3E0A}.Release|Any CPU.Build.0 = Release|Any CPU + {CB2B6883-2461-4115-848C-DA79D20A3E0A}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -208,5 +216,6 @@ Global {6DC93A95-7B8E-4D2E-BFB7-E2D3BCE089C8} = {CBFFC0A9-9D77-443F-84FB-831A1C368EA0} {E99066B4-F2FC-469D-B427-CA1793BB0B23} = {CBFFC0A9-9D77-443F-84FB-831A1C368EA0} {6454A8DE-C1E8-4A34-86B0-89E364861BAC} = {CBFFC0A9-9D77-443F-84FB-831A1C368EA0} + {CB2B6883-2461-4115-848C-DA79D20A3E0A} = {CBFFC0A9-9D77-443F-84FB-831A1C368EA0} EndGlobalSection EndGlobal