1
1
using Codeuctivity . HtmlRenderer ;
2
2
using Codeuctivity . HtmlRendererTests . Infrastructure ;
3
- using Codeuctivity . PdfjsSharp ;
4
- using Jering . Javascript . NodeJS ;
5
3
using PuppeteerSharp ;
6
4
using System ;
7
5
using System . IO ;
8
- using System . Linq ;
9
6
using System . Runtime . InteropServices ;
10
7
using System . Threading . Tasks ;
11
8
using Xunit ;
12
9
13
10
namespace Codeuctivity . HtmlRendererTests
14
11
{
15
- public class RendererTests : IDisposable
12
+ public class RendererTests
16
13
{
17
- private bool disposedValue ;
18
-
19
14
public RendererTests ( )
20
15
{
21
- Rasterize = new Rasterizer ( ) ;
22
16
}
23
17
24
- public Rasterizer Rasterize { get ; private set ; }
25
-
26
18
[ Theory ]
27
19
[ InlineData ( "BasicTextFormatted.html" ) ]
28
20
public async Task ShouldConvertHtmlToPdf ( string testFileName )
@@ -44,14 +36,12 @@ public async Task ShouldConvertHtmlToPdf(string testFileName)
44
36
45
37
if ( ! IsRunningOnAzureOrMacos ( ) )
46
38
{
47
- var actualImages = await Rasterize . ConvertToPngAsync ( actualFilePath , actualImagePathDirectory ) ;
48
- Assert . Single ( actualImages ) ;
49
- // File.Copy(actualImages.Single(), expectReferenceFilePath, true);
50
- DocumentAsserter . AssertImageIsEqual ( actualImages . Single ( ) , expectReferenceFilePath , 8000 ) ;
39
+ PDFtoImage . Conversion . SavePng ( actualImagePathDirectory , await File . ReadAllBytesAsync ( actualFilePath ) ) ;
40
+ DocumentAsserter . AssertImageIsEqual ( actualImagePathDirectory , expectReferenceFilePath , 8080 ) ;
51
41
}
52
42
File . Delete ( actualFilePath ) ;
53
43
}
54
- await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunning ( ) ;
44
+ await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunningExceptExpectedOrphanedBackgroundChromeProcesses ( ) ;
55
45
}
56
46
57
47
[ Theory ]
@@ -72,26 +62,16 @@ public async Task ShouldConvertHtmlToPdfWithOptions(string testFileName, bool pr
72
62
{
73
63
await chromiumRenderer . ConvertHtmlToPdf ( sourceHtmlFilePath , actualFilePath , new PdfOptions ( ) { PrintBackground = printBackground } ) ;
74
64
75
- var actualImagePathDirectory = Path . Combine ( Path . GetTempPath ( ) , testFileName ) ;
65
+ var actualImagePathDirectory = Path . Combine ( Path . GetTempPath ( ) , testFileName + ".png" ) ;
76
66
77
67
if ( ! IsRunningOnAzureOrMacos ( ) )
78
68
{
79
- try
80
- {
81
- var actualImages = await Rasterize . ConvertToPngAsync ( actualFilePath , actualImagePathDirectory ) ;
82
- Assert . Single ( actualImages ) ;
83
- // File.Copy(actualImages.Single(), expectReferenceFilePath, true);
84
- DocumentAsserter . AssertImageIsEqual ( actualImages . Single ( ) , expectReferenceFilePath , allowedPixelDiff ) ;
85
- }
86
- catch ( InvocationException ex )
87
- {
88
- // Working around issue in Jering.Javascript.NodeJS, silencing false positive failing
89
- Assert . True ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) , ex . Message ) ;
90
- }
69
+ PDFtoImage . Conversion . SavePng ( actualImagePathDirectory , await File . ReadAllBytesAsync ( actualFilePath ) ) ;
70
+ DocumentAsserter . AssertImageIsEqual ( actualImagePathDirectory , expectReferenceFilePath , allowedPixelDiff ) ;
91
71
}
92
72
File . Delete ( actualFilePath ) ;
93
73
}
94
- await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunning ( ) ;
74
+ await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunningExceptExpectedOrphanedBackgroundChromeProcesses ( ) ;
95
75
}
96
76
97
77
private static bool IsRunningOnAzureOrMacos ( )
@@ -133,7 +113,7 @@ public async Task ShouldConvertHtmlToPng(string testFileName)
133
113
}
134
114
135
115
File . Delete ( actualFilePath ) ;
136
- await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunning ( ) ;
116
+ await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunningExceptExpectedOrphanedBackgroundChromeProcesses ( ) ;
137
117
}
138
118
139
119
[ Theory ]
@@ -158,12 +138,11 @@ public async Task ShouldConvertHtmlToPngScreenshotOptions(string testFileName, b
158
138
} ;
159
139
160
140
await chromiumRenderer . ConvertHtmlToPng ( sourceHtmlFilePath , actualFilePath , screenshotOptions ) ;
161
- // File.Copy(actualFilePath, expectReferenceFilePath, true);
162
141
DocumentAsserter . AssertImageIsEqual ( actualFilePath , expectReferenceFilePath , allowedPixelDiff ) ;
163
142
}
164
143
165
144
File . Delete ( actualFilePath ) ;
166
- await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunning ( ) ;
145
+ await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunningExceptExpectedOrphanedBackgroundChromeProcesses ( ) ;
167
146
}
168
147
169
148
[ Theory ]
@@ -189,13 +168,12 @@ public async Task ShouldConvertHtmlToPngBufferOptions(string testFileName, bool
189
168
190
169
var fileContent = await File . ReadAllTextAsync ( sourceHtmlFilePath ) ;
191
170
var pngData = await chromiumRenderer . ConvertHtmlStringToPngData ( fileContent , screenshotOptions ) ;
192
- // File.Copy(actualFilePath, expectReferenceFilePath, true);
193
171
await File . WriteAllBytesAsync ( actualFilePath , pngData ) ;
194
172
DocumentAsserter . AssertImageIsEqual ( actualFilePath , expectReferenceFilePath , allowedPixelDiff ) ;
195
173
}
196
174
197
175
File . Delete ( actualFilePath ) ;
198
- await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunning ( ) ;
176
+ await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunningExceptExpectedOrphanedBackgroundChromeProcesses ( ) ;
199
177
}
200
178
201
179
[ Fact ]
@@ -232,26 +210,7 @@ public async Task ShouldConvertHtmlToPngNoSandbox(string testFileName)
232
210
}
233
211
234
212
File . Delete ( actualFilePath ) ;
235
- await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunning ( ) ;
236
- }
237
-
238
- protected virtual void Dispose ( bool disposing )
239
- {
240
- if ( ! disposedValue )
241
- {
242
- if ( disposing )
243
- {
244
- Rasterize ? . Dispose ( ) ;
245
- }
246
-
247
- disposedValue = true ;
248
- }
249
- }
250
-
251
- public void Dispose ( )
252
- {
253
- Dispose ( disposing : true ) ;
254
- GC . SuppressFinalize ( this ) ;
213
+ await ChromiumProcessDisposedAsserter . AssertNoChromiumProcessIsRunningExceptExpectedOrphanedBackgroundChromeProcesses ( ) ;
255
214
}
256
215
}
257
216
}
0 commit comments