Skip to content

Commit

Permalink
Create the base for our tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flagbug committed Jan 18, 2014
1 parent db24224 commit 2953647
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 0 deletions.
9 changes: 9 additions & 0 deletions MahApps.Metro.sln
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions 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();
}
}
}
115 changes: 115 additions & 0 deletions Mahapps.Metro.Tests/Mahapps.Metro.Tests.csproj
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{4B381135-F480-478E-9635-B76A425670B7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mahapps.Metro.Tests</RootNamespace>
<AssemblyName>Mahapps.Metro.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>True</IsCodedUITest>
<TestProjectType>CodedUITest</TestProjectType>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Threading.Tasks">
<HintPath>..\packages\Microsoft.Bcl.1.0.19\lib\net40\System.Threading.Tasks.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
<Reference Include="xunit">
<HintPath>..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<Compile Include="AutomationTestBase.cs" />
<Compile Include="MetroWindowTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SwitchContextToUiThreadAwaiter.cs" />
<Compile Include="TestHost.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MahApps.Metro\MahApps.Metro.csproj">
<Project>{5b1710d2-5dc8-4754-91b2-19165de49b3d}</Project>
<Name>MahApps.Metro</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' Or '$(VisualStudioVersion)' == '11.0') And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="UIAutomationTypes" />
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
18 changes: 18 additions & 0 deletions 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();
}
}
}
35 changes: 35 additions & 0 deletions 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")]
30 changes: 30 additions & 0 deletions 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() { }
}
}
40 changes: 40 additions & 0 deletions 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();
}
}
}
4 changes: 4 additions & 0 deletions Mahapps.Metro.Tests/packages.config
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="1.9.2" targetFramework="net40" />
</packages>

0 comments on commit 2953647

Please sign in to comment.