Add unit tests for InsertTable

Using NUnit 3 and ApprovalTests
This commit is contained in:
David Gardiner 2016-02-28 09:24:32 +10:30
parent 926e8f4177
commit a25c622726
12 changed files with 441 additions and 1 deletions

View File

@ -45,7 +45,8 @@ namespace OpenLiveWriter.PostEditor.Tables
// table properties
TableProperties properties = parameters.Properties;
StringBuilder propertiesString = new StringBuilder();
propertiesString.AppendFormat("width=\"{0}\"", properties.Width);
if (properties.Width.Units != PixelPercentUnits.Undefined)
propertiesString.AppendFormat("width=\"{0}\"", properties.Width);
if (properties.BorderSize != String.Empty)
propertiesString.AppendFormat(" border=\"{0}\"", properties.BorderSize);
if (properties.CellPadding != String.Empty)

View File

@ -0,0 +1,139 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B3E5F002-AFD0-427A-BCBB-B1E4FB6FC92E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenLiveWriter.Tests</RootNamespace>
<AssemblyName>OpenLiveWriter.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</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>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</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>
<PlatformTarget>x86</PlatformTarget>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</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>
<PlatformTarget>x86</PlatformTarget>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="ApprovalTests, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL">
<HintPath>..\packages\ApprovalTests.3.0.10\lib\net40\ApprovalTests.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ApprovalUtilities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL">
<HintPath>..\packages\ApprovalUtilities.3.0.10\lib\net45\ApprovalUtilities.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ApprovalUtilities.Net45, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ApprovalUtilities.3.0.10\lib\net45\ApprovalUtilities.Net45.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit3TestAdapter.3.0.8-ctp-8\lib\Mono.Cecil.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="nunit.engine, Version=3.0.5813.39036, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit3TestAdapter.3.0.8-ctp-8\lib\nunit.engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="nunit.engine.api, Version=3.0.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit3TestAdapter.3.0.8-ctp-8\lib\nunit.engine.api.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="nunit.framework, Version=3.0.5813.39031, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NUnit3.TestAdapter, Version=3.0.8.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit3TestAdapter.3.0.8-ctp-8\lib\NUnit3.TestAdapter.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="PostEditor\Tables\TestHtmlEditor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PostEditor\Tables\InsertTableTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenLiveWriter.ApplicationFramework\OpenLiveWriter.ApplicationFramework.csproj">
<Project>{eeee653a-90ce-44e2-b40e-22f747880cc0}</Project>
<Name>OpenLiveWriter.ApplicationFramework</Name>
</ProjectReference>
<ProjectReference Include="..\OpenLiveWriter.HtmlEditor\OpenLiveWriter.HtmlEditor.csproj">
<Project>{6A6872BC-67EF-4A42-A21A-30ECED376923}</Project>
<Name>OpenLiveWriter.HtmlEditor</Name>
</ProjectReference>
<ProjectReference Include="..\OpenLiveWriter.PostEditor\OpenLiveWriter.PostEditor.csproj">
<Project>{d6c9a393-e0b8-4548-b84b-f8b6fe2a5645}</Project>
<Name>OpenLiveWriter.PostEditor</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>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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>

View File

@ -0,0 +1,22 @@
<table width="100%" unselectable="on">
<tbody>
<tr>
<td valign="top" width="25%"></td>
<td valign="top" width="25%"></td>
<td valign="top" width="25%"></td>
<td valign="top" width="25%"></td>
</tr>
<tr>
<td valign="top" width="25%"></td>
<td valign="top" width="25%"></td>
<td valign="top" width="25%"></td>
<td valign="top" width="25%"></td>
</tr>
<tr>
<td valign="top" width="25%"></td>
<td valign="top" width="25%"></td>
<td valign="top" width="25%"></td>
<td valign="top" width="25%"></td>
</tr>
</tbody>
</table>

View File

@ -0,0 +1,22 @@
<table width="400" unselectable="on">
<tbody>
<tr>
<td valign="top" width="100"></td>
<td valign="top" width="100"></td>
<td valign="top" width="100"></td>
<td valign="top" width="100"></td>
</tr>
<tr>
<td valign="top" width="100"></td>
<td valign="top" width="100"></td>
<td valign="top" width="100"></td>
<td valign="top" width="100"></td>
</tr>
<tr>
<td valign="top" width="100"></td>
<td valign="top" width="100"></td>
<td valign="top" width="100"></td>
<td valign="top" width="100"></td>
</tr>
</tbody>
</table>

View File

@ -0,0 +1,22 @@
<table unselectable="on">
<tbody>
<tr>
<td valign="top"></td>
<td valign="top"></td>
<td valign="top"></td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top"></td>
<td valign="top"></td>
<td valign="top"></td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top"></td>
<td valign="top"></td>
<td valign="top"></td>
<td valign="top"></td>
</tr>
</tbody>
</table>

View File

@ -0,0 +1,22 @@
<table cellpadding="0" cellspacing="2" unselectable="on">
<tbody>
<tr>
<td valign="top"></td>
<td valign="top"></td>
<td valign="top"></td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top"></td>
<td valign="top"></td>
<td valign="top"></td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top"></td>
<td valign="top"></td>
<td valign="top"></td>
<td valign="top"></td>
</tr>
</tbody>
</table>

View File

@ -0,0 +1,89 @@
using ApprovalTests;
using ApprovalTests.Reporters;
using NUnit.Framework;
using OpenLiveWriter.PostEditor.Tables;
namespace OpenLiveWriter.Tests.PostEditor.Tables
{
[UseReporter(typeof(DiffReporter))]
[TestFixture]
public class InsertTableTests
{
[Test]
public void Table400PixelsWide3Rows4Columns()
{
// Arrange
var editor = new TestHtmlEditor();
TableProperties tableProperties = new TableProperties();
tableProperties.Width = new PixelPercent(400, PixelPercentUnits.Pixels);
int rows = 3;
int columns = 4;
TableCreationParameters tableCreationParamters = new TableCreationParameters(rows, columns, tableProperties);
// Act
TableEditor.InsertTable(editor, null, tableCreationParamters);
// Assert
Approvals.VerifyHtml(editor.Html);
}
[Test]
public void Table100PercentWide3Rows4Columns()
{
// Arrange
var editor = new TestHtmlEditor();
TableProperties tableProperties = new TableProperties();
tableProperties.Width = new PixelPercent(100, PixelPercentUnits.Percentage);
int rows = 3;
int columns = 4;
TableCreationParameters tableCreationParamters = new TableCreationParameters(rows, columns, tableProperties);
// Act
TableEditor.InsertTable(editor, null, tableCreationParamters);
// Assert
Approvals.VerifyHtml(editor.Html);
}
[Test]
public void TableNoWide3Rows4Columns()
{
// Arrange
var editor = new TestHtmlEditor();
TableProperties tableProperties = new TableProperties();
tableProperties.Width = new PixelPercent(0, PixelPercentUnits.Undefined);
int rows = 3;
int columns = 4;
TableCreationParameters tableCreationParamters = new TableCreationParameters(rows, columns, tableProperties);
// Act
TableEditor.InsertTable(editor, null, tableCreationParamters);
// Assert
Approvals.VerifyHtml(editor.Html);
}
[Test]
public void TableNoWide3Rows4ColumnsCellSpacingPadding()
{
// Arrange
var editor = new TestHtmlEditor();
TableProperties tableProperties = new TableProperties();
tableProperties.Width = new PixelPercent(0, PixelPercentUnits.Undefined);
tableProperties.CellSpacing = "2";
tableProperties.CellPadding = "0";
int rows = 3;
int columns = 4;
TableCreationParameters tableCreationParamters = new TableCreationParameters(rows, columns, tableProperties);
// Act
TableEditor.InsertTable(editor, null, tableCreationParamters);
// Assert
Approvals.VerifyHtml(editor.Html);
}
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Windows.Forms;
using OpenLiveWriter.HtmlEditor;
namespace OpenLiveWriter.Tests.PostEditor.Tables
{
class TestHtmlEditor : IHtmlEditor
{
public string Html { get; set; } = string.Empty;
public void Dispose()
{
}
public Control EditorControl { get; }
public void LoadHtmlFile(string filePath)
{
}
public string GetEditedHtml(bool preferWellFormed)
{
return null;
}
public string GetEditedHtmlFast()
{
return null;
}
public string SelectedText { get; }
public string SelectedHtml { get; }
public void EmptySelection()
{
}
public void InsertHtml(string content, bool moveSelectionRight)
{
Html += content;
}
public void InsertHtml(string content, HtmlInsertionOptions options)
{
}
public void InsertLink(string url, string linkText, string linkTitle, string rel, bool newWindow)
{
}
public bool IsDirty { get; set; }
public IHtmlEditorCommandSource CommandSource { get; }
#pragma warning disable CS0067
public event EventHandler IsDirtyEvent;
public bool SuspendAutoSave { get; }
}
}

View File

@ -0,0 +1,36 @@
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("OpenLiveWriter.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OpenLiveWriter.Tests")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[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("b3e5f002-afd0-427a-bcbb-b1e4fb6fc92e")]
// 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.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ApprovalUtilities" publicKeyToken="11bd7d124fc62e0f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.22.0.0" newVersion="1.22.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ApprovalTests" version="3.0.10" targetFramework="net452" />
<package id="ApprovalUtilities" version="3.0.10" targetFramework="net452" />
<package id="NUnit" version="3.0.1" targetFramework="net452" />
<package id="NUnit3TestAdapter" version="3.0.8-ctp-8" targetFramework="net452" />
</packages>

View File

@ -85,6 +85,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PostBuild.CreateInstaller",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenLiveWriter.SpellChecker", "OpenLiveWriter.SpellChecker\OpenLiveWriter.SpellChecker.csproj", "{2DB3A424-0F1E-44AC-AE01-5454586CE769}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenLiveWriter.Tests", "OpenLiveWriter.Tests\OpenLiveWriter.Tests.csproj", "{B3E5F002-AFD0-427A-BCBB-B1E4FB6FC92E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -199,6 +201,10 @@ Global
{2DB3A424-0F1E-44AC-AE01-5454586CE769}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2DB3A424-0F1E-44AC-AE01-5454586CE769}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2DB3A424-0F1E-44AC-AE01-5454586CE769}.Release|Any CPU.Build.0 = Release|Any CPU
{B3E5F002-AFD0-427A-BCBB-B1E4FB6FC92E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3E5F002-AFD0-427A-BCBB-B1E4FB6FC92E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3E5F002-AFD0-427A-BCBB-B1E4FB6FC92E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3E5F002-AFD0-427A-BCBB-B1E4FB6FC92E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE