@@ -45,6 +45,40 @@ public async Task ShouldConvertHtmlToPdf(string testFileName)
45
45
await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunning ( ) ;
46
46
}
47
47
48
+ [ Theory ]
49
+ [ InlineData ( "BasicTextFormatedInlineBackground.html" , false ) ]
50
+ [ InlineData ( "BasicTextFormatedInlineBackground.html" , true ) ]
51
+ public async Task ShouldConvertHtmlToPdfWithOptions ( string testFileName , bool printBackground )
52
+ {
53
+ var sourceHtmlFilePath = $ "../../../TestInput/{ testFileName } ";
54
+ var actualFilePath = Path . Combine ( Path . GetTempPath ( ) , $ "ActualConvertHtmlToPdf{ testFileName } .{ printBackground } .pdf") ;
55
+ var expectReferenceFilePath = $ "../../../ExpectedTestOutcome/ExpectedFromHtmlConvertHtmlToPdf{ testFileName } .{ printBackground } .png";
56
+
57
+ if ( File . Exists ( actualFilePath ) )
58
+ {
59
+ File . Delete ( actualFilePath ) ;
60
+ }
61
+
62
+ await using ( var chromiumRenderer = await Renderer . CreateAsync ( ) )
63
+ {
64
+ await chromiumRenderer . ConvertHtmlToPdf ( sourceHtmlFilePath , actualFilePath , new PdfOptions ( ) { PrintBackground = printBackground } ) ;
65
+
66
+ var actualImagePathDirectory = Path . Combine ( Path . GetTempPath ( ) , testFileName ) ;
67
+
68
+ using var rasterize = new Rasterizer ( ) ;
69
+
70
+ if ( ! IsRunningOnWslOrAzureOrMacos ( ) )
71
+ {
72
+ var actualImages = await rasterize . ConvertToPngAsync ( actualFilePath , actualImagePathDirectory ) ;
73
+ Assert . Single ( actualImages ) ;
74
+ // File.Copy(actualImages.Single(), expectReferenceFilePath, true);
75
+ DocumentAsserter . AssertImageIsEqual ( actualImages . Single ( ) , expectReferenceFilePath , 2000 ) ;
76
+ }
77
+ File . Delete ( actualFilePath ) ;
78
+ }
79
+ await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunning ( ) ;
80
+ }
81
+
48
82
private static bool IsRunningOnWslOrAzureOrMacos ( )
49
83
{
50
84
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) || RuntimeInformation . IsOSPlatform ( OSPlatform . FreeBSD ) )
@@ -88,6 +122,36 @@ public async Task ShouldConvertHtmlToPng(string testFileName)
88
122
await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunning ( ) ;
89
123
}
90
124
125
+ [ Theory ]
126
+ [ InlineData ( "BasicTextFormatedInlineBackground.html" , false , 11000 ) ]
127
+ [ InlineData ( "BasicTextFormatedInlineBackground.html" , true , 9500 ) ]
128
+ public async Task ShouldConvertHtmlToPngScreenshotOptions ( string testFileName , bool omitBackground , int allowedPixelDiff )
129
+ {
130
+ var sourceHtmlFilePath = $ "../../../TestInput/{ testFileName } ";
131
+ var actualFilePath = Path . Combine ( Path . GetTempPath ( ) , $ "ActualConvertHtmlToPng{ testFileName } .{ omitBackground } .png") ;
132
+ var expectReferenceFilePath = $ "../../../ExpectedTestOutcome/ExpectedConvertHtmlToPng{ testFileName } .{ omitBackground } .png";
133
+
134
+ if ( File . Exists ( actualFilePath ) )
135
+ {
136
+ File . Delete ( actualFilePath ) ;
137
+ }
138
+
139
+ await using ( var chromiumRenderer = await Renderer . CreateAsync ( ) )
140
+ {
141
+ ScreenshotOptions screenshotOptions = new ScreenshotOptions
142
+ {
143
+ OmitBackground = omitBackground
144
+ } ;
145
+
146
+ await chromiumRenderer . ConvertHtmlToPng ( sourceHtmlFilePath , actualFilePath , screenshotOptions ) ;
147
+ // File.Copy(actualFilePath, expectReferenceFilePath);
148
+ DocumentAsserter . AssertImageIsEqual ( actualFilePath , expectReferenceFilePath , allowedPixelDiff ) ;
149
+ }
150
+
151
+ File . Delete ( actualFilePath ) ;
152
+ await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunning ( ) ;
153
+ }
154
+
91
155
[ Fact ]
92
156
public async Task ShouldDisposeGracefull ( )
93
157
{
0 commit comments