From 45e530dceda42282fae56b4c4f5fa7865f57899d Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 4 Jun 2016 16:03:56 +0100 Subject: Remove dotnet (use submodule from dotnet repo instead) --- dotnet/Mammoth.Tests/DocumentConverterTests.cs | 214 ------------------------- 1 file changed, 214 deletions(-) delete mode 100644 dotnet/Mammoth.Tests/DocumentConverterTests.cs (limited to 'dotnet/Mammoth.Tests/DocumentConverterTests.cs') 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"), - "

Walking on imported air

"); - } - - [Fact] - public void CanReadFilesWithUtf8Bom() { - AssertSuccessfulConversion( - ConvertToHtml("utf8-bom.docx"), - "

This XML has a byte order mark.

"); - } - - [Fact] - public void EmptyParagraphsAreIgnoredByDefault() { - AssertSuccessfulConversion( - ConvertToHtml("empty.docx"), - ""); - } - - [Fact] - public void EmptyParagraphsArePreservedIfIgnoreEmptyParagraphsIsFalse() { - AssertSuccessfulConversion( - ConvertToHtml("empty.docx", converter => converter.PreserveEmptyParagraphs()), - "

"); - } - - [Fact] - public void SimpleListIsConvertedToListElements() { - AssertSuccessfulConversion( - ConvertToHtml("simple-list.docx"), - ""); - } - - [Fact] - public void WordTablesAreConvertedToHtmlTables() { - AssertSuccessfulConversion( - ConvertToHtml("tables.docx"), - "

Above

" + - "" + - "" + - "" + - "

Top left

Top right

Bottom left

Bottom right

" + - "

Below

"); - } - - [Fact] - public void InlineImagesAreIncludedInOutput() { - AssertSuccessfulConversion( - ConvertToHtml("tiny-picture.docx"), - "

"); - } - - [Fact] - public void ImagesStoredOutsideOfDocumentAreIncludedInOutput() { - AssertSuccessfulConversion( - ConvertToHtml("external-picture.docx"), - "

"); - } - - [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"), - "

"); - } - - [Fact] - public void FootnotesAreAppendedToText() { - AssertSuccessfulConversion( - ConvertToHtml("footnotes.docx", mammoth => mammoth.IdPrefix("doc-42-")), - "

Ouch" + - "[1]." + - "[2]

" + - "
  1. A tachyon walks into a bar. ↑

  2. " + - "
  3. Fin. ↑

"); - } - - [Fact] - public void EndNotesAreAppendedToText() { - AssertSuccessfulConversion( - ConvertToHtml("endnotes.docx", mammoth => mammoth.IdPrefix("doc-42-")), - "

Ouch" + - "[1]." + - "[2]

" + - "
  1. A tachyon walks into a bar. ↑

  2. " + - "
  3. Fin. ↑

"); - } - - [Fact] - public void RelationshipsAreReadForEachFileContainingBodyXml() { - AssertSuccessfulConversion( - ConvertToHtml("footnote-hyperlink.docx", mammoth => mammoth.IdPrefix("doc-42-")), - - "

[1]

" + - "
  1. Example ↑

"); - } - - [Fact] - public void TextBoxesAreRead() { - AssertSuccessfulConversion( - ConvertToHtml("text-box.docx"), - "

Datum plane

"); - } - - [Fact] - public void CanUseCustomStyleMap() { - AssertSuccessfulConversion( - ConvertToHtml("underline.docx", mammoth => mammoth.AddStyleMap("u => em")), - "

The Sunset Tree

"); - } - - [Fact] - public void MostRecentlyAddedStyleMapTakesPrecedence() { - AssertSuccessfulConversion( - ConvertToHtml("underline.docx", mammoth => mammoth.AddStyleMap("u => em").AddStyleMap("u => strong")), - "

The Sunset Tree

"); - } - - [Fact] - public void RulesFromPreviouslyAddedStyleMapsStillTakeEffectIfNotOverridden() { - AssertSuccessfulConversion( - ConvertToHtml("underline.docx", mammoth => mammoth.AddStyleMap("u => em").AddStyleMap("strike => del")), - "

The Sunset Tree

"); - } - - [Fact] - public void ErrorIsRaisedIfStyleMapCannotBeParsed() { - var exception = Assert.ThrowsAny(() => - 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("

Apple

Banana

", 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 result, string expectedValue) { - if (result.Warnings.Count > 0) { - throw new XunitException("Unexpected warnings: " + string.Join(", ", result.Warnings)); - } - Assert.Equal(expectedValue, result.Value); - } - - private IResult ConvertToHtml(string name) { - return ConvertToHtml(name, converter => converter); - } - - private IResult ConvertToHtml(string name, Func configure) { - return configure(new DocumentConverter()).ConvertToHtml(TestFilePath(name)); - } - - private string TestFilePath(string name) { - return Path.Combine("../../TestData", name); - } - } -} - -- cgit v1.2.3