(), Is.True);
}
+ }
- [Test]
- public void ConsecutiveParagraph_WithClosedTags_ShouldNotContinueStyle()
+ [Test]
+ public void ConsecutiveParagraph_WithUnclosedTags_ShouldContinueStyle()
+ {
+ var elements = converter.Parse("First paragraph in semi-italics
Second paragraph still italic but also in bold
");
+ Assert.That(elements, Has.Count.EqualTo(2));
+ using (Assert.EnterMultipleScope())
{
- // this should generate a new paragraph with its own style
- var elements = converter.Parse("First paragraph in italics
Second paragraph not in italic
");
- Assert.That(elements, Has.Count.EqualTo(2));
Assert.That(elements[0].Elements().Count, Is.EqualTo(2));
- Assert.That(elements[1].Elements().Count, Is.EqualTo(1));
- Assert.That(elements[1].FirstChild, Is.TypeOf(typeof(Run)));
-
- var runProperties = elements[1].FirstChild!.GetFirstChild();
- Assert.That(runProperties, Is.Null);
+ Assert.That(elements[1].Elements().Count, Is.EqualTo(2));
}
- [TestCase("Some\ntext
", ExpectedResult = 1)]
- [TestCase("Some bold\ntext
", ExpectedResult = 3)]
- [TestCase("\tSome bold\ntext
", ExpectedResult = 3)]
- [TestCase(" Some text
", ExpectedResult = 1)]
- public int Newline_ReturnsRunCount (string html)
- {
- var elements = converter.Parse(html);
- return elements[0].Elements().Count();
- }
+ var runProperties = elements[0].ChildElements[0].GetFirstChild();
+ Assert.That(runProperties, Is.Null);
- [TestCase(" < b >bold", ExpectedResult = "< b >bold")]
- [TestCase(" <3", ExpectedResult = "<3")]
- public string EntityNames_ShouldBeTreatedAsSimpleText (string html)
- {
- var elements = converter.Parse(html);
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements[0].ChildElements, Has.Count.EqualTo(1));
- Assert.That(elements[0].FirstChild, Is.TypeOf());
- return elements[0].FirstChild.InnerText;
- }
+ runProperties = elements[0].GetLastChild()!.GetFirstChild();
+ Assert.That(runProperties, Is.Not.Null);
+ Assert.That(runProperties.HasChild(), Is.True);
- [Test(Description = "Provided html is only whitespaces")]
- public void EmptyText_ShouldBeIgnored()
- {
- var elements = converter.Parse(" \n");
- Assert.That(elements, Is.Empty);
- }
+ runProperties = elements[1].FirstChild?.GetFirstChild();
+ Assert.That(runProperties, Is.Not.Null);
+ Assert.That(runProperties.HasChild(), Is.True);
+ Assert.That(runProperties.HasChild(), Is.False);
- [Test(Description = "Provided mainPart is null")]
- public void ProvidedMainPart_WithNull_ShouldFail()
- {
- Assert.Throws(() => new HtmlConverter((MainDocumentPart) null!));
- }
+ runProperties = elements[1].GetLastChild()!.GetFirstChild();
+ Assert.That(runProperties, Is.Not.Null);
+ Assert.That(runProperties.HasChild(), Is.True);
+ Assert.That(runProperties.HasChild(), Is.True);
+ }
- [Test(Description = "Provided mainPart.Document is empty")]
- public void ProvidedMainPartDocument_WithNull_ShouldBeAssigned()
- {
- using var generatedDocument = new MemoryStream();
- using var package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document);
- mainPart = package.MainDocumentPart!;
- mainPart = package.AddMainDocumentPart();
+ [Test]
+ public void ConsecutiveParagraph_WithClosedTags_ShouldNotContinueStyle()
+ {
+ // this should generate a new paragraph with its own style
+ var elements = converter.Parse("First paragraph in italics
Second paragraph not in italic
");
+ Assert.That(elements, Has.Count.EqualTo(2));
+ Assert.That(elements[0].Elements().Count, Is.EqualTo(2));
+ Assert.That(elements[1].Elements().Count, Is.EqualTo(1));
+ Assert.That(elements[1].FirstChild, Is.TypeOf(typeof(Run)));
+
+ var runProperties = elements[1].FirstChild!.GetFirstChild();
+ Assert.That(runProperties, Is.Null);
+ }
- Assert.That(mainPart.Document, Is.Null);
+ [TestCase("Some\ntext
", ExpectedResult = 1)]
+ [TestCase("Some bold\ntext
", ExpectedResult = 3)]
+ [TestCase("\tSome bold\ntext
", ExpectedResult = 3)]
+ [TestCase(" Some text
", ExpectedResult = 1)]
+ public int Newline_ReturnsRunCount (string html)
+ {
+ var elements = converter.Parse(html);
+ return elements[0].Elements().Count();
+ }
- var elements = new HtmlConverter(mainPart).Parse("Placeholder");
- Assert.That(elements, Is.Not.Empty);
- }
+ [TestCase(" < b >bold", ExpectedResult = "< b >bold")]
+ [TestCase(" <3", ExpectedResult = "<3")]
+ public string EntityNames_ShouldBeTreatedAsSimpleText (string html)
+ {
+ var elements = converter.Parse(html);
+ Assert.That(elements, Has.Count.EqualTo(1));
+ Assert.That(elements[0].ChildElements, Has.Count.EqualTo(1));
+ Assert.That(elements[0].FirstChild, Is.TypeOf());
+ return elements[0].FirstChild.InnerText;
+ }
+
+ [Test(Description = "Provided html is only whitespaces")]
+ public void EmptyText_ShouldBeIgnored()
+ {
+ var elements = converter.Parse(" \n");
+ Assert.That(elements, Is.Empty);
+ }
- [Test(Description = "Provided BaseImageUrl must be an absolute uri")]
- public void ProvidedBaseImageUrl_WithRelativeUrl_ShouldFail()
+ [Test(Description = "Provided mainPart is null")]
+ public void ProvidedMainPart_WithNull_ShouldFail()
+ {
+ Assert.Throws(() => new HtmlConverter((MainDocumentPart) null!));
+ }
+
+ [Test(Description = "Provided mainPart.Document is empty")]
+ public void ProvidedMainPartDocument_WithNull_ShouldBeAssigned()
+ {
+ using var generatedDocument = new MemoryStream();
+ using var package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document);
+ mainPart = package.MainDocumentPart!;
+ mainPart = package.AddMainDocumentPart();
+
+ Assert.That(mainPart.Document, Is.Null);
+
+ var elements = new HtmlConverter(mainPart).Parse("Placeholder");
+ Assert.That(elements, Is.Not.Empty);
+ }
+
+ [Test(Description = "Provided BaseImageUrl must be an absolute uri")]
+ public void ProvidedBaseImageUrl_WithRelativeUrl_ShouldFail()
+ {
+ Assert.Throws(() => new HtmlConverter(mainPart, new IO.DefaultWebRequest {
+ BaseImageUrl = new Uri("/path", UriKind.Relative)
+ }));
+ }
+
+ [Test]
+ public async Task LoadHtml_ThenParseFragment_ShouldInsertInCorrectPart()
+ {
+ var document = await converter.LoadDocumentAsync("""
+
+ Body content
+ """, TestContext.CurrentContext.CancellationToken);
+
+ var header = document.QuerySelector("header");
+ Assert.That(header, Is.Not.Null);
+ Assert.That(header.InnerHtml, Is.EqualTo("Header content"));
+
+ await converter.ParseHeader(header);
+ header.Remove();
+
+ Assert.That(document.InnerHtml.Trim(), Is.EqualTo("Body content"));
+
+ await converter.ParseBody(document);
+
+ using (Assert.EnterMultipleScope())
{
- Assert.Throws(() => new HtmlConverter(mainPart, new IO.DefaultWebRequest {
- BaseImageUrl = new Uri("/path", UriKind.Relative)
- }));
+ Assert.That(mainPart.HeaderParts.First().Header!.InnerText, Is.EqualTo("Header content"));
+ Assert.That(mainPart.Document!.Body!.InnerText, Is.EqualTo("Body content"));
}
}
+
+ [Test]
+ public void OverrideNodeProcessor_ShouldReplaceDefaultInterpreter()
+ {
+ var today = DateTime.Today;
+
+ var dateProcessor = new Mock();
+ dateProcessor.Setup(p => p.CanProcess(It.IsAny()))
+ .Returns(false);
+ dateProcessor.Setup(p => p.CanProcess(It.Is(
+ n => n.NodeName == "H2O-DATE")))
+ .Returns(true);
+
+ dateProcessor.Setup(p => p.Interpret(
+ It.IsAny(),
+ It.Is(n => n.NodeName == "H2O-DATE")))
+ .Returns([
+ new Run(new Text(today.ToShortDateString()))
+ ]);
+
+ converter.NodeProcessors.Add(dateProcessor.Object);
+
+ var elements = converter.Parse("Italics");
+ dateProcessor.Verify(p => p.CanProcess(It.IsAny()),
+ Times.Exactly(2), "Expected to be called for and ");
+
+ dateProcessor.Verify(p => p.Interpret(
+ It.IsAny(),
+ It.Is(n => n.NodeName == "H2O-DATE")), Times.Once());
+
+ Assert.That(elements, Has.Count.EqualTo(1));
+ Assert.That(elements[0].ChildElements, Has.Count.EqualTo(2));
+ Assert.That(elements[0].FirstChild?.InnerText, Is.EqualTo(today.ToShortDateString()));
+ Assert.That(elements[0].LastChild?.InnerText, Is.EqualTo("Italics"));
+ }
}
\ No newline at end of file
diff --git a/test/HtmlToOpenXml.Tests/TableTests.cs b/test/HtmlToOpenXml.Tests/TableTests.cs
deleted file mode 100644
index a265bfef..00000000
--- a/test/HtmlToOpenXml.Tests/TableTests.cs
+++ /dev/null
@@ -1,879 +0,0 @@
-using NUnit.Framework;
-using DocumentFormat.OpenXml.Wordprocessing;
-
-namespace HtmlToOpenXml.Tests
-{
- ///
- /// Tests for table or pre.
- ///
- [TestFixture]
- public class TableTests : HtmlConverterTestBase
- {
- [TestCase("", Description = "Row with no cells")]
- [TestCase("", Description = "No rows")]
- [TestCase("", Description = "No rows in any parts")]
- public void EmptyTable_ShouldBeIgnored(string html)
- {
- var elements = converter.Parse(html);
- Assert.That(elements, Is.Empty);
- }
-
- [Test(Description = "Empty cell should generate an empty Paragraph")]
- public void EmptyCell_ReturnsEmpty()
- {
- var elements = converter.Parse(@"");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
-
- var rows = elements[0].Elements();
- Assert.That(rows.Count(), Is.EqualTo(1));
- var cells = rows.First().Elements();
- Assert.That(cells.Count(), Is.EqualTo(2));
- Assert.That(cells.All(c => c.HasChild()), Is.True);
- Assert.That(cells.Last().Count(c => c is not TableCellProperties), Is.EqualTo(1));
- }
-
- [Test(Description = "Empty tfoot should be ignored")]
- public void EmptyTablePart_ShouldBeIgnored()
- {
- // table parts should be reordered
- var elements = converter.Parse(@"");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements[0], Is.TypeOf(typeof(Table)));
-
- var rows = elements[0].Elements();
- Assert.That(rows.Count(), Is.EqualTo(1));
- }
-
- [Test(Description = "Second row does not contains complete number of cells")]
- public void RowWithNoCell_ReturnsCompletelyFilledRow()
- {
- var elements = converter.Parse(@"
- | Cell 1.1 | Cell 1.2 | Cell 1.3 |
- | Cell 2.1 |
-
-
");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var rows = elements[0].Elements();
- Assert.That(rows.Count(), Is.EqualTo(2), "Row with no cells should be skipped");
- Assert.That(rows.Select(r => r.Elements().Count()),
- Has.All.EqualTo(3),
- "All rows should have the same number of cells");
- }
-
- [Test(Description = "Respect the order header-body-footer even if provided disordered")]
- public void DisorderedTableParts_ReturnsOrderedTable ()
- {
- // table parts should be reordered
- var elements = converter.Parse(@"
- | Body |
- | Header |
- | Footer |
-
");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements[0], Is.TypeOf(typeof(Table)));
-
- var rows = elements[0].Elements();
- Assert.That(rows.Count(), Is.EqualTo(3));
- using (Assert.EnterMultipleScope())
- {
- Assert.That(rows.ElementAt(0).InnerText, Is.EqualTo("Header"));
- Assert.That(rows.ElementAt(1).InnerText, Is.EqualTo("Body"));
- Assert.That(rows.ElementAt(2).InnerText, Is.EqualTo("Footer"));
- }
- }
-
- [TestCase(2u, 2)]
- [TestCase(1u, null)]
- [TestCase(0u, null)]
- public void ColSpan_ReturnsGridSpan(uint colSpan, int? expectedColSpan)
- {
- var elements = converter.Parse(@$"
- | Cell 1.1 |
- {"| Cell | ".Repeat(Math.Max(1, colSpan))}
-
");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var rows = elements[0].Elements();
- Assert.That(rows.Count(), Is.EqualTo(2));
-
- using (Assert.EnterMultipleScope())
- {
- Assert.That(rows.First().GetFirstChild()?
- .TableCellProperties?.GetFirstChild()?.Val?.Value, Is.EqualTo(expectedColSpan),
- $"Expected GridSpan={expectedColSpan}");
- Assert.That(rows.First().Elements().Count(), Is.EqualTo(1),
- "1st row should contain only 1 cell");
- Assert.That(rows.Last().Elements().Count(), Is.EqualTo(Math.Max(1, colSpan)),
- $"2nd row should contains {Math.Max(1, colSpan)} cells");
- }
- }
-
- [Test(Description = "rowSpan=0 should extend on all rows")]
- public void RowSpanZero_ReturnsExtendedToAllRows()
- {
- var elements = converter.Parse(@"
-
- | Cell 1.1 | Cell 1.2 | Cell 1.3 |
- | Cell 2.2 | Cell 2.3 |
- | Cell 3.2 | Cell 3.3 |
-
-
- | Cell 4.1 | Cell 4.2 | Cell 4.3 |
-
-
");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var rows = elements[0].Elements().ToArray();
- Assert.That(rows, Has.Length.EqualTo(4));
- using (Assert.EnterMultipleScope())
- {
- Assert.That(rows.Select(r => r.Elements().Count()),
- Has.All.EqualTo(3),
- "All rows should have the same number of cells");
- Assert.That(rows[0].GetFirstChild()?.TableCellProperties?
- .VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Restart));
- Assert.That(rows[1].GetFirstChild()?.TableCellProperties?
- .VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Continue));
- Assert.That(rows[2].GetFirstChild()?.TableCellProperties?
- .VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Continue));
- Assert.That(rows[3].GetFirstChild()?.TableCellProperties?
- .VerticalMerge?.Val?.Value, Is.Null,
- "Row on tfoot should not continue the span");
- }
- }
-
- [Test]
- public void RowSpan_ReturnsVerticalMerge()
- {
- var elements = converter.Parse(@"
- | Cell 1.1 | Cell 1.2 | Cell 1.3 |
- | Cell 2.1 | Cell 2.2 | Cell 2.3 |
- | Cell 3.1 | Cell 3.3 |
-
");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var rows = elements[0].Elements();
- Assert.That(rows.Count(), Is.EqualTo(3));
- Assert.That(rows.Select(r => r.Elements().Count()),
- Has.All.EqualTo(3),
- "All rows should have the same number of cells");
-
- Assert.That(rows.ElementAt(1).Elements().ElementAt(1)?.TableCellProperties?.VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Restart));
- Assert.That(rows.ElementAt(2).Elements().ElementAt(1)?.TableCellProperties?.VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Continue));
- }
-
- [Test]
- public void RowAndColumnSpan_ReturnsVerticalMergeAndGridSpan()
- {
- var elements = converter.Parse(@"
- | Cell 1.1 | Cell 1.3 |
- | Cell 2.3 |
- | Cell 3.1 | Cell 3.2 | Cell 3.3 |
-
");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var rows = elements[0].Elements();
- Assert.That(rows.Count(), Is.EqualTo(3));
- Assert.That(rows.Take(2).Select(r => r.Elements().Count()),
- Has.All.EqualTo(2),
- "1st and 2nd rows should have 2 cells");
- Assert.That(rows.Last().Elements().Count(),
- Is.EqualTo(3),
- "3rd row should have 3 cells");
- Assert.That(rows.First().GetFirstChild()?.TableCellProperties?.GridSpan?.Val?.Value, Is.EqualTo(2));
- Assert.That(rows.First().GetFirstChild()?.TableCellProperties?.VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Restart));
-
- Assert.That(rows.ElementAt(1).GetFirstChild()?.TableCellProperties?.GridSpan?.Val?.Value, Is.EqualTo(2));
- Assert.That(rows.ElementAt(1).GetFirstChild()?.TableCellProperties?.VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Continue));
- }
-
- [TestCase("tb-lr", ExpectedResult = "btLr")]
- [TestCase("vertical-lr", ExpectedResult ="btLr")]
- [TestCase("tb-rl", ExpectedResult = "tbRl")]
- [TestCase("vertical-rl", ExpectedResult = "tbRl")]
- public string? VerticalText_ReturnsTableCellWithTextAlignment(string direction)
- {
- var elements = converter.Parse(@$"");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var rows = elements[0].Elements();
- Assert.That(rows.Count(), Is.EqualTo(1));
- Assert.That(rows.First().Elements().Count(), Is.EqualTo(1));
- var cell = rows.First().GetFirstChild();
- Assert.That(cell?.TableCellProperties?.TableCellVerticalAlignment?.Val?.Value, Is.EqualTo(TableVerticalAlignmentValues.Center));
- return cell?.TableCellProperties?.TextDirection?.Val?.InnerText;
- }
-
- [Test(Description = "Table padding is not supported in OpenXml, only margin")]
- public void CellPadding_ReturnsTableWithCellMargin()
- {
- var elements = converter.Parse(@$"");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var cellMargin = elements[0].GetFirstChild()?.TableCellMarginDefault;
- Assert.That(cellMargin, Is.Not.Null);
-
- using (Assert.EnterMultipleScope())
- {
- Assert.That(cellMargin.TableCellLeftMargin?.Width?.Value, Is.EqualTo(29));
- Assert.That(cellMargin.TableCellRightMargin?.Width?.Value, Is.EqualTo(29));
- Assert.That(cellMargin.TopMargin?.Width?.Value, Is.EqualTo("29"));
- Assert.That(cellMargin.BottomMargin?.Width?.Value, Is.EqualTo("29"));
- }
- }
-
- [Test]
- public void CellSpacing_ReturnsTableCellWithSpacing()
- {
- var elements = converter.Parse(@$"");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var cellSpacing = elements[0].GetFirstChild()?.TableCellSpacing;
- Assert.That(cellSpacing?.Type?.Value, Is.EqualTo(TableWidthUnitValues.Dxa));
- Assert.That(cellSpacing?.Width?.Value, Is.EqualTo("29"));
- }
-
- [TestCaseSource(nameof(BorderWidthCases))]
- public void HtmlBorders_ShouldSucceed(string borderAtrribute, IEnumerable? expectedBorderValue, IEnumerable? expectedBorderWidth)
- {
- // we specify a style which doesn't handle borders
- converter.HtmlStyles.AddStyle(new Style {
- StyleId = "NoStyle",
- Type = StyleValues.Table
- });
- var elements = converter.Parse($@"");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var borders = elements[0].GetFirstChild()?.TableBorders;
- if (expectedBorderValue is null)
- {
- Assert.That(borders, Is.Null);
- return;
- }
-
- Assert.That(borders, Is.Not.Null);
- Assert.That(borders.HasChild(), Is.True);
- Assert.That(new string?[] { borders.TopBorder?.Val?.InnerText,
- borders.LeftBorder?.Val?.InnerText,
- borders.RightBorder?.Val?.InnerText,
- borders.BottomBorder?.Val?.InnerText,
- borders.InsideHorizontalBorder?.Val?.InnerText,
- borders.InsideVerticalBorder?.Val?.InnerText },
- Is.EquivalentTo(expectedBorderValue));
-
- if (expectedBorderWidth is null)
- {
- Assert.That(borders.Elements().Any(b => b.Size?.HasValue == true), Is.False);
- }
- else
- {
- Assert.That(new uint?[] { borders.TopBorder?.Size?.Value,
- borders.LeftBorder?.Size?.Value,
- borders.RightBorder?.Size?.Value,
- borders.BottomBorder?.Size?.Value,
- borders.InsideHorizontalBorder?.Size?.Value,
- borders.InsideVerticalBorder?.Size?.Value },
- Is.EquivalentTo(expectedBorderWidth));
- }
- }
-
- static readonly object[] BorderWidthCases =
- [
- // unset border <> border=0
- new object[] { "", null!, null! },
- // Negative border should be considered as zero
- new object[] { "border='-1'",
- new string[] { "none", "none", "none", "none", "none", "none" }, null! },
- new object[] { "border='0'",
- new string[] { "none", "none", "none", "none", "none", "none" }, null! },
- new object[] { "border='1'",
- new string[] { "none", "none", "none", "none", "single", "single" },
- new uint?[] { null, null, null, null, 14, 14 } },
- new object[] { "style='border:1px;border-bottom:3px dashed'",
- new string[] { "single", "single", "single", "dashed", null!, null! },
- new uint?[] { 6, 6, 6, 18, null, null } }
- ];
-
- [TestCase("above", 0, 1)]
- [TestCase("below", 1, 0)]
- public void TableCaption_ReturnsPositionedParagraph(string position, int captionPos, int tablePos)
- {
- converter.TableCaptionPosition = new (position);
- var elements = converter.Parse(@$"
- Some table caption
- | Cell 1.1 |
-
");
- Assert.That(elements, Has.Count.EqualTo(2));
- Assert.That(elements[captionPos], Is.TypeOf());
- Assert.That(elements[tablePos], Is.TypeOf());
- var p = (Paragraph) elements[captionPos];
- var runs = p.Elements();
- Assert.That(runs.Count(), Is.AtLeast(4));
-
- using (Assert.EnterMultipleScope())
- {
- Assert.That(p.ParagraphProperties?.ParagraphStyleId?.Val?.Value, Is.EqualTo(converter.HtmlStyles.DefaultStyles.CaptionStyle));
- Assert.That(runs.First().HasChild(), Is.True);
- Assert.That(runs.ElementAt(1).HasChild(), Is.True);
- Assert.That(runs.ElementAt(2).HasChild(), Is.True);
- }
- using (Assert.EnterMultipleScope())
- {
- Assert.That(runs.First().GetFirstChild()?.FieldCharType?.Value, Is.EqualTo(FieldCharValues.Begin));
- Assert.That(runs.ElementAt(1).GetFirstChild()?.InnerText, Is.EqualTo("SEQ TABLE \\* ARABIC"));
- Assert.That(runs.ElementAt(2).GetFirstChild()?.FieldCharType?.Value, Is.EqualTo(FieldCharValues.End));
- Assert.That(runs.Last().InnerText, Is.EqualTo(" Some table caption"));
- }
- }
-
- [TestCase("right", ExpectedResult = "right")]
- [TestCase("", ExpectedResult = "center")]
- public string? TableCaptionAlign_ReturnsPositionedParagraph_AlignedWithTable(string alignment)
- {
- var elements = converter.Parse(@$"
- Some table caption
- | Cell 1.1 |
-
");
-
- Assert.That(elements, Has.Count.EqualTo(2));
- var caption = (Paragraph) elements[1];
- return caption.ParagraphProperties?.Justification?.Val?.ToString();
- }
-
- [TestCase("align='right'", ExpectedResult = "right")]
- [TestCase("style='justify-self:center'", ExpectedResult = "center")]
- [TestCase("style='margin-left:auto'", ExpectedResult = "right")]
- [TestCase("style='margin-left:auto;margin-right:auto'", ExpectedResult = "center")]
- public string? TableAlign_ReturnsTableJustification(string style)
- {
- var elements = converter.Parse(@$"");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- return elements[0].GetFirstChild()?.TableJustification?.Val?.ToString();
- }
-
- [TestCase("", ExpectedResult = "right")]
- [TestCase("justify-self:center", ExpectedResult = "center")]
- public string? NestedTableAlign_ReturnsTableOrParentJustification(string tableStyle)
- {
- var elements = converter.Parse(@$"");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- return elements[0].GetFirstChild()?.TableJustification?.Val?.ToString();
- }
-
- [Test]
- public void EmptyTableCaption_ShouldBeIgnored()
- {
- var elements = converter.Parse(@$"");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements[0], Is.TypeOf());
- }
-
- [Test]
- public void PreAsTable_ReturnsTableWithPreservedWhitespaces()
- {
- const string preformattedText = @"
- ^__^
- (oo)\_______
- (__)\ )\/\
- ||----w |
- || ||";
-
- converter.RenderPreAsTable = true;
- var elements = converter.Parse(@$"
-
-{preformattedText}");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var tableProps = elements[0].GetFirstChild();
- Assert.That(tableProps, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- Assert.That(tableProps.GetFirstChild()?.Val?.Value, Is.EqualTo(converter.HtmlStyles.DefaultStyles.PreTableStyle));
- Assert.That(tableProps.GetFirstChild()?.Type?.Value, Is.EqualTo(TableWidthUnitValues.Auto));
- Assert.That(tableProps.GetFirstChild()?.Width?.Value, Is.EqualTo("0"));
- }
-
- var rows = elements[0].Elements();
- Assert.That(rows.Count(), Is.EqualTo(1));
- var cells = rows.First().Elements();
- Assert.That(cells.Count(), Is.EqualTo(1));
- var cell = cells.First();
- using (Assert.EnterMultipleScope())
- {
- Assert.That(cell.TableCellProperties?.TableCellBorders?.ChildElements.Count(), Is.EqualTo(4));
- Assert.That(cell.TableCellProperties?.TableCellBorders?.ChildElements, Has.All.InstanceOf());
- Assert.That(cell.TableCellProperties?.TableCellBorders?.Elements().All(b => b.Val?.Value == BorderValues.Single), Is.True);
- }
-
- var run = cell.GetFirstChild()?.GetFirstChild();
- Assert.That(run, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- var odds = run.ChildElements.Where((item, index) => index % 2 != 0);
- Assert.That(odds, Has.All.TypeOf());
- Assert.That(run.ChildElements.ElementAt(0).InnerText, Is.EqualTo(" ^__^"));
- Assert.That(run.ChildElements.ElementAt(2).InnerText, Is.EqualTo(" (oo)\\_______"));
- Assert.That(run.ChildElements.ElementAt(4).InnerText, Is.EqualTo(" (__)\\ )\\/\\"));
- Assert.That(run.ChildElements.ElementAt(6).InnerText, Is.EqualTo(" ||----w |"));
- Assert.That(run.ChildElements.ElementAt(8).InnerText, Is.EqualTo(" || ||"));
- }
- }
-
- [Test]
- public void RowStyle_ReturnsRunCellsWithCascadedStyle()
- {
- var elements = converter.Parse(@$"");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
-
- var row = elements[0].GetFirstChild();
- Assert.That(row, Is.Not.Null);
- Assert.That(row.TableRowProperties?.GetFirstChild()?.Val?.Value, Is.EqualTo(1800));
-
- var cell = row.GetFirstChild();
- Assert.That(cell, Is.Not.Null);
- Assert.That(cell.TableCellProperties, Is.Not.Null);
- Assert.That(cell.TableCellProperties.Shading?.Fill?.Value, Is.EqualTo("C0C0C0"));
-
- var runProperties = cell.GetFirstChild()?.GetFirstChild()?.RunProperties;
- Assert.That(runProperties?.Shading, Is.Null);
- }
-
- [Test(Description = "Ancestor block background-color must not paint table cell runs")]
- public void ParentDivBackground_ShouldNotCascadeIntoCell()
- {
- var elements = converter.Parse(@"");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Is.All.TypeOf());
-
- var cell = elements[0].GetFirstChild()?.GetFirstChild();
- Assert.That(cell, Is.Not.Null);
- var runProperties = cell.GetFirstChild()?.GetFirstChild()?.RunProperties;
- Assert.That(runProperties, Is.Null);
- }
-
- [Test(Description = "Explicit span background inside a cell is kept even when a parent div has a fill")]
- public void ParentDivBackground_SpanInCell_KeepsOwnShading()
- {
- var elements = converter.Parse(@"");
-
- var cell = elements[0].GetFirstChild()?.GetFirstChild();
- var runProperties = cell?.GetFirstChild()?.GetFirstChild()?.RunProperties;
- Assert.That(runProperties?.Shading?.Fill?.Value, Is.EqualTo("FFFF00"));
- }
-
- [Test(Description = "Background on a div inside a cell still applies to the run")]
- public void InnerDivBackground_InsideCell_StillCascadesToRun()
- {
- var elements = converter.Parse(@"");
-
- var cell = elements[0].GetFirstChild()?.GetFirstChild();
- var runProperties = cell?.GetFirstChild()?.GetFirstChild()?.RunProperties;
- Assert.That(runProperties?.Shading?.Fill?.Value, Is.EqualTo("00FF00"));
- }
-
- [Test]
- public void CellStyle_ReturnsRunWithCascadeStyle()
- {
- var elements = converter.Parse(@$"");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var cell = elements[0].GetFirstChild()?.GetFirstChild();
- Assert.That(cell, Is.Not.Null);
- var runProperties = cell.GetFirstChild()?.GetFirstChild()?.RunProperties;
- Assert.That(runProperties, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- Assert.That(runProperties.Bold, Is.Not.Null);
- Assert.That(runProperties.Italic, Is.Not.Null);
- }
- using (Assert.EnterMultipleScope())
- {
- // normally, Val should be null
- if (runProperties.Bold.Val is not null)
- Assert.That(runProperties.Bold.Val, Is.True);
- if (runProperties.Italic.Val is not null)
- Assert.That(runProperties.Italic.Val, Is.True);
- }
- }
-
- [Test]
- public void NestedTable_ReturnsTableInsideTable()
- {
- var elements = converter.Parse(@$"");
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- Assert.That(elements[0].GetFirstChild()?.Elements().Count(), Is.EqualTo(1));
- var cell = elements[0].GetFirstChild()?.GetFirstChild();
- Assert.That(cell, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- Assert.That(cell.HasChild(), Is.True);
- Assert.That(cell.HasChild(), Is.True, "Word requires at least a paragraph");
- Assert.That(cell.LastChild, Is.TypeOf(), "Word disallow to ends a cell with a Table");
- }
- }
-
- [Test]
- public void Colstyle_ReturnsStyleAppliedOnCell()
- {
- var elements = converter.Parse(@$"
-
-
-
-
- | Cell 1.1 | Cell 1.2 |
-
");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var columns = elements[0].GetFirstChild()?.Elements();
- Assert.That(columns, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- Assert.That(columns.Count(), Is.EqualTo(2));
- Assert.That(columns.First().Width?.Value, Is.EqualTo("1500"));
- Assert.That(columns.Last().Width?.Value, Is.EqualTo("750"));
- }
-
- var cells = elements[0].GetFirstChild()?.Elements();
- Assert.That(cells, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- Assert.That(cells.Count(), Is.EqualTo(2));
- Assert.That(cells.First().TableCellProperties?.TableCellBorders, Is.Null);
- Assert.That(cells.Last().TableCellProperties?.TableCellBorders, Is.Not.Null);
- }
- }
-
- [Test]
- public void ColWithSpan_ReturnsStyleAppliedOnMultipleCells()
- {
- var elements = converter.Parse(@$"
-
-
-
-
- | Cell 1.1 | Cell 1.2 | Cell 1.3 |
-
");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var columns = elements[0].GetFirstChild()?.Elements();
- Assert.That(columns, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- Assert.That(columns.Count(), Is.EqualTo(3));
- //Assert.That(columns.First().Width?.Value, Is.EqualTo("1500"));
- //Assert.That(columns.ElementAt(1).Width?.Value, Is.EqualTo("1500"));
- //Assert.That(columns.Last().Width?.Value, Is.EqualTo("750"));
- }
-
- var cells = elements[0].GetFirstChild()?.Elements();
- Assert.That(cells, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- Assert.That(cells.Count(), Is.EqualTo(3));
- Assert.That(cells.First().GetFirstChild()?.ParagraphProperties?.Justification?.Val?.Value, Is.EqualTo(JustificationValues.Right));
- Assert.That(cells.ElementAt(1).GetFirstChild()?.ParagraphProperties?.Justification?.Val?.Value, Is.EqualTo(JustificationValues.Right));
- Assert.That(cells.Last().GetFirstChild()?.ParagraphProperties?.Justification?.Val, Is.Null);
- }
- }
-
- [Test(Description = "Table row contains more cell than specified col")]
- public void IncompleteColStyle_ShouldNotThrow()
- {
- Assert.DoesNotThrow(() => converter.Parse(@$"
-
-
-
- | Cell 1.1 | Cell 1.2 |
-
"));
- }
-
- [Test(Description = "Cell with multiple runs")]
- public void CellWithMultipleDivs_ReturnsOneCellWithMultipleParagraphs()
- {
- var elements = converter.Parse(@$"");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var cells = elements[0].GetFirstChild()?.Elements();
- Assert.That(cells?.Count(), Is.EqualTo(1));
- Assert.That(cells.First().Elements().Count(), Is.EqualTo(2));
- }
-
- [Test(Description = "Prevent Word to merge two consecutive tables")]
- public void ConsecutiveTables_ReturnsTablesWithPlaceholderParagraphInBetween()
- {
- var elements = converter.Parse(@"
-
- ");
- Assert.That(elements, Has.Count.EqualTo(3));
- using (Assert.EnterMultipleScope())
- {
- Assert.That(elements[0], Is.TypeOf());
- Assert.That(elements[1], Is.TypeOf());
- Assert.That(elements[2], Is.TypeOf());
- }
- }
-
- [Test(Description = "Insert the empty paragraph on right location, based on combinated rowSpan and colSpan #59")]
- public void DoubleRowSpanSameLine_ShouldSucceed()
- {
- var elements = converter.Parse(@"
-
- | Cell 1.1 |
- Cell 1.2 |
- Cell 1.3 |
-
-
- | Cell 2.2 |
-
-
");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- Assert.That(elements[0].GetFirstChild()?.Elements().Count(), Is.EqualTo(4));
-
- var rows = elements[0].Elements();
- Assert.That(rows.Count(), Is.EqualTo(2));
- Assert.That(rows.Select(r => r.Elements().Count()),
- Has.All.EqualTo(3),
- "All should have 3 cells");
- Assert.That(rows.First().GetFirstChild()?.TableCellProperties?.GridSpan?.Val?.Value, Is.EqualTo(2));
- Assert.That(rows.First().GetFirstChild()?.TableCellProperties?.VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Restart));
- Assert.That(rows.First().GetLastChild()?.TableCellProperties?.VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Restart));
-
- Assert.That(rows.ElementAt(1).GetFirstChild()?.TableCellProperties?.GridSpan?.Val?.Value, Is.EqualTo(2));
- Assert.That(rows.ElementAt(1).GetFirstChild()?.TableCellProperties?.VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Continue));
- Assert.That(rows.ElementAt(1).GetLastChild()?.TableCellProperties?.VerticalMerge?.Val?.Value, Is.EqualTo(MergedCellValues.Continue));
- }
-
- [Test(Description = "Cell borders should not be applied on inner runs #156")]
- public void CellBorders_ShouldNotPropagate_OnRuns()
- {
- var elements = converter.Parse(@"");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var cells = elements[0].GetFirstChild()?.Elements();
- Assert.That(cells?.Count(), Is.EqualTo(1));
- Assert.That(cells.First().TableCellProperties?.TableCellBorders, Is.Not.Null);
- var paragraphs = cells.First().Elements();
- Assert.That(paragraphs.Count(), Is.EqualTo(1));
- var runs = paragraphs.First().Elements();
- Assert.That(runs.Count(), Is.EqualTo(1));
- Assert.That(runs.First().RunProperties?.Border, Is.Null);
- }
-
- [TestCase("100%", "pct", Expressions.BlockElementExpression.FullPageWidthPct)]
- [TestCase("auto", "auto", "0")]
- [TestCase("120px", "dxa", "1800")]
- [TestCase("", "pct", Expressions.BlockElementExpression.FullPageWidthPct, Description = "Defaults to 100%")]
- public void Width_ReturnsRefineTableWidth(string width, string expectedUnit, string expectedValue)
- {
- var elements = converter.Parse(@$"");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var tableWidth = elements[0].GetFirstChild()?.TableWidth;
- Assert.That(tableWidth, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- Assert.That(tableWidth?.Type?.Value, Is.EqualTo(new TableWidthUnitValues(expectedUnit)));
- Assert.That(tableWidth?.Width?.Value, Is.EqualTo(expectedValue));
- }
- }
-
- [Test]
- public void ColWithPercentWidth_ReturnsRefineTableWidth()
- {
- var elements = converter.Parse(@"
-
-
-
- | Cell 1 |
- Cell 2 |
-
-
-
");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
- var tableWidth = elements[0].GetFirstChild()?.TableWidth;
- Assert.That(tableWidth, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- Assert.That(tableWidth?.Type?.Value, Is.EqualTo(TableWidthUnitValues.Pct));
- Assert.That(tableWidth?.Width?.Value, Is.EqualTo("3750"));
- }
-
- var columns = elements[0].GetFirstChild()?.Elements();
- Assert.That(columns, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- Assert.That(columns.Count(), Is.EqualTo(2));
- Assert.That(columns.First().Width?.Value, Is.EqualTo("1269"));
- Assert.That(columns.Last().Width?.Value, Is.EqualTo("8365"));
- }
-
- var cells = elements[0].GetFirstChild()?.Elements();
- Assert.That(cells, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- Assert.That(cells.Count(), Is.EqualTo(2));
- // width on cell are on 5000 basis
- Assert.That(cells.First().TableCellProperties?.TableCellWidth?.Width?.Value, Is.EqualTo("659"));
- Assert.That(cells.Last().TableCellProperties?.TableCellWidth?.Width?.Value, Is.EqualTo("4346"));
- }
- }
-
- [Test]
- public void CellPadding_ReturnsTableCellMargin()
- {
- var elements = converter.Parse(@"");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
-
- var cells = elements[0].GetFirstChild()?.Elements();
- Assert.That(cells, Is.Not.Null);
- using (Assert.EnterMultipleScope())
- {
- Assert.That(cells.Count(), Is.EqualTo(2));
- Assert.That(cells.First().TableCellProperties?.TableCellMargin, Is.Not.Null);
- Assert.That(cells.Last().TableCellProperties?.TableCellMargin, Is.Null,
- "Only fixed unit are supported");
- }
-
- var cellMargin = cells.First().TableCellProperties?.TableCellMargin;
- using (Assert.EnterMultipleScope())
- {
- Assert.That(cellMargin.LeftMargin?.Width?.Value, Is.EqualTo("75"));
- Assert.That(cellMargin.RightMargin?.Width?.Value, Is.EqualTo("75"));
- Assert.That(cellMargin.TopMargin?.Width?.Value, Is.EqualTo("300"));
- Assert.That(cellMargin.BottomMargin?.Width?.Value, Is.EqualTo("300"));
- }
- }
-
- [Test]
- public void CellWidth_UsesLegacyWidthAttributeWithoutUnit()
- {
- var elements = converter.Parse(@"");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
-
- var cells = elements[0].GetFirstChild()?.Elements();
- Assert.That(cells, Is.Not.Null);
-
- using (Assert.EnterMultipleScope())
- {
- Assert.That(cells.Count(), Is.EqualTo(2));
- Assert.That(cells.First().TableCellProperties?.TableCellWidth, Is.Not.Null);
- Assert.That(cells.Last().TableCellProperties?.TableCellWidth, Is.Not.Null);
- }
-
- var firstWidth = cells.First().TableCellProperties?.TableCellWidth;
- var lastWidth = cells.Last().TableCellProperties?.TableCellWidth;
-
- using (Assert.EnterMultipleScope())
- {
- Assert.That(firstWidth?.Width?.Value, Is.EqualTo("150"));
- Assert.That(lastWidth?.Width?.Value, Is.EqualTo("1350"));
- }
- }
-
- [Test]
- public void CellWidth_UsesLegacyWidthAttributeWithPercentage()
- {
- var elements = converter.Parse(@"");
-
- Assert.That(elements, Has.Count.EqualTo(1));
- Assert.That(elements, Has.All.TypeOf());
-
- var cells = elements[0].GetFirstChild()?.Elements();
- Assert.That(cells, Is.Not.Null);
-
- using (Assert.EnterMultipleScope())
- {
- Assert.That(cells.Count(), Is.EqualTo(2));
- Assert.That(cells.First().TableCellProperties?.TableCellWidth, Is.Not.Null);
- Assert.That(cells.Last().TableCellProperties?.TableCellWidth, Is.Not.Null);
- }
-
- var firstWidth = cells.First().TableCellProperties?.TableCellWidth;
- var lastWidth = cells.Last().TableCellProperties?.TableCellWidth;
-
- using (Assert.EnterMultipleScope())
- {
- Assert.That(firstWidth?.Width?.Value, Is.EqualTo("500"));
- Assert.That(lastWidth?.Width?.Value, Is.EqualTo("4500"));
- }
- }
- }
-}
diff --git a/test/HtmlToOpenXml.Tests/Utilities/MockHttpMessageHandler.cs b/test/HtmlToOpenXml.Tests/Utilities/MockHttpMessageHandler.cs
index f964b44c..d2bb98b5 100644
--- a/test/HtmlToOpenXml.Tests/Utilities/MockHttpMessageHandler.cs
+++ b/test/HtmlToOpenXml.Tests/Utilities/MockHttpMessageHandler.cs
@@ -1,35 +1,35 @@
-/*
- * Copyright (c) 2017 Deal Stream sàrl. All rights reserved
+/* Copyright (C) Olivier Nizet https://github.com/onizet/html2openxml
+ * Licensed under the MIT License.
+ * Please see the LICENSE file in the project root fo full license information
*/
using Moq;
using Moq.Protected;
using System.Net.Http;
-namespace HtmlToOpenXml.Tests
+namespace HtmlToOpenXml.Tests;
+
+public class MockHttpMessageHandler
{
- public class MockHttpMessageHandler
- {
- private readonly Mock mockMessageHandler;
+ private readonly Mock mockMessageHandler;
- public MockHttpMessageHandler()
- {
- mockMessageHandler = new Mock();
- mockMessageHandler.Protected()
- .Setup>("SendAsync", ItExpr.IsAny(), ItExpr.IsAny())
- .ReturnsAsync(new HttpResponseMessage());
- }
+ public MockHttpMessageHandler()
+ {
+ mockMessageHandler = new Mock();
+ mockMessageHandler.Protected()
+ .Setup>("SendAsync", ItExpr.IsAny(), ItExpr.IsAny())
+ .ReturnsAsync(new HttpResponseMessage());
+ }
- public IO.IWebRequest GetWebRequest()
- {
- return new IO.DefaultWebRequest(new HttpClient(mockMessageHandler.Object));
- }
+ public IO.IWebRequest GetWebRequest()
+ {
+ return new IO.DefaultWebRequest(new HttpClient(mockMessageHandler.Object));
+ }
- public void AssertNeverCalled()
- {
- mockMessageHandler.Protected()
- .Verify("SendAsync", Times.Never(),
- ItExpr.IsAny(), ItExpr.IsAny());
- }
+ public void AssertNeverCalled()
+ {
+ mockMessageHandler.Protected()
+ .Verify("SendAsync", Times.Never(),
+ ItExpr.IsAny(), ItExpr.IsAny());
}
-}
\ No newline at end of file
+}
diff --git a/test/HtmlToOpenXml.Tests/Utilities/OpenXmlExtensions.cs b/test/HtmlToOpenXml.Tests/Utilities/OpenXmlExtensions.cs
index 3167cfd2..5337caaa 100755
--- a/test/HtmlToOpenXml.Tests/Utilities/OpenXmlExtensions.cs
+++ b/test/HtmlToOpenXml.Tests/Utilities/OpenXmlExtensions.cs
@@ -1,13 +1,6 @@
-/* Copyright (C) Olivier Nizet https://github.com/onizet/html2openxml - All Rights Reserved
- *
- * This source is subject to the Microsoft Permissive License.
- * Please see the License.txt file for more information.
- * All other rights reserved.
- *
- * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
- * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
- * PARTICULAR PURPOSE.
+/* Copyright (C) Olivier Nizet https://github.com/onizet/html2openxml
+ * Licensed under the MIT License.
+ * Please see the LICENSE file in the project root fo full license information
*/
using DocumentFormat.OpenXml;
diff --git a/test/HtmlToOpenXml.Tests/Utilities/ProxyHttpMessageHandler.cs b/test/HtmlToOpenXml.Tests/Utilities/ProxyHttpMessageHandler.cs
index fdd08bf6..3c70b9ed 100644
--- a/test/HtmlToOpenXml.Tests/Utilities/ProxyHttpMessageHandler.cs
+++ b/test/HtmlToOpenXml.Tests/Utilities/ProxyHttpMessageHandler.cs
@@ -1,22 +1,22 @@
-/*
- * Copyright (c) 2017 Deal Stream sàrl. All rights reserved
+/* Copyright (C) Olivier Nizet https://github.com/onizet/html2openxml
+ * Licensed under the MIT License.
+ * Please see the LICENSE file in the project root fo full license information
*/
using System.Net.Http;
-namespace HtmlToOpenXml.Tests
+namespace HtmlToOpenXml.Tests;
+
+public class ProxyHttpMessageHandler : HttpMessageHandler
{
- public class ProxyHttpMessageHandler : HttpMessageHandler
- {
- private readonly Func> _getResponseFunc;
+ private readonly Func> _getResponseFunc;
- public ProxyHttpMessageHandler(Func> getResponseFunc)
- {
- _getResponseFunc = getResponseFunc;
- }
+ public ProxyHttpMessageHandler(Func> getResponseFunc)
+ {
+ _getResponseFunc = getResponseFunc;
+ }
- protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
- {
- return await _getResponseFunc(request.RequestUri!);
- }
+ protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
+ {
+ return await _getResponseFunc(request.RequestUri!);
}
-}
\ No newline at end of file
+}
diff --git a/test/HtmlToOpenXml.Tests/Utilities/ResourceHelper.cs b/test/HtmlToOpenXml.Tests/Utilities/ResourceHelper.cs
index d1f8ed93..9d484570 100644
--- a/test/HtmlToOpenXml.Tests/Utilities/ResourceHelper.cs
+++ b/test/HtmlToOpenXml.Tests/Utilities/ResourceHelper.cs
@@ -1,41 +1,41 @@
-/*
- * Copyright (c) 2017 Deal Stream sàrl. All rights reserved
+/* Copyright (C) Olivier Nizet https://github.com/onizet/html2openxml
+ * Licensed under the MIT License.
+ * Please see the LICENSE file in the project root fo full license information
*/
using System.Reflection;
using System.Resources;
-namespace HtmlToOpenXml.Tests
+namespace HtmlToOpenXml.Tests;
+
+///
+/// Helper class to get an embedded resources.
+///
+public static class ResourceHelper
{
- ///
- /// Helper class to get an embedded resources.
- ///
- public static class ResourceHelper
+ public static string GetString(string resourceName)
{
- public static string GetString(string resourceName)
- {
- return GetString(typeof(ResourceHelper).GetTypeInfo().Assembly, resourceName);
- }
+ return GetString(typeof(ResourceHelper).GetTypeInfo().Assembly, resourceName);
+ }
- public static string GetString(Assembly assembly, string resourceName)
+ public static string GetString(Assembly assembly, string resourceName)
+ {
+ using (var stream = GetStream(assembly, resourceName))
{
- using (var stream = GetStream(assembly, resourceName))
- {
- using (var reader = new StreamReader(stream))
- return reader.ReadToEnd();
- }
+ using (var reader = new StreamReader(stream))
+ return reader.ReadToEnd();
}
+ }
- public static Stream GetStream(string resourceName)
- {
- return GetStream(typeof(ResourceHelper).GetTypeInfo().Assembly, resourceName);
- }
+ public static Stream GetStream(string resourceName)
+ {
+ return GetStream(typeof(ResourceHelper).GetTypeInfo().Assembly, resourceName);
+ }
- public static Stream GetStream(Assembly assembly, string resourceName)
- {
- var stream = assembly.GetManifestResourceStream(assembly.GetName().Name + "." + resourceName)
- ?? throw new MissingManifestResourceException($"Requested resource `{resourceName}` was not found in the assembly `{assembly}`.");
+ public static Stream GetStream(Assembly assembly, string resourceName)
+ {
+ var stream = assembly.GetManifestResourceStream(assembly.GetName().Name + "." + resourceName)
+ ?? throw new MissingManifestResourceException($"Requested resource `{resourceName}` was not found in the assembly `{assembly}`.");
- return stream;
- }
+ return stream;
}
-}
\ No newline at end of file
+}
diff --git a/test/HtmlToOpenXml.Tests/Utilities/StringExtensions.cs b/test/HtmlToOpenXml.Tests/Utilities/StringExtensions.cs
index 2b8a4fb9..11cea578 100644
--- a/test/HtmlToOpenXml.Tests/Utilities/StringExtensions.cs
+++ b/test/HtmlToOpenXml.Tests/Utilities/StringExtensions.cs
@@ -1,33 +1,24 @@
-/* Copyright (C) Olivier Nizet https://github.com/onizet/html2openxml - All Rights Reserved
- *
- * This source is subject to the Microsoft Permissive License.
- * Please see the License.txt file for more information.
- * All other rights reserved.
- *
- * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
- * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
- * PARTICULAR PURPOSE.
+/* Copyright (C) Olivier Nizet https://github.com/onizet/html2openxml
+ * Licensed under the MIT License.
+ * Please see the LICENSE file in the project root fo full license information
*/
+namespace HtmlToOpenXml.Tests;
-namespace HtmlToOpenXml.Tests
+///
+/// Helper class that provide some extension methods to String.
+///
+[System.Diagnostics.DebuggerStepThrough]
+static class StringExtensions
{
- ///
- /// Helper class that provide some extension methods to String.
- ///
- [System.Diagnostics.DebuggerStepThrough]
- static class StringExtensions
+ public static string Repeat(this string text, uint n)
{
- public static string Repeat(this string text, uint n)
+ var textAsSpan = text.AsSpan();
+ var span = new Span(new char[textAsSpan.Length * (int)n]);
+ for (var i = 0; i < n; i++)
{
- var textAsSpan = text.AsSpan();
- var span = new Span(new char[textAsSpan.Length * (int)n]);
- for (var i = 0; i < n; i++)
- {
- textAsSpan.CopyTo(span.Slice(i * textAsSpan.Length, textAsSpan.Length));
- }
-
- return span.ToString();
+ textAsSpan.CopyTo(span.Slice(i * textAsSpan.Length, textAsSpan.Length));
}
+
+ return span.ToString();
}
}