using Xunit; using System.IO; using Xunit.Sdk; using System; 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()), "

"); } // TODO: simple list [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"), "

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