Skip to content

Commit

Permalink
Adding groundwork for UnitTests
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Oct 30, 2016
1 parent bd24ac1 commit 881c6f9
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Fluent.Ribbon.Tests/Controls/BackstageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Fluent.Tests.Controls
{
using Fluent.Tests.Helper;
using Fluent.Tests.TestClasses;
using NUnit.Framework;

[TestFixture]
public class BackstageTests
{
/// <summary>
/// This test ensures that the <see cref="BackstageAdorner"/> is destroyed as soon as the <see cref="Backstage"/> is unloaded.
/// </summary>
[Test]
public void Adorner_should_be_destroyed_on_unload()
{
var backstage = new Backstage
{
Content = new Button()
};

using (var window = new TestRibbonWindow(backstage))
{
Assert.That(backstage.IsLoaded, Is.True);

Assert.That(backstage.GetPrivateFieldValue("adorner"), Is.Null);

backstage.IsOpen = true;

Assert.That(backstage.GetPrivateFieldValue("adorner"), Is.Not.Null);

backstage.IsOpen = false;

Assert.That(backstage.GetPrivateFieldValue("adorner"), Is.Not.Null);

window.Content = null;

UIHelper.DoEvents();

Assert.That(backstage.GetPrivateFieldValue("adorner"), Is.Null);
}
}
}
}
72 changes: 72 additions & 0 deletions Fluent.Ribbon.Tests/Fluent.Ribbon.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{11E74323-57EB-4F25-AB3B-0759B1F978ED}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Fluent.Tests</RootNamespace>
<AssemblyName>Fluent.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\build\bin\NET 4.5\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>..\Fluent.Ribbon.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\build\bin\NET 4.5\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Shared\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Controls\BackstageTests.cs" />
<Compile Include="Helper\ReflectionHelper.cs" />
<Compile Include="Helper\UIHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestClasses\TestRibbonWindow.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fluent.Ribbon\Fluent.Ribbon.NET 4.5.csproj">
<Project>{4C92FCF4-3561-499F-BC5B-F2F089863047}</Project>
<Name>Fluent.Ribbon.NET 4.5</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
19 changes: 19 additions & 0 deletions Fluent.Ribbon.Tests/Helper/ReflectionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace Fluent.Tests.Helper
{
using System.Reflection;

public static class ReflectionHelper
{
public static object GetPrivateFieldValue(this object obj, string fieldName)
{
return GetPrivateFieldInfo(obj.GetType(), fieldName).GetValue(obj);
}

private static FieldInfo GetPrivateFieldInfo(Type type, string fieldName)
{
return type.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
}
}
}
18 changes: 18 additions & 0 deletions Fluent.Ribbon.Tests/Helper/UIHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Fluent.Tests.Helper
{
using System;
using System.Windows.Threading;

public static class UIHelper
{
public static void DoEvents()
{
Dispatcher.CurrentDispatcher.DoEvents();
}

public static void DoEvents(this Dispatcher dispatcher)
{
dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));
}
}
}
8 changes: 8 additions & 0 deletions Fluent.Ribbon.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Reflection;
using System.Threading;
using NUnit.Framework;

[assembly: AssemblyTitle("Fluent.Ribbon.Tests")]
[assembly: AssemblyDescription("")]

[assembly: Apartment(ApartmentState.STA)]
34 changes: 34 additions & 0 deletions Fluent.Ribbon.Tests/TestClasses/TestRibbonWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Fluent.Tests.TestClasses
{
using System;
using System.Diagnostics;

public class TestRibbonWindow : RibbonWindow, IDisposable
{
public TestRibbonWindow()
: this(null)
{
}

public TestRibbonWindow(object content)
{
this.Content = content;

this.ShowActivated = false;
this.ShowInTaskbar = false;

if (Debugger.IsAttached == false)
{
this.Left = int.MinValue;
this.Top = int.MinValue;
}

this.Show();
}

public void Dispose()
{
this.Close();
}
}
}
4 changes: 4 additions & 0 deletions Fluent.Ribbon.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.5.0" targetFramework="net45" />
</packages>
6 changes: 6 additions & 0 deletions Fluent.Ribbon.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ReleaseNotes.md = ReleaseNotes.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fluent.Ribbon.Tests", "Fluent.Ribbon.Tests\Fluent.Ribbon.Tests.csproj", "{11E74323-57EB-4F25-AB3B-0759B1F978ED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -59,6 +61,10 @@ Global
{2A893D50-BBC4-4482-ADAA-D52B517E8632}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A893D50-BBC4-4482-ADAA-D52B517E8632}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A893D50-BBC4-4482-ADAA-D52B517E8632}.Release|Any CPU.Build.0 = Release|Any CPU
{11E74323-57EB-4F25-AB3B-0759B1F978ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{11E74323-57EB-4F25-AB3B-0759B1F978ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{11E74323-57EB-4F25-AB3B-0759B1F978ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{11E74323-57EB-4F25-AB3B-0759B1F978ED}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 881c6f9

Please sign in to comment.