Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fc33cee

Browse files
author
Igor Velikorossov
committedSep 26, 2018
Add tests
1 parent fe10242 commit fc33cee

File tree

5 files changed

+161
-2
lines changed

5 files changed

+161
-2
lines changed
 

‎GitExtensions.sln

+7
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitExtUtilsTests", "UnitTes
182182
EndProject
183183
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TextEditor", "Externals\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj", "{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}"
184184
EndProject
185+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitUIPluginInterfacesTests", "UnitTests\Plugins\GitUIPluginInterfacesTests\GitUIPluginInterfacesTests.csproj", "{4DBDE0EB-9E03-48E0-8B1A-338850111373}"
186+
EndProject
185187
Global
186188
GlobalSection(SolutionConfigurationPlatforms) = preSolution
187189
Debug|Any CPU = Debug|Any CPU
@@ -358,6 +360,10 @@ Global
358360
{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Debug|Any CPU.Build.0 = Release|Any CPU
359361
{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
360362
{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Release|Any CPU.Build.0 = Release|Any CPU
363+
{4DBDE0EB-9E03-48E0-8B1A-338850111373}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
364+
{4DBDE0EB-9E03-48E0-8B1A-338850111373}.Debug|Any CPU.Build.0 = Debug|Any CPU
365+
{4DBDE0EB-9E03-48E0-8B1A-338850111373}.Release|Any CPU.ActiveCfg = Release|Any CPU
366+
{4DBDE0EB-9E03-48E0-8B1A-338850111373}.Release|Any CPU.Build.0 = Release|Any CPU
361367
EndGlobalSection
362368
GlobalSection(SolutionProperties) = preSolution
363369
HideSolutionNode = FALSE
@@ -403,6 +409,7 @@ Global
403409
{17FD2A6B-4005-41DC-BFAC-59F936DF33AA} = {C5855184-8571-4AD0-A373-B98215BA56CA}
404410
{2B9B62FA-3E0C-45C5-9287-68B69413C5DF} = {020F800B-9170-4BB3-83C9-FCF83596D83C}
405411
{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D} = {0E859634-B3DF-46AC-A73C-D49734F19D6A}
412+
{4DBDE0EB-9E03-48E0-8B1A-338850111373} = {C2276A26-13DF-485A-8B2C-414CF507798F}
406413
EndGlobalSection
407414
GlobalSection(ExtensibilityGlobals) = postSolution
408415
SolutionGuid = {ECECB7EA-BCCF-44AD-B63E-C2FA45589FB0}

‎Plugins/GitUIPluginInterfaces/FontParser.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ public static string AsString(this Font value)
1515

1616
public static Font Parse(this string value, Font defaultValue)
1717
{
18-
if (value == null)
18+
if (string.IsNullOrWhiteSpace(value))
1919
{
2020
return defaultValue;
2121
}
2222

2323
string[] parts = value.Split(';');
24-
2524
if (parts.Length < 2)
2625
{
2726
return defaultValue;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System.Drawing;
2+
using FluentAssertions;
3+
using GitUIPluginInterfaces;
4+
using NUnit.Framework;
5+
6+
namespace GitUIPluginInterfacesTests
7+
{
8+
[TestFixture]
9+
public class FontParserTests
10+
{
11+
private Font _defaultFont;
12+
13+
[SetUp]
14+
public void Setup()
15+
{
16+
_defaultFont = new Font("Arial", 9);
17+
}
18+
19+
[TearDown]
20+
public void TearDown()
21+
{
22+
_defaultFont.Dispose();
23+
}
24+
25+
[TestCase(FontStyle.Regular, "Arial;9;_IC_;0;0")]
26+
[TestCase(FontStyle.Bold, "Arial;9;_IC_;1;0")]
27+
[TestCase(FontStyle.Italic, "Arial;9;_IC_;0;1")]
28+
[TestCase(FontStyle.Bold | FontStyle.Italic, "Arial;9;_IC_;1;1")]
29+
public void AsString_should_persist_font_with_styles(FontStyle fontStyle, string serialised)
30+
{
31+
using (var font = new Font("Arial", 9, fontStyle))
32+
{
33+
font.AsString().Should().Be(serialised);
34+
}
35+
}
36+
37+
[TestCase(null)]
38+
[TestCase("")]
39+
[TestCase("\t")]
40+
public void Parse_should_return_default_if_null_or_empty(string serialised)
41+
{
42+
var font = serialised.Parse(_defaultFont);
43+
44+
font.Should().Be(_defaultFont);
45+
}
46+
47+
[TestCase("Arial")]
48+
[TestCase("Arial;")]
49+
public void Parse_should_return_default_if_less_then_two_parts(string serialised)
50+
{
51+
var font = serialised.Parse(_defaultFont);
52+
53+
font.Should().Be(_defaultFont);
54+
}
55+
56+
[TestCase("Courier;8.25;", "Courier", 8.25f, FontStyle.Regular)]
57+
[TestCase("Courier;12;_IC_", "Courier", 12f, FontStyle.Regular)]
58+
[TestCase("Courier;11,3;", "Courier", 11.3f, FontStyle.Regular)]
59+
[TestCase("Courier;11,3;ru", "Courier", 11.3f, FontStyle.Regular)]
60+
[TestCase("Courier;12;_IC_;0;0", "Courier", 12f, FontStyle.Regular)]
61+
[TestCase("Courier;12;_IC_;1;0", "Courier", 12f, FontStyle.Bold)]
62+
[TestCase("Courier;12;_IC_;0;1", "Courier", 12f, FontStyle.Italic)]
63+
[TestCase("Courier;12;_IC_;1;1", "Courier", 12f, FontStyle.Italic | FontStyle.Bold)]
64+
public void Parse_should_parse(string serialised, string name, float size, FontStyle style)
65+
{
66+
var font = serialised.Parse(_defaultFont);
67+
68+
font.Should().NotBe(_defaultFont);
69+
font.OriginalFontName.Should().Be(name);
70+
font.Size.Should().Be(size);
71+
font.Style.Should().Be(style);
72+
}
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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>{4DBDE0EB-9E03-48E0-8B1A-338850111373}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>GitUIPluginInterfacesTests</RootNamespace>
11+
<AssemblyName>GitUIPluginInterfacesTests</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
15+
<TestProjectType>UnitTest</TestProjectType>
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+
<CodeAnalysisRuleSet>..\..\..\GitExtensionsTest.ruleset</CodeAnalysisRuleSet>
26+
<DocumentationFile>bin\Debug\GitUIPluginInterfacesTests.xml</DocumentationFile>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
<CodeAnalysisRuleSet>..\..\..\GitExtensionsTest.ruleset</CodeAnalysisRuleSet>
36+
<DocumentationFile>bin\Release\GitUIPluginInterfacesTests.xml</DocumentationFile>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Reference Include="System" />
40+
<Reference Include="System.Drawing" />
41+
<Reference Include="System.Windows.Forms" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<PackageReference Include="FluentAssertions" Version="5.2.0" />
45+
<PackageReference Include="NUnit" Version="3.10.1" />
46+
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="FontParserTests.cs" />
50+
<Compile Include="Properties\AssemblyInfo.cs" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<ProjectReference Include="..\..\..\Plugins\GitUIPluginInterfaces\GitUIPluginInterfaces.csproj">
54+
<Project>{27559302-F35E-4B62-A6EC-11FF21A5FA6F}</Project>
55+
<Name>GitUIPluginInterfaces</Name>
56+
</ProjectReference>
57+
</ItemGroup>
58+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
59+
</Project>
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("GitUIPluginInterfacesTests")]
6+
[assembly: AssemblyDescription("")]
7+
[assembly: AssemblyConfiguration("")]
8+
[assembly: AssemblyCompany("")]
9+
[assembly: AssemblyProduct("GitUIPluginInterfacesTests")]
10+
[assembly: AssemblyCopyright("Copyright © 2018")]
11+
[assembly: AssemblyTrademark("")]
12+
[assembly: AssemblyCulture("")]
13+
14+
[assembly: ComVisible(false)]
15+
16+
[assembly: Guid("4dbde0eb-9e03-48e0-8b1a-338850111373")]
17+
18+
// [assembly: AssemblyVersion("1.0.*")]
19+
[assembly: AssemblyVersion("1.0.0.0")]
20+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)
Please sign in to comment.