From 295364770f6fddbc47cf6829144e52125cf0cf85 Mon Sep 17 00:00:00 2001 From: Dennis Daume Date: Sat, 18 Jan 2014 16:46:53 +0100 Subject: [PATCH] Create the base for our tests --- MahApps.Metro.sln | 9 ++ Mahapps.Metro.Tests/AutomationTestBase.cs | 17 +++ .../Mahapps.Metro.Tests.csproj | 115 ++++++++++++++++++ Mahapps.Metro.Tests/MetroWindowTest.cs | 18 +++ .../Properties/AssemblyInfo.cs | 35 ++++++ .../SwitchContextToUiThreadAwaiter.cs | 30 +++++ Mahapps.Metro.Tests/TestHost.cs | 40 ++++++ Mahapps.Metro.Tests/packages.config | 4 + 8 files changed, 268 insertions(+) create mode 100644 Mahapps.Metro.Tests/AutomationTestBase.cs create mode 100644 Mahapps.Metro.Tests/Mahapps.Metro.Tests.csproj create mode 100644 Mahapps.Metro.Tests/MetroWindowTest.cs create mode 100644 Mahapps.Metro.Tests/Properties/AssemblyInfo.cs create mode 100644 Mahapps.Metro.Tests/SwitchContextToUiThreadAwaiter.cs create mode 100644 Mahapps.Metro.Tests/TestHost.cs create mode 100644 Mahapps.Metro.Tests/packages.config diff --git a/MahApps.Metro.sln b/MahApps.Metro.sln index 195ffb039f..c841f9c835 100644 --- a/MahApps.Metro.sln +++ b/MahApps.Metro.sln @@ -33,6 +33,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{4166BE .nuget\NuGet.targets = .nuget\NuGet.targets EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mahapps.Metro.Tests", "Mahapps.Metro.Tests\Mahapps.Metro.Tests.csproj", "{4B381135-F480-478E-9635-B76A425670B7}" + ProjectSection(ProjectDependencies) = postProject + {5B1710D2-5DC8-4754-91B2-19165DE49B3D} = {5B1710D2-5DC8-4754-91B2-19165DE49B3D} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -70,6 +75,10 @@ Global {6107F8A7-28DB-45D9-B822-0BB8C1AE2095}.Debug|Any CPU.Build.0 = Debug|Any CPU {6107F8A7-28DB-45D9-B822-0BB8C1AE2095}.Release|Any CPU.ActiveCfg = Release|Any CPU {6107F8A7-28DB-45D9-B822-0BB8C1AE2095}.Release|Any CPU.Build.0 = Release|Any CPU + {4B381135-F480-478E-9635-B76A425670B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4B381135-F480-478E-9635-B76A425670B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4B381135-F480-478E-9635-B76A425670B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4B381135-F480-478E-9635-B76A425670B7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Mahapps.Metro.Tests/AutomationTestBase.cs b/Mahapps.Metro.Tests/AutomationTestBase.cs new file mode 100644 index 0000000000..7c5b9a80e1 --- /dev/null +++ b/Mahapps.Metro.Tests/AutomationTestBase.cs @@ -0,0 +1,17 @@ +using System; + +namespace Mahapps.Metro.Tests +{ + public class AutomationTestBase : IDisposable + { + public AutomationTestBase() + { + TestHost.Start(); + } + + public void Dispose() + { + TestHost.Shutdown(); + } + } +} diff --git a/Mahapps.Metro.Tests/Mahapps.Metro.Tests.csproj b/Mahapps.Metro.Tests/Mahapps.Metro.Tests.csproj new file mode 100644 index 0000000000..38e9e770e0 --- /dev/null +++ b/Mahapps.Metro.Tests/Mahapps.Metro.Tests.csproj @@ -0,0 +1,115 @@ + + + + Debug + AnyCPU + + + 2.0 + {4B381135-F480-478E-9635-B76A425670B7} + Library + Properties + Mahapps.Metro.Tests + Mahapps.Metro.Tests + v4.0 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + True + CodedUITest + ..\ + true + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + ..\packages\Microsoft.Bcl.1.0.19\lib\net40\System.Threading.Tasks.dll + + + + + + ..\packages\xunit.1.9.2\lib\net20\xunit.dll + + + + + False + + + + + + + + + + + + + + + {5b1710d2-5dc8-4754-91b2-19165de49b3d} + MahApps.Metro + + + + + + + False + + + False + + + False + + + False + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Mahapps.Metro.Tests/MetroWindowTest.cs b/Mahapps.Metro.Tests/MetroWindowTest.cs new file mode 100644 index 0000000000..8a101456f1 --- /dev/null +++ b/Mahapps.Metro.Tests/MetroWindowTest.cs @@ -0,0 +1,18 @@ +using System.Threading.Tasks; +using System.Windows; +using MahApps.Metro.Controls; +using Xunit; + +namespace Mahapps.Metro.Tests +{ + public class MetroWindowTest : AutomationTestBase + { + [Fact] + public async Task MetroWindowSmokeTest() + { + await TestHost.SwitchToAppThread(); + + Window window = new MetroWindow(); + } + } +} diff --git a/Mahapps.Metro.Tests/Properties/AssemblyInfo.cs b/Mahapps.Metro.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..003c43e97f --- /dev/null +++ b/Mahapps.Metro.Tests/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("Mahapps.Metro.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Mahapps.Metro.Tests")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[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("93c48128-aa54-4aaa-82f3-dc272300c909")] + +// 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 Build and Revision Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Mahapps.Metro.Tests/SwitchContextToUiThreadAwaiter.cs b/Mahapps.Metro.Tests/SwitchContextToUiThreadAwaiter.cs new file mode 100644 index 0000000000..be3d0dcac5 --- /dev/null +++ b/Mahapps.Metro.Tests/SwitchContextToUiThreadAwaiter.cs @@ -0,0 +1,30 @@ +using System; +using System.Runtime.CompilerServices; +using System.Windows.Threading; + +namespace Mahapps.Metro.Tests +{ + public class SwitchContextToUiThreadAwaiter : INotifyCompletion + { + private readonly Dispatcher uiContext; + + public SwitchContextToUiThreadAwaiter(Dispatcher uiContext) + { + this.uiContext = uiContext; + } + + public SwitchContextToUiThreadAwaiter GetAwaiter() + { + return this; + } + + public bool IsCompleted { get { return false; } } + + public void OnCompleted(Action continuation) + { + this.uiContext.Invoke(new Action(continuation)); + } + + public void GetResult() { } + } +} diff --git a/Mahapps.Metro.Tests/TestHost.cs b/Mahapps.Metro.Tests/TestHost.cs new file mode 100644 index 0000000000..63161dfce7 --- /dev/null +++ b/Mahapps.Metro.Tests/TestHost.cs @@ -0,0 +1,40 @@ +using System.Threading; +using System.Windows; +using System.Windows.Threading; + +namespace Mahapps.Metro.Tests +{ + public static class TestHost + { + private static Application app; + private static Thread appThread; + private static AutoResetEvent gate = new AutoResetEvent(false); + + public static void Start() + { + appThread = new Thread(StartDispatcher); + appThread.SetApartmentState(ApartmentState.STA); + appThread.Start(); + + gate.WaitOne(); + } + + public static void StartDispatcher() + { + app = new Application { ShutdownMode = ShutdownMode.OnExplicitShutdown }; + app.Startup += (sender, args) => gate.Set(); + app.Run(); + } + + public static SwitchContextToUiThreadAwaiter SwitchToAppThread() + { + return new SwitchContextToUiThreadAwaiter(app.Dispatcher); + } + + public static void Shutdown() + { + app.Dispatcher.BeginInvokeShutdown(DispatcherPriority.Send); + appThread.Join(); + } + } +} diff --git a/Mahapps.Metro.Tests/packages.config b/Mahapps.Metro.Tests/packages.config new file mode 100644 index 0000000000..c35572b60e --- /dev/null +++ b/Mahapps.Metro.Tests/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file