1+ using System ;
2+ using System . IO ;
3+ using System . Linq ;
4+ using System . Runtime . InteropServices ;
5+ using Xunit ;
6+
7+ namespace PdfAValidatorTestCore2 . _2
8+ {
9+ public static class PdfAValidatorTest
10+ {
11+ [ Fact ]
12+ public static void ShouldUnpackNewDirectoryInTempdirectory ( )
13+ {
14+ var listOfDirectoriesInTempWithoutVeraPdf = Directory . GetDirectories ( Path . GetTempPath ( ) ) ;
15+ using ( var pdfAValidator = new PdfAValidator . PdfAValidator ( ) )
16+ {
17+ pdfAValidator . Validate ( @"./TestPdfFiles/FromLibreOffice.pdf" ) ;
18+ AssertVeraPdfBinCreation ( listOfDirectoriesInTempWithoutVeraPdf , pdfAValidator ) ;
19+ }
20+ var listOfDirectoriesInTempAfterVeraPdf = Directory . GetDirectories ( Path . GetTempPath ( ) ) ;
21+ Assert . Equal ( listOfDirectoriesInTempAfterVeraPdf . Length , listOfDirectoriesInTempWithoutVeraPdf . Length ) ;
22+ }
23+
24+ [ Fact ]
25+ public static void ShouldDetectCompliantPdfA ( )
26+ {
27+ using ( var pdfAValidator = new PdfAValidator . PdfAValidator ( ) )
28+ {
29+ Assert . True ( File . Exists ( @"./TestPdfFiles/FromLibreOffice.pdf" ) ) ;
30+ var result = pdfAValidator . Validate ( @"./TestPdfFiles/FromLibreOffice.pdf" ) ;
31+ Assert . True ( result ) ;
32+ }
33+ }
34+
35+ [ Fact ]
36+ public static void ShouldGetDetailedReportFromPdfA ( )
37+ {
38+ using ( var pdfAValidator = new PdfAValidator . PdfAValidator ( ) )
39+ {
40+ Assert . True ( File . Exists ( @"./TestPdfFiles/FromLibreOffice.pdf" ) ) ;
41+ var result = pdfAValidator . ValidateWithDetailedReport ( @"./TestPdfFiles/FromLibreOffice.pdf" ) ;
42+ Assert . True ( result . jobs . job . validationReport . isCompliant ) ;
43+ Assert . True ( result . jobs . job . validationReport . profileName == "PDF/A-1A validation profile" ) ;
44+ }
45+ }
46+
47+ [ Fact ]
48+ public static void ShouldDetectNonCompliantPdfA ( )
49+ {
50+ using ( var pdfAValidator = new PdfAValidator . PdfAValidator ( ) )
51+ {
52+ Assert . True ( File . Exists ( @"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf" ) ) ;
53+ var result = pdfAValidator . Validate ( @"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf" ) ;
54+ Assert . False ( result ) ;
55+ }
56+ }
57+
58+ [ Fact ]
59+ public static void ShouldGetDetailedReportFromNonCompliantPdfA ( )
60+ {
61+ using ( var pdfAValidator = new PdfAValidator . PdfAValidator ( ) )
62+ {
63+ Assert . True ( File . Exists ( @"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf" ) ) ;
64+ var result = pdfAValidator . ValidateWithDetailedReport ( @"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf" ) ;
65+ Assert . False ( result . jobs . job . validationReport . isCompliant ) ;
66+ Assert . True ( result . jobs . job . validationReport . profileName == "PDF/A-1B validation profile" ) ;
67+ }
68+ }
69+
70+ [ Fact ]
71+ public static void ShouldWorkWithCustomJavaAndVeraPdfLocation ( )
72+ {
73+ // Using default ctor to get verapdf and java bins for the test
74+ var listOfDirectoriesInTempWithoutVeraPdf = Directory . GetDirectories ( Path . GetTempPath ( ) ) ;
75+ using ( var pdfAValidatorPrepareBins = new PdfAValidator . PdfAValidator ( ) )
76+ {
77+ {
78+ pdfAValidatorPrepareBins . Validate ( @"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf" ) ;
79+ using ( var pdfAValidator = new PdfAValidator . PdfAValidator ( pdfAValidatorPrepareBins . VeraPdfStartScript , pdfAValidatorPrepareBins . PathJava ) )
80+ {
81+ AssertVeraPdfBinCreation ( listOfDirectoriesInTempWithoutVeraPdf , pdfAValidator ) ;
82+ Assert . True ( File . Exists ( @"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf" ) ) ;
83+ var result = pdfAValidator . Validate ( @"./TestPdfFiles/FromLibreOfficeNonPdfA.pdf" ) ;
84+ Assert . False ( result ) ;
85+ }
86+ }
87+ }
88+ var listOfDirectoriesInTempAfterVeraPdf = Directory . GetDirectories ( Path . GetTempPath ( ) ) ;
89+ Assert . Equal ( listOfDirectoriesInTempAfterVeraPdf . Length , listOfDirectoriesInTempWithoutVeraPdf . Length ) ;
90+ }
91+
92+ private static void AssertVeraPdfBinCreation ( string [ ] listOfDirectoriesInTempWithoutVeraPdf , PdfAValidator . PdfAValidator pdfAValidator )
93+ {
94+ var listOfDirectoriesInTempWithVeraPdf = Directory . GetDirectories ( Path . GetTempPath ( ) ) ;
95+ var newDirectories = listOfDirectoriesInTempWithVeraPdf . Except ( listOfDirectoriesInTempWithoutVeraPdf ) ;
96+
97+ Assert . Single ( newDirectories ) ;
98+ var scriptPath = pdfAValidator . VeraPdfStartScript ;
99+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
100+ {
101+ Assert . Equal ( ".bat" , scriptPath . Substring ( scriptPath . Length - 4 ) ) ;
102+ }
103+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
104+ {
105+ Assert . Equal ( "verapdf" , scriptPath . Substring ( scriptPath . Length - 7 ) ) ;
106+ }
107+ Assert . True ( File . Exists ( scriptPath ) , scriptPath + " does not exist." ) ;
108+ }
109+ }
110+ }
0 commit comments