Skip to content

Commit 3764f01

Browse files
committed
Preparing for Windows unit tests.
1 parent 9bd6ecb commit 3764f01

File tree

8 files changed

+310
-0
lines changed

8 files changed

+310
-0
lines changed

ColorSet.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28307.572
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorSetKit", "ColorSetKit\ColorSetKit.csproj", "{E3BF32CB-99E2-4331-AFB6-9281D79E63BC}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorSetKit-Test", "ColorSetKit-Test\ColorSetKit-Test.csproj", "{56A92618-CCFE-4313-90C1-EA63DFD154A0}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{E3BF32CB-99E2-4331-AFB6-9281D79E63BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{E3BF32CB-99E2-4331-AFB6-9281D79E63BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{E3BF32CB-99E2-4331-AFB6-9281D79E63BC}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{56A92618-CCFE-4313-90C1-EA63DFD154A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{56A92618-CCFE-4313-90C1-EA63DFD154A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{56A92618-CCFE-4313-90C1-EA63DFD154A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{56A92618-CCFE-4313-90C1-EA63DFD154A0}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
4+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
5+
<PropertyGroup>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{56A92618-CCFE-4313-90C1-EA63DFD154A0}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>ColorSetKit_Test</RootNamespace>
12+
<AssemblyName>ColorSetKit-Test</AssemblyName>
13+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
16+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
17+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
18+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
19+
<IsCodedUITest>False</IsCodedUITest>
20+
<TestProjectType>UnitTest</TestProjectType>
21+
<NuGetPackageImportStamp>
22+
</NuGetPackageImportStamp>
23+
<TargetFrameworkProfile />
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
26+
<DebugSymbols>true</DebugSymbols>
27+
<DebugType>full</DebugType>
28+
<Optimize>false</Optimize>
29+
<OutputPath>..\Build\Debug\</OutputPath>
30+
<DefineConstants>DEBUG;TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
<Prefer32Bit>false</Prefer32Bit>
34+
</PropertyGroup>
35+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
36+
<DebugType>pdbonly</DebugType>
37+
<Optimize>true</Optimize>
38+
<OutputPath>..\Build\Release\</OutputPath>
39+
<DefineConstants>TRACE</DefineConstants>
40+
<ErrorReport>prompt</ErrorReport>
41+
<WarningLevel>4</WarningLevel>
42+
<Prefer32Bit>false</Prefer32Bit>
43+
</PropertyGroup>
44+
<ItemGroup>
45+
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
46+
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
47+
</Reference>
48+
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
49+
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
50+
</Reference>
51+
<Reference Include="PresentationCore" />
52+
<Reference Include="System" />
53+
<Reference Include="System.Core" />
54+
<Reference Include="WindowsBase" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<Compile Include="Test.cs" />
58+
<Compile Include="Properties\AssemblyInfo.cs" />
59+
</ItemGroup>
60+
<ItemGroup>
61+
<None Include="packages.config" />
62+
</ItemGroup>
63+
<ItemGroup>
64+
<ProjectReference Include="..\ColorSetKit\ColorSetKit.csproj">
65+
<Project>{e3bf32cb-99e2-4331-afb6-9281d79e63bc}</Project>
66+
<Name>ColorSetKit</Name>
67+
</ProjectReference>
68+
</ItemGroup>
69+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
70+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
71+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
72+
<PropertyGroup>
73+
<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>
74+
</PropertyGroup>
75+
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
76+
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
77+
</Target>
78+
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
79+
<PropertyGroup>
80+
<PostBuildEvent>copy "$(ProjectDir)Colors.colorset" "$(TargetDir)Colors.colorset"</PostBuildEvent>
81+
</PropertyGroup>
82+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
[assembly: AssemblyTitle( "ColorSetKit-Test" )]
6+
[assembly: AssemblyDescription( "" )]
7+
[assembly: AssemblyConfiguration( "" )]
8+
[assembly: AssemblyCompany( "" )]
9+
[assembly: AssemblyProduct( "ColorSetKit-Test" )]
10+
[assembly: AssemblyCopyright( "Copyright © 2019" )]
11+
[assembly: AssemblyTrademark( "" )]
12+
[assembly: AssemblyCulture( "" )]
13+
14+
[assembly: ComVisible( false )]
15+
16+
[assembly: Guid( "56a92618-ccfe-4313-90c1-ea63dfd154a0" )]
17+
18+
// [assembly: AssemblyVersion("1.0.*")]
19+
[assembly: AssemblyVersion( "1.0.0.0" )]
20+
[assembly: AssemblyFileVersion( "1.0.0.0" )]

ColorSetKit-Test/Test.cs

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/*******************************************************************************
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018 Jean-David Gadina - www.imazing.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
******************************************************************************/
24+
25+
using System;
26+
using System.Reflection;
27+
using Microsoft.VisualStudio.TestTools.UnitTesting;
28+
using ColorSetKit;
29+
using System.Windows.Media;
30+
31+
namespace ColorSetKit_Test
32+
{
33+
[TestClass]
34+
public class Test
35+
{
36+
[TestMethod]
37+
public void TestInitWithPath()
38+
{
39+
string path = System.IO.Path.Combine( System.IO.Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "Colors.colorset" );
40+
ColorSet set = new ColorSet( path );
41+
42+
Assert.IsTrue( set.Colors.Count > 0 );
43+
}
44+
45+
[TestMethod]
46+
public void TestInitWithData()
47+
{
48+
string path = System.IO.Path.Combine( System.IO.Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "Colors.colorset" );
49+
Data data = new Data( path );
50+
ColorSet set = new ColorSet( data );
51+
52+
Assert.IsTrue( set.Colors.Count > 0 );
53+
}
54+
55+
[TestMethod]
56+
public void TestShared()
57+
{
58+
Assert.AreEqual( ColorSet.Shared.Colors.Count, 2 );
59+
60+
Assert.IsTrue( ColorSet.Shared.Colors.ContainsKey( "NoVariant" ) );
61+
Assert.IsTrue( ColorSet.Shared.Colors.ContainsKey( "Variant" ) );
62+
63+
ColorPair p1 = ColorSet.Shared.Colors[ "NoVariant" ];
64+
ColorPair p2 = ColorSet.Shared.Colors[ "Variant" ];
65+
66+
if( p1.Color is SolidColorBrush c )
67+
{
68+
Assert.AreEqual( c.Color.R, 50 );
69+
Assert.AreEqual( c.Color.G, 100 );
70+
Assert.AreEqual( c.Color.B, 150 );
71+
Assert.AreEqual( ( double )( c.Color.A ) / 256, 0.5 );
72+
}
73+
else
74+
{
75+
Assert.Fail( "Color is not defined" );
76+
}
77+
78+
if( p1.Variant != null )
79+
{
80+
Assert.Fail( "No variant should be defined" );
81+
}
82+
}
83+
84+
/*
85+
func testShared()
86+
{
87+
if let c = p2.color
88+
{
89+
XCTAssertEqual( c.redComponent * 255, 250.0 )
90+
XCTAssertEqual( c.greenComponent * 255, 200.0 )
91+
XCTAssertEqual( c.blueComponent * 255, 150.0 )
92+
XCTAssertEqual( c.alphaComponent, 0.75 )
93+
}
94+
else
95+
{
96+
XCTFail( "Color is not defined" )
97+
}
98+
99+
if let c = p2.variant
100+
{
101+
XCTAssertEqual( c.redComponent * 255, 200.0 )
102+
XCTAssertEqual( c.greenComponent * 255, 150.0 )
103+
XCTAssertEqual( c.blueComponent * 255, 250.0 )
104+
XCTAssertEqual( c.alphaComponent, 0.25 )
105+
}
106+
else
107+
{
108+
XCTFail( "Color is not defined" )
109+
}
110+
}
111+
112+
func testNSColor()
113+
{
114+
if let c = NSColor.colorFrom( colorSet: "NoVariant" )
115+
{
116+
XCTAssertEqual( c.redComponent * 255, 50.0 )
117+
XCTAssertEqual( c.greenComponent * 255, 100.0 )
118+
XCTAssertEqual( c.blueComponent * 255, 150.0 )
119+
XCTAssertEqual( c.alphaComponent, 0.5 )
120+
}
121+
else
122+
{
123+
XCTFail( "Cannot retrieve color from NSColor" ); return
124+
}
125+
}
126+
127+
func testCreate()
128+
{
129+
var set = ColorSet()
130+
131+
set.add( color: NSColor( red: 0.1, green: 0.2, blue: 0.3, alpha: 0.4 ), forName: "NoVariant" )
132+
set.add( color: NSColor( red: 0.5, green: 0.6, blue: 0.7, alpha: 0.8 ), variant: NSColor( red: 0.8, green: 0.7, blue: 0.6, alpha: 0.5 ), forName: "Variant" )
133+
134+
set = ColorSet( data: set.data ) ?? ColorSet()
135+
136+
XCTAssertEqual( set.colors.count, 2 )
137+
138+
guard let p1 = set.colors[ "NoVariant" ] else
139+
{
140+
XCTFail( "Cannot retrieve color from shared color set file" ); return
141+
}
142+
143+
guard let p2 = set.colors[ "Variant" ] else
144+
{
145+
XCTFail( "Cannot retrieve color from shared color set file" ); return
146+
}
147+
148+
if let c = p1.color
149+
{
150+
XCTAssertEqual( c.redComponent, 0.1 )
151+
XCTAssertEqual( c.greenComponent, 0.2 )
152+
XCTAssertEqual( c.blueComponent, 0.3 )
153+
XCTAssertEqual( c.alphaComponent, 0.4 )
154+
}
155+
else
156+
{
157+
XCTFail( "Color is not defined" )
158+
}
159+
160+
if let _ = p1.variant
161+
{
162+
XCTFail( "No variant should be defined" )
163+
}
164+
165+
if let c = p2.color
166+
{
167+
XCTAssertEqual( c.redComponent, 0.5 )
168+
XCTAssertEqual( c.greenComponent, 0.6 )
169+
XCTAssertEqual( c.blueComponent, 0.7 )
170+
XCTAssertEqual( c.alphaComponent, 0.8 )
171+
}
172+
else
173+
{
174+
XCTFail( "Color is not defined" )
175+
}
176+
177+
if let c = p2.variant
178+
{
179+
XCTAssertEqual( c.redComponent, 0.8 )
180+
XCTAssertEqual( c.greenComponent, 0.7 )
181+
XCTAssertEqual( c.blueComponent, 0.6 )
182+
XCTAssertEqual( c.alphaComponent, 0.5 )
183+
}
184+
else
185+
{
186+
XCTFail( "Color is not defined" )
187+
}
188+
}
189+
*/
190+
}
191+
}

ColorSetKit-Test/bin/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

ColorSetKit-Test/obj/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

ColorSetKit-Test/packages.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net45" />
4+
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net45" />
5+
</packages>

packages/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

0 commit comments

Comments
 (0)