11using Codeuctivity . OpenXmlToHtml ;
2- using OpenXmlPowerTools ;
3- using System . Collections . Generic ;
2+ using Codeuctivity . PuppeteerSharp ;
3+ using PdfSharp . Pdf . IO ;
44using System . IO ;
55using System . Threading . Tasks ;
6- using System . Xml . Linq ;
76using Xunit ;
87
98namespace OpenXmlToHtmlTests
@@ -13,9 +12,9 @@ public class OpenXmlToHtmlTests
1312 [ Theory ]
1413 [ InlineData ( "EmptyDocument.docx" , 0 ) ]
1514 [ InlineData ( "WingdingsSymbols.docx" , 71000 ) ]
16- [ InlineData ( "BasicTextFormated.docx" , 0 ) ]
17- [ InlineData ( "Images.docx" , 0 ) ]
18- public async Task ShouldConvertDocumentIntegrativeTest ( string testFileName , int allowedPixelErrorCount )
15+ [ InlineData ( "BasicTextFormated.docx" , 50 ) ]
16+ [ InlineData ( "Images.docx" , 5 ) ]
17+ public async Task ShouldConvertDocumentIntegrativeWithKnownAberrancyTest ( string testFileName , int allowedPixelErrorCount )
1918 {
2019 var sourceOpenXmlFilePath = $ "../../../TestInput/{ testFileName } ";
2120 var actualHtmlFilePath = Path . Combine ( Path . GetTempPath ( ) , $ "Actual{ testFileName } .html") ;
@@ -30,35 +29,30 @@ public async Task ShouldConvertDocumentIntegrativeTest(string testFileName, int
3029 await DocumentAsserter . AssertRenderedHtmlIsEqual ( actualHtmlFilePath , expectedHtmlFilePath , allowedPixelErrorCount ) ;
3130 }
3231
33-
34- [ Theory ]
35- [ InlineData ( "1" , "•1" , "Symbol" ) ]
36- [ InlineData ( "1" , "1" , "arial" ) ]
37- public void ShouldTranslateTextWithCustomGlyphToUnicode ( string original , string expectedEquivalent , string fontFamily )
32+ [ Fact ]
33+ public async Task ShouldConvertDocumentIntegrativeWithToExpectedPageQuantityTest ( )
3834 {
39- var currentStyle = new Dictionary < string , string > { { "font-family" , fontFamily } } ;
35+ var testFileName = "TwoPages.docx" ;
36+ var sourceOpenXmlFilePath = $ "../../../TestInput/{ testFileName } ";
37+ var actualHtmlFilePath = Path . Combine ( Path . GetTempPath ( ) , $ "Actual{ testFileName } .html") ;
4038
41- var WordprocessingTextSymbolToUnicodeHandler = new WordprocessingTextSymbolToUnicodeHandler ( ) ;
39+ if ( File . Exists ( actualHtmlFilePath ) )
40+ {
41+ File . Delete ( actualHtmlFilePath ) ;
42+ }
4243
43- var actual = WordprocessingTextSymbolToUnicodeHandler . TransformText ( original , currentStyle ) ;
44+ await OpenXmlToHtml . ConvertToHtmlAsync ( sourceOpenXmlFilePath , actualHtmlFilePath ) ;
4445
45- Assert . Equal ( expectedEquivalent , actual ) ;
46+ await using var chromiumRenderer = await Renderer . CreateAsync ( ) ;
47+ var pathPdfizedHtml = actualHtmlFilePath + ".pdf" ;
48+ await chromiumRenderer . ConvertHtmlToPdf ( actualHtmlFilePath , pathPdfizedHtml ) ;
49+ AssertPdfPageCount ( pathPdfizedHtml , 2 ) ;
4650 }
4751
48- [ Fact ]
49- public void ShouldTranslateSymbolsToUnicode ( )
52+ private static void AssertPdfPageCount ( string pathPdfizedHtml , int expectePageQuantity )
5053 {
51- var fontFamily = new Dictionary < string , string >
52- {
53- { "font-family" , "Symbol" }
54- } ;
55-
56- var symbolHandler = new SymbolHandler ( ) ;
57- var element = new XElement ( "symbol" , new XAttribute ( W . _char , "F0D7" ) ) ;
58-
59- var actual = symbolHandler . TransformSymbol ( element , fontFamily ) ;
60-
61- Assert . Equal ( "<span xmlns=\" http://www.w3.org/1999/xhtml\" >⋅</span>" , actual . ToString ( ) ) ;
54+ var pdfReader = PdfReader . Open ( pathPdfizedHtml , PdfDocumentOpenMode . ReadOnly ) ;
55+ Assert . Equal ( expectePageQuantity , pdfReader . PageCount ) ;
6256 }
6357 }
6458}
0 commit comments