Skip to content

Commit 7c514b6

Browse files
committed
Ensure PaletteHelper is mockable. Fixes #135 This is a good will test - not a functionality test - so that developers using TDD for their view models who want to test calling down to PaletteHelper can do so.
1 parent 159d487 commit 7c514b6

File tree

8 files changed

+233
-15
lines changed

8 files changed

+233
-15
lines changed

MaterialDesignColors.Wpf.Tests/MaterialDesignColors.Wpf.Tests.csproj

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" />
43
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
54
<PropertyGroup>
65
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -51,12 +50,16 @@
5150
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
5251
<Private>True</Private>
5352
</Reference>
54-
<Reference Include="xunit.assert, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
55-
<HintPath>..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll</HintPath>
53+
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
54+
<HintPath>..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
5655
<Private>True</Private>
5756
</Reference>
58-
<Reference Include="xunit.core, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
59-
<HintPath>..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath>
57+
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
58+
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
59+
<Private>True</Private>
60+
</Reference>
61+
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
62+
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
6063
<Private>True</Private>
6164
</Reference>
6265
</ItemGroup>
@@ -78,7 +81,6 @@
7881
<PropertyGroup>
7982
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
8083
</PropertyGroup>
81-
<Error Condition="!Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props'))" />
8284
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
8385
</Target>
8486
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Shouldly" version="2.5.0" targetFramework="net452" />
4-
<package id="xunit" version="2.0.0" targetFramework="net452" />
4+
<package id="xunit" version="2.1.0" targetFramework="net452" />
55
<package id="xunit.abstractions" version="2.0.0" targetFramework="net452" />
6-
<package id="xunit.assert" version="2.0.0" targetFramework="net452" />
7-
<package id="xunit.core" version="2.0.0" targetFramework="net452" />
8-
<package id="xunit.extensibility.core" version="2.0.0" targetFramework="net452" />
6+
<package id="xunit.assert" version="2.1.0" targetFramework="net452" />
7+
<package id="xunit.core" version="2.1.0" targetFramework="net452" />
8+
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net452" />
9+
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net452" />
910
</packages>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{A361C80E-F6CD-4C57-A96C-002DB159C1F4}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>MaterialDesignThemes.Wpf.Tests</RootNamespace>
11+
<AssemblyName>MaterialDesignThemes.Wpf.Tests</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<NuGetPackageImportStamp>
15+
</NuGetPackageImportStamp>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
36+
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
37+
<Private>True</Private>
38+
</Reference>
39+
<Reference Include="NSubstitute, Version=1.9.2.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
40+
<HintPath>..\packages\NSubstitute.1.9.2.0\lib\net45\NSubstitute.dll</HintPath>
41+
<Private>True</Private>
42+
</Reference>
43+
<Reference Include="Rhino.Mocks, Version=3.6.0.0, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
44+
<HintPath>..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll</HintPath>
45+
<Private>True</Private>
46+
</Reference>
47+
<Reference Include="System" />
48+
<Reference Include="System.Core" />
49+
<Reference Include="System.Xml.Linq" />
50+
<Reference Include="System.Data.DataSetExtensions" />
51+
<Reference Include="Microsoft.CSharp" />
52+
<Reference Include="System.Data" />
53+
<Reference Include="System.Net.Http" />
54+
<Reference Include="System.Xml" />
55+
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
56+
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
57+
<Private>True</Private>
58+
</Reference>
59+
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
60+
<HintPath>..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
61+
<Private>True</Private>
62+
</Reference>
63+
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
64+
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
65+
<Private>True</Private>
66+
</Reference>
67+
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
68+
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
69+
<Private>True</Private>
70+
</Reference>
71+
</ItemGroup>
72+
<ItemGroup>
73+
<Compile Include="PaletteHelperFixture.cs" />
74+
<Compile Include="Properties\AssemblyInfo.cs" />
75+
</ItemGroup>
76+
<ItemGroup>
77+
<None Include="packages.config" />
78+
</ItemGroup>
79+
<ItemGroup>
80+
<ProjectReference Include="..\MaterialDesignThemes.Wpf\MaterialDesignThemes.Wpf.csproj">
81+
<Project>{F079FB0A-A8ED-4216-B6A5-345756751A04}</Project>
82+
<Name>MaterialDesignThemes.Wpf</Name>
83+
</ProjectReference>
84+
</ItemGroup>
85+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
86+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
87+
Other similar extension points exist, see Microsoft.Common.targets.
88+
<Target Name="BeforeBuild">
89+
</Target>
90+
<Target Name="AfterBuild">
91+
</Target>
92+
-->
93+
</Project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Moq;
2+
using NSubstitute;
3+
using Rhino.Mocks;
4+
using Xunit;
5+
using MockRepository = Rhino.Mocks.MockRepository;
6+
7+
namespace MaterialDesignThemes.Wpf.Tests
8+
{
9+
/// <summary>
10+
/// Proves that PaletteHelper is mockable, thus allowing TDD for view models which may want to change
11+
/// an application's palette.
12+
/// </summary>
13+
/// <remarks>
14+
/// This is not an exhaustive test of the class itself.
15+
/// </remarks>
16+
public class PaletteHelperFixture
17+
{
18+
[Fact]
19+
public void IsMockableWithRhino()
20+
{
21+
var paletteHelper = MockRepository.GenerateStub<PaletteHelper>();
22+
23+
paletteHelper.SetLightDark(true);
24+
25+
paletteHelper.AssertWasCalled(ph => ph.SetLightDark(true));
26+
}
27+
28+
[Fact]
29+
public void IsMockableWithMoq()
30+
{
31+
var mock = new Mock<PaletteHelper>();
32+
33+
mock.Object.SetLightDark(true);
34+
35+
mock.Verify(ph => ph.SetLightDark(true));
36+
}
37+
38+
[Fact]
39+
public void IsMockableWithNSubstitute()
40+
{
41+
var mock = Substitute.For<PaletteHelper>();
42+
43+
mock.SetLightDark(true);
44+
45+
mock.Received(1).SetLightDark(true);
46+
}
47+
}
48+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("MaterialDesignThemes.Wpf.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("MaterialDesignThemes.Wpf.Tests")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("a361c80e-f6cd-4c57-a96c-002db159c1f4")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Moq" version="4.2.1510.2205" targetFramework="net452" />
4+
<package id="NSubstitute" version="1.9.2.0" targetFramework="net452" />
5+
<package id="RhinoMocks" version="3.6.1" targetFramework="net452" />
6+
<package id="xunit" version="2.1.0" targetFramework="net452" />
7+
<package id="xunit.abstractions" version="2.0.0" targetFramework="net452" />
8+
<package id="xunit.assert" version="2.1.0" targetFramework="net452" />
9+
<package id="xunit.core" version="2.1.0" targetFramework="net452" />
10+
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net452" />
11+
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net452" />
12+
</packages>

MaterialDesignThemes.Wpf/PaletteHelper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace MaterialDesignThemes.Wpf
1010
{
1111
public class PaletteHelper
1212
{
13-
public void SetLightDark(bool isDark)
13+
public virtual void SetLightDark(bool isDark)
1414
{
1515
var existingResourceDictionary = Application.Current.Resources.MergedDictionaries
1616
.Where(rd => rd.Source != null)
@@ -38,7 +38,7 @@ public void SetLightDark(bool isDark)
3838
Application.Current.Resources.MergedDictionaries.Add(newMahAppsResourceDictionary);
3939
}
4040

41-
public void ReplacePrimaryColor(Swatch swatch)
41+
public virtual void ReplacePrimaryColor(Swatch swatch)
4242
{
4343
if (swatch == null) throw new ArgumentNullException(nameof(swatch));
4444

@@ -75,7 +75,7 @@ public void ReplacePrimaryColor(Swatch swatch)
7575
ReplaceEntry("IdealForegroundDisabledBrush", new SolidColorBrush(dark.Color) { Opacity = .4 });
7676
}
7777

78-
public void ReplacePrimaryColor(string name)
78+
public virtual void ReplacePrimaryColor(string name)
7979
{
8080
if (name == null) throw new ArgumentNullException(nameof(name));
8181

@@ -88,7 +88,7 @@ public void ReplacePrimaryColor(string name)
8888
ReplacePrimaryColor(swatch);
8989
}
9090

91-
public void ReplaceAccentColor(Swatch swatch)
91+
public virtual void ReplaceAccentColor(Swatch swatch)
9292
{
9393
if (swatch == null) throw new ArgumentNullException(nameof(swatch));
9494

@@ -102,7 +102,7 @@ public void ReplaceAccentColor(Swatch swatch)
102102
ReplaceEntry("SecondaryAccentForegroundBrush", new SolidColorBrush(swatch.AccentExemplarHue.Foreground));
103103
}
104104

105-
public void ReplaceAccentColor(string name)
105+
public virtual void ReplaceAccentColor(string name)
106106
{
107107
if (name == null) throw new ArgumentNullException(nameof(name));
108108

MaterialDesignToolkit.Wpf.sln

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialDesignColors.Wpf.Te
2626
EndProject
2727
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialDesignThemes.MahApps", "MaterialDesignThemes.MahApps\MaterialDesignThemes.MahApps.csproj", "{81556A2D-D467-43E7-945B-FD987C676CF6}"
2828
EndProject
29+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialDesignThemes.Wpf.Tests", "MaterialDesignThemes.Wpf.Tests\MaterialDesignThemes.Wpf.Tests.csproj", "{A361C80E-F6CD-4C57-A96C-002DB159C1F4}"
30+
EndProject
2931
Global
3032
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3133
AppVeyor|Any CPU = AppVeyor|Any CPU
@@ -210,6 +212,30 @@ Global
210212
{81556A2D-D467-43E7-945B-FD987C676CF6}.Release|x64.Build.0 = Release|Any CPU
211213
{81556A2D-D467-43E7-945B-FD987C676CF6}.Release|x86.ActiveCfg = Release|Any CPU
212214
{81556A2D-D467-43E7-945B-FD987C676CF6}.Release|x86.Build.0 = Release|Any CPU
215+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.AppVeyor|Any CPU.ActiveCfg = Release|Any CPU
216+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.AppVeyor|Any CPU.Build.0 = Release|Any CPU
217+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.AppVeyor|ARM.ActiveCfg = Release|Any CPU
218+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.AppVeyor|ARM.Build.0 = Release|Any CPU
219+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.AppVeyor|x64.ActiveCfg = Release|Any CPU
220+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.AppVeyor|x64.Build.0 = Release|Any CPU
221+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.AppVeyor|x86.ActiveCfg = Release|Any CPU
222+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.AppVeyor|x86.Build.0 = Release|Any CPU
223+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
224+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
225+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Debug|ARM.ActiveCfg = Debug|Any CPU
226+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Debug|ARM.Build.0 = Debug|Any CPU
227+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Debug|x64.ActiveCfg = Debug|Any CPU
228+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Debug|x64.Build.0 = Debug|Any CPU
229+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Debug|x86.ActiveCfg = Debug|Any CPU
230+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Debug|x86.Build.0 = Debug|Any CPU
231+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
232+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Release|Any CPU.Build.0 = Release|Any CPU
233+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Release|ARM.ActiveCfg = Release|Any CPU
234+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Release|ARM.Build.0 = Release|Any CPU
235+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Release|x64.ActiveCfg = Release|Any CPU
236+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Release|x64.Build.0 = Release|Any CPU
237+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Release|x86.ActiveCfg = Release|Any CPU
238+
{A361C80E-F6CD-4C57-A96C-002DB159C1F4}.Release|x86.Build.0 = Release|Any CPU
213239
EndGlobalSection
214240
GlobalSection(SolutionProperties) = preSolution
215241
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)