diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-06-04 16:03:56 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-06-04 16:03:56 +0100 |
| commit | 45e530dceda42282fae56b4c4f5fa7865f57899d (patch) | |
| tree | 685868f4bf78c64e851cbcdafd674e887bc782a5 /dotnet/Mammoth.Tests | |
| parent | b5a83b1cb96d410e325ff8b733d550295376d8c7 (diff) | |
Remove dotnet (use submodule from dotnet repo instead)
Diffstat (limited to 'dotnet/Mammoth.Tests')
| -rw-r--r-- | dotnet/Mammoth.Tests/DocumentConverterTests.cs | 214 | ||||
| -rw-r--r-- | dotnet/Mammoth.Tests/Mammoth.Tests.csproj | 77 | ||||
| -rw-r--r-- | dotnet/Mammoth.Tests/Properties/AssemblyInfo.cs | 27 | ||||
| l--------- | dotnet/Mammoth.Tests/TestData | 1 | ||||
| -rw-r--r-- | dotnet/Mammoth.Tests/packages.config | 9 |
5 files changed, 0 insertions, 328 deletions
diff --git a/dotnet/Mammoth.Tests/DocumentConverterTests.cs b/dotnet/Mammoth.Tests/DocumentConverterTests.cs deleted file mode 100644 index 92a3adf..0000000 --- a/dotnet/Mammoth.Tests/DocumentConverterTests.cs +++ /dev/null @@ -1,214 +0,0 @@ -using Xunit; -using System.IO; -using Xunit.Sdk; -using System; -using System.Linq; - -namespace Mammoth.Tests { - public class DocumentConverterTests { - [Fact] - public void DocxContainingOneParagraphIsConvertedToSingleParagraphElement() { - AssertSuccessfulConversion( - ConvertToHtml("single-paragraph.docx"), - "<p>Walking on imported air</p>"); - } - - [Fact] - public void CanReadFilesWithUtf8Bom() { - AssertSuccessfulConversion( - ConvertToHtml("utf8-bom.docx"), - "<p>This XML has a byte order mark.</p>"); - } - - [Fact] - public void EmptyParagraphsAreIgnoredByDefault() { - AssertSuccessfulConversion( - ConvertToHtml("empty.docx"), - ""); - } - - [Fact] - public void EmptyParagraphsArePreservedIfIgnoreEmptyParagraphsIsFalse() { - AssertSuccessfulConversion( - ConvertToHtml("empty.docx", converter => converter.PreserveEmptyParagraphs()), - "<p></p>"); - } - - [Fact] - public void SimpleListIsConvertedToListElements() { - AssertSuccessfulConversion( - ConvertToHtml("simple-list.docx"), - "<ul><li>Apple</li><li>Banana</li></ul>"); - } - - [Fact] - public void WordTablesAreConvertedToHtmlTables() { - AssertSuccessfulConversion( - ConvertToHtml("tables.docx"), - "<p>Above</p>" + - "<table>" + - "<tr><td><p>Top left</p></td><td><p>Top right</p></td></tr>" + - "<tr><td><p>Bottom left</p></td><td><p>Bottom right</p></td></tr>" + - "</table>" + - "<p>Below</p>"); - } - - [Fact] - public void InlineImagesAreIncludedInOutput() { - AssertSuccessfulConversion( - ConvertToHtml("tiny-picture.docx"), - "<p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=\" /></p>"); - } - - [Fact] - public void ImagesStoredOutsideOfDocumentAreIncludedInOutput() { - AssertSuccessfulConversion( - ConvertToHtml("external-picture.docx"), - "<p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=\" /></p>"); - } - - [Fact] - public void WarnIfDocumentHasImagesStoredOutsideOfDocumentWhenPathOfDocumentIsUnknown() { - using (var file = File.OpenRead(TestFilePath("external-picture.docx"))) { - var result = new DocumentConverter().ConvertToHtml(file); - Assert.Equal("", result.Value); - Assert.Equal(new[]{"could not open external image 'tiny-picture.png': path of document is unknown, but is required for relative URI"}, result.Warnings); - } - } - - [Fact] - public void WarnIfImagesStoredOutsideOfDocumentAreNotFound() { - var tempDirectory = Path.Combine(Path.GetTempPath(), "mammoth-" + Guid.NewGuid()); - Directory.CreateDirectory(tempDirectory); - try { - var documentPath = Path.Combine(tempDirectory, "external-picture.docx"); - File.Copy(TestFilePath("external-picture.docx"), documentPath); - var result = new DocumentConverter().ConvertToHtml(documentPath); - Assert.Equal("", result.Value); - Assert.StartsWith("could not open external image 'tiny-picture.png':", result.Warnings.Single()); - } finally { - Directory.Delete(tempDirectory, recursive: true); - } - } - - [Fact] - public void ContentTypesAreRead() { - AssertSuccessfulConversion( - ConvertToHtml("tiny-picture-custom-content-type.docx"), - "<p><img src=\"data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=\" /></p>"); - } - - [Fact] - public void FootnotesAreAppendedToText() { - AssertSuccessfulConversion( - ConvertToHtml("footnotes.docx", mammoth => mammoth.IdPrefix("doc-42-")), - "<p>Ouch" + - "<sup><a href=\"#doc-42-footnote-1\" id=\"doc-42-footnote-ref-1\">[1]</a></sup>." + - "<sup><a href=\"#doc-42-footnote-2\" id=\"doc-42-footnote-ref-2\">[2]</a></sup></p>" + - "<ol><li id=\"doc-42-footnote-1\"><p> A tachyon walks into a bar. <a href=\"#doc-42-footnote-ref-1\">↑</a></p></li>" + - "<li id=\"doc-42-footnote-2\"><p> Fin. <a href=\"#doc-42-footnote-ref-2\">↑</a></p></li></ol>"); - } - - [Fact] - public void EndNotesAreAppendedToText() { - AssertSuccessfulConversion( - ConvertToHtml("endnotes.docx", mammoth => mammoth.IdPrefix("doc-42-")), - "<p>Ouch" + - "<sup><a href=\"#doc-42-endnote-2\" id=\"doc-42-endnote-ref-2\">[1]</a></sup>." + - "<sup><a href=\"#doc-42-endnote-3\" id=\"doc-42-endnote-ref-3\">[2]</a></sup></p>" + - "<ol><li id=\"doc-42-endnote-2\"><p> A tachyon walks into a bar. <a href=\"#doc-42-endnote-ref-2\">↑</a></p></li>" + - "<li id=\"doc-42-endnote-3\"><p> Fin. <a href=\"#doc-42-endnote-ref-3\">↑</a></p></li></ol>"); - } - - [Fact] - public void RelationshipsAreReadForEachFileContainingBodyXml() { - AssertSuccessfulConversion( - ConvertToHtml("footnote-hyperlink.docx", mammoth => mammoth.IdPrefix("doc-42-")), - - "<p><sup><a href=\"#doc-42-footnote-1\" id=\"doc-42-footnote-ref-1\">[1]</a></sup></p>" + - "<ol><li id=\"doc-42-footnote-1\"><p> <a href=\"http://www.example.com\">Example</a> <a href=\"#doc-42-footnote-ref-1\">↑</a></p></li></ol>"); - } - - [Fact] - public void TextBoxesAreRead() { - AssertSuccessfulConversion( - ConvertToHtml("text-box.docx"), - "<p>Datum plane</p>"); - } - - [Fact] - public void CanUseCustomStyleMap() { - AssertSuccessfulConversion( - ConvertToHtml("underline.docx", mammoth => mammoth.AddStyleMap("u => em")), - "<p><strong>The <em>Sunset</em> Tree</strong></p>"); - } - - [Fact] - public void MostRecentlyAddedStyleMapTakesPrecedence() { - AssertSuccessfulConversion( - ConvertToHtml("underline.docx", mammoth => mammoth.AddStyleMap("u => em").AddStyleMap("u => strong")), - "<p><strong>The <strong>Sunset</strong> Tree</strong></p>"); - } - - [Fact] - public void RulesFromPreviouslyAddedStyleMapsStillTakeEffectIfNotOverridden() { - AssertSuccessfulConversion( - ConvertToHtml("underline.docx", mammoth => mammoth.AddStyleMap("u => em").AddStyleMap("strike => del")), - "<p><strong>The <em>Sunset</em> Tree</strong></p>"); - } - - [Fact] - public void ErrorIsRaisedIfStyleMapCannotBeParsed() { - var exception = Assert.ThrowsAny<Exception>(() => - new DocumentConverter().AddStyleMap("p =>\np[style-name=] =>")); - Assert.Equal( - "error reading style map at line 2, character 14: expected token of type _STRING but was of type _CLOSE_SQUARE_BRACKET\n\n" + - "p[style-name=] =>\n" + - " ^", - exception.Message); - } - - [Fact] - public void CanDisableDefaultStyleMap() { - var result = ConvertToHtml("simple-list.docx", mammoth => mammoth.DisableDefaultStyleMap()); - Assert.Equal(new[]{"Unrecognised paragraph style: List Paragraph (Style ID: ListParagraph)"}, result.Warnings); - Assert.Equal("<p>Apple</p><p>Banana</p>", result.Value); - } - - [Fact] - public void CanExtractRawTextFromFile() { - AssertSuccessfulConversion( - new DocumentConverter().ExtractRawText(TestFilePath("simple-list.docx")), - "Apple\n\nBanana\n\n"); - } - - [Fact] - public void CanExtractRawTextFromStream() { - using (var file = File.OpenRead(TestFilePath("simple-list.docx"))) { - AssertSuccessfulConversion( - new DocumentConverter().ExtractRawText(file), - "Apple\n\nBanana\n\n"); - } - } - - private void AssertSuccessfulConversion(IResult<string> result, string expectedValue) { - if (result.Warnings.Count > 0) { - throw new XunitException("Unexpected warnings: " + string.Join(", ", result.Warnings)); - } - Assert.Equal(expectedValue, result.Value); - } - - private IResult<string> ConvertToHtml(string name) { - return ConvertToHtml(name, converter => converter); - } - - private IResult<string> ConvertToHtml(string name, Func<DocumentConverter, DocumentConverter> configure) { - return configure(new DocumentConverter()).ConvertToHtml(TestFilePath(name)); - } - - private string TestFilePath(string name) { - return Path.Combine("../../TestData", name); - } - } -} - diff --git a/dotnet/Mammoth.Tests/Mammoth.Tests.csproj b/dotnet/Mammoth.Tests/Mammoth.Tests.csproj deleted file mode 100644 index d561dde..0000000 --- a/dotnet/Mammoth.Tests/Mammoth.Tests.csproj +++ /dev/null @@ -1,77 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProjectGuid>{E9C3EA8B-FF3B-4E3E-8137-1510465200B5}</ProjectGuid> - <OutputType>Library</OutputType> - <RootNamespace>Mammoth.Tests</RootNamespace> - <AssemblyName>Mammoth.Tests</AssemblyName> - <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug</OutputPath> - <DefineConstants>DEBUG;</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <ConsolePause>false</ConsolePause> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>full</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release</OutputPath> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <ConsolePause>false</ConsolePause> - </PropertyGroup> - <ItemGroup> - <Reference Include="System" /> - <Reference Include="xunit.abstractions"> - <HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath> - </Reference> - <Reference Include="xunit.core"> - <HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.core.dll</HintPath> - </Reference> - <Reference Include="xunit.execution.desktop"> - <HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath> - </Reference> - <Reference Include="xunit.assert"> - <HintPath>..\packages\xunit.assert.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.assert.dll</HintPath> - </Reference> - </ItemGroup> - <ItemGroup> - <Compile Include="Properties\AssemblyInfo.cs" /> - <Compile Include="DocumentConverterTests.cs" /> - </ItemGroup> - <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> - <Import Project="..\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props')" /> - <ItemGroup> - <None Include="packages.config" /> - </ItemGroup> - <ItemGroup> - <EmbeddedResource Include="TestData\empty.docx" /> - <EmbeddedResource Include="TestData\endnotes.docx" /> - <EmbeddedResource Include="TestData\external-picture.docx" /> - <EmbeddedResource Include="TestData\footnote-hyperlink.docx" /> - <EmbeddedResource Include="TestData\footnotes.docx" /> - <EmbeddedResource Include="TestData\simple-list.docx" /> - <EmbeddedResource Include="TestData\single-paragraph.docx" /> - <EmbeddedResource Include="TestData\strikethrough.docx" /> - <EmbeddedResource Include="TestData\tables.docx" /> - <EmbeddedResource Include="TestData\text-box.docx" /> - <EmbeddedResource Include="TestData\tiny-picture.docx" /> - <EmbeddedResource Include="TestData\tiny-picture.png" /> - <EmbeddedResource Include="TestData\tiny-picture-custom-content-type.docx" /> - <EmbeddedResource Include="TestData\underline.docx" /> - <EmbeddedResource Include="TestData\utf8-bom.docx" /> - </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\Mammoth\Mammoth.csproj"> - <Project>{51C5CBD6-8809-4D5E-BABE-1787A16F5ED8}</Project> - <Name>Mammoth</Name> - </ProjectReference> - </ItemGroup> -</Project>
\ No newline at end of file diff --git a/dotnet/Mammoth.Tests/Properties/AssemblyInfo.cs b/dotnet/Mammoth.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 79596a3..0000000 --- a/dotnet/Mammoth.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle ("Mammoth.Tests")] -[assembly: AssemblyDescription ("")] -[assembly: AssemblyConfiguration ("")] -[assembly: AssemblyCompany ("")] -[assembly: AssemblyProduct ("")] -[assembly: AssemblyCopyright ("Michael Williamson")] -[assembly: AssemblyTrademark ("")] -[assembly: AssemblyCulture ("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion ("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] - diff --git a/dotnet/Mammoth.Tests/TestData b/dotnet/Mammoth.Tests/TestData deleted file mode 120000 index f8f6221..0000000 --- a/dotnet/Mammoth.Tests/TestData +++ /dev/null @@ -1 +0,0 @@ -../../src/test/resources/test-data
\ No newline at end of file diff --git a/dotnet/Mammoth.Tests/packages.config b/dotnet/Mammoth.Tests/packages.config deleted file mode 100644 index 69a4ec4..0000000 --- a/dotnet/Mammoth.Tests/packages.config +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="xunit" version="2.1.0" targetFramework="net45" /> - <package id="xunit.abstractions" version="2.0.0" targetFramework="net45" /> - <package id="xunit.assert" version="2.1.0" targetFramework="net45" /> - <package id="xunit.core" version="2.1.0" targetFramework="net45" /> - <package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" /> - <package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net45" /> -</packages>
\ No newline at end of file |
