@@ -13,62 +13,110 @@ public void Setup()
1313 {
1414 Directory . Delete ( TestOutputDir , true ) ;
1515 }
16+
1617 Directory . CreateDirectory ( TestOutputDir ) ;
1718 }
1819
1920 [ Test ]
20- public void TestConvertPdfToDocx ( )
21+ public async Task TestConvertPdfToDocx ( )
2122 {
2223 var outputFile = Path . Combine ( TestOutputDir , "simple.docx" ) ;
2324 var inputFile = Path . Combine ( Directory . GetCurrentDirectory ( ) , "../../../../" , "test_files" , "simple.pdf" ) ;
2425
25- Run ( $ "{ ApiToken } { outputFile } { inputFile } ", inputFile ) ;
26+ await Program . Main ( [ ApiToken , outputFile , inputFile ] ) ;
27+
28+ Assert . IsTrue ( File . Exists ( outputFile ) , "Output file was not created." ) ;
29+ }
30+
31+ [ Test ]
32+ public async Task TestMergePdfs ( )
33+ {
34+ var outputFile = Path . Combine ( TestOutputDir , "simple.pdf" ) ;
35+ var inputFile1 = Path . Combine ( Directory . GetCurrentDirectory ( ) , "../../../../" , "test_files" , "simple.pdf" ) ;
36+ var inputFile2 = Path . Combine ( Directory . GetCurrentDirectory ( ) , "../../../../" , "test_files" , "invoice.pdf" ) ;
37+
38+ await Program . Main ( [ ApiToken , TestOutputDir , inputFile1 , inputFile2 , "pdf" , "merge" ] ) ;
39+
2640 Assert . IsTrue ( File . Exists ( outputFile ) , "Output file was not created." ) ;
2741 }
2842
2943 [ Test ]
30- public void TestMergePdfs ( )
44+ public async Task TestMergeMutiplePdfs ( )
3145 {
3246 var outputFile = Path . Combine ( TestOutputDir , "simple.pdf" ) ;
3347 var inputFile1 = Path . Combine ( Directory . GetCurrentDirectory ( ) , "../../../../" , "test_files" , "simple.pdf" ) ;
3448 var inputFile2 = Path . Combine ( Directory . GetCurrentDirectory ( ) , "../../../../" , "test_files" , "invoice.pdf" ) ;
35- Run ( $ "{ ApiToken } { outputFile } { inputFile1 } { inputFile2 } pdf merge", $ "{ inputFile1 } { Environment . NewLine } { inputFile2 } { Environment . NewLine } ") ;
49+ var inputFile3 = Path . Combine ( Directory . GetCurrentDirectory ( ) , "../../../../" , "test_files" , "invoice.pdf" ) ;
50+
51+ await Program . Main ( [ ApiToken , TestOutputDir , inputFile1 , inputFile2 , inputFile3 , "pdf" , "merge" ] ) ;
3652
3753 Assert . IsTrue ( File . Exists ( outputFile ) , "Output file was not created." ) ;
3854 }
3955
4056 [ Test ]
41- public void TestAddWatermarkToPdf ( )
57+ public async Task TestAddWatermarkToPdf ( )
4258 {
4359 var outputFile = Path . Combine ( TestOutputDir , "watermark.pdf" ) ;
4460 var inputFile = Path . Combine ( Directory . GetCurrentDirectory ( ) , "../../../../" , "test_files" , "simple.pdf" ) ;
45- Run ( $ "{ ApiToken } { outputFile } { inputFile } pdf watermark Text=Confidential FileName=watermark", inputFile ) ;
61+
62+ await Program . Main ( [ ApiToken , TestOutputDir , inputFile , "pdf" , "watermark" , "Text=Confidential" , "FileName=watermark" ] ) ;
63+
4664
4765 Assert . IsTrue ( File . Exists ( outputFile ) , "Output file was not created." ) ;
4866 }
4967
5068 [ Test ]
51- public void TestProtectPdfWithPassword ( )
69+ public async Task TestProtectPdfWithPassword ( )
5270 {
5371 var outputFile = Path . Combine ( TestOutputDir , "protected.pdf" ) ;
5472 var inputFile = Path . Combine ( Directory . GetCurrentDirectory ( ) , "../../../../" , "test_files" , "simple.pdf" ) ;
55- Run ( $ "{ ApiToken } { outputFile } { inputFile } pdf protect UserPassword=1234 OwnerPassword=abcd FileName=protected", inputFile ) ;
56-
73+
74+ await Program . Main ( [ ApiToken , TestOutputDir , inputFile , "pdf" , "protect" , "UserPassword=1234" , "OwnerPassword=abcd" , "FileName=protected" ] ) ;
75+
5776 Assert . IsTrue ( File . Exists ( outputFile ) , "Output file was not created." ) ;
5877 }
5978
60- private void Run ( string arguments , string inputFiles = "" )
79+ [ Test ]
80+ public async Task TestPdfToPngWithResolution ( )
6181 {
62- var originalIn = Console . In ;
63- try
64- {
65- Console . SetIn ( new StringReader ( inputFiles ) ) ;
66- Program . Main ( arguments . Split ( ) ) . GetAwaiter ( ) . GetResult ( ) ;
67- }
68- finally
69- {
70- // Restore the original input
71- Console . SetIn ( originalIn ) ;
72- }
82+ var inputFile = Path . Combine ( Directory . GetCurrentDirectory ( ) , "../../../../" , "test_files" , "simple.pdf" ) ;
83+
84+ await Program . Main ( [ ApiToken , TestOutputDir , inputFile , "pdf" , "png" , "Resolution=300" ] ) ;
85+
86+ Assert . IsTrue ( File . Exists ( outputFolder ) , "Output file was not created." ) ;
87+ }
88+
89+ [ Test ]
90+ public async Task TestPdfToExtractImages ( )
91+ {
92+ var inputFile = Path . Combine ( Directory . GetCurrentDirectory ( ) , "../../../../" , "test_files" , "simple.pdf" ) ;
93+
94+ await Program . Main ( [ ApiToken , TestOutputDir , inputFile , "pdf" , "extract-images" ] ) ;
95+
96+ Assert . IsTrue ( File . Exists ( outputFolder ) , "Output file was not created." ) ;
97+ }
98+
99+ [ Test ]
100+ public async Task TestPdfToExtractImagesError ( )
101+ {
102+ var outputFolder = Path . Combine ( TestOutputDir , "watermark.pdf" ) ;
103+ var inputFile = Path . Combine ( Directory . GetCurrentDirectory ( ) , "../../../../" , "test_files" , "simple.pdf" ) ;
104+
105+ await Program . Main ( [ ApiToken , TestOutputDir , inputFile , "pdf" , "extract-images" ] ) ;
106+
107+ Should fail
108+ Assert . IsTrue ( File . Exists ( outputFolder ) , "Output file was not created." ) ;
109+ }
110+
111+ [ Test ]
112+ public async Task TestWebToPdf ( )
113+ {
114+ var outputFolder = Path . Combine ( TestOutputDir , "watermark.pdf" ) ;
115+ var inputFile = Path . Combine ( Directory . GetCurrentDirectory ( ) , "../../../../" , "test_files" , "simple.pdf" ) ;
116+
117+ await Program . Main ( [ ApiToken , TestOutputDir , "" , "web" , "pdf" , "url=https://www.google.com" ] ) ;
118+
119+
120+ Assert . IsTrue ( File . Exists ( outputFolder ) , "Output file was not created." ) ;
73121 }
74122}
0 commit comments