@@ -64,7 +64,7 @@ public void Throws_SingleCertificateName_File_KeyNotFound()
64
64
Mock . Of < ICertificateFileLoader > ( ) ,
65
65
Mock . Of < ICertificateStoreLoader > ( ) ) ;
66
66
67
- var exception = Assert . Throws < InvalidOperationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
67
+ var exception = Assert . Throws < CertificateConfigurationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
68
68
Assert . Equal ( "No certificate named Certificate2 found in configuration" , exception . Message ) ;
69
69
}
70
70
@@ -81,19 +81,18 @@ public void Throws_SingleCertificateName_File_FileNotFound()
81
81
} )
82
82
. Build ( ) ;
83
83
84
- var exception = new Exception ( ) ;
85
-
86
84
var certificateFileLoader = new Mock < ICertificateFileLoader > ( ) ;
87
85
certificateFileLoader
88
86
. Setup ( loader => loader . Load ( "Certificate1.pfx" , "Password1" , It . IsAny < X509KeyStorageFlags > ( ) ) )
89
- . Callback ( ( ) => throw exception ) ;
87
+ . Callback ( ( ) => throw new Exception ( nameof ( Throws_SingleCertificateName_File_FileNotFound ) ) ) ;
90
88
91
89
var certificateLoader = new CertificateLoader (
92
90
configuration . GetSection ( "Certificates" ) ,
93
91
certificateFileLoader . Object ,
94
92
Mock . Of < ICertificateStoreLoader > ( ) ) ;
95
93
96
- Assert . Same ( exception , Assert . Throws < Exception > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ) ;
94
+ var exception = Assert . Throws < CertificateConfigurationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
95
+ Assert . Equal ( $ "Failed to load certificate from file 'Certificate1.pfx': { nameof ( Throws_SingleCertificateName_File_FileNotFound ) } ", exception . Message ) ;
97
96
}
98
97
99
98
[ Fact ]
@@ -147,7 +146,7 @@ public void Throws_SingleCertificateName_Store_KeyNotFound()
147
146
Mock . Of < ICertificateFileLoader > ( ) ,
148
147
Mock . Of < ICertificateStoreLoader > ( ) ) ;
149
148
150
- var exception = Assert . Throws < InvalidOperationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
149
+ var exception = Assert . Throws < CertificateConfigurationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
151
150
Assert . Equal ( "No certificate named Certificate2 found in configuration" , exception . Message ) ;
152
151
}
153
152
@@ -256,7 +255,7 @@ public void Throws_MultipleCertificateNames_File_KeyNotFound(string certificateN
256
255
certificateFileLoader . Object ,
257
256
Mock . Of < ICertificateStoreLoader > ( ) ) ;
258
257
259
- var exception = Assert . Throws < InvalidOperationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
258
+ var exception = Assert . Throws < CertificateConfigurationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
260
259
Assert . Equal ( "No certificate named NotFound found in configuration" , exception . Message ) ;
261
260
}
262
261
@@ -279,22 +278,22 @@ public void Throws_MultipleCertificateNames_File_FileNotFound(string certificate
279
278
. Build ( ) ;
280
279
281
280
var certificate1 = new X509Certificate2 ( ) ;
282
- var exception = new Exception ( ) ;
283
281
284
282
var certificateFileLoader = new Mock < ICertificateFileLoader > ( ) ;
285
283
certificateFileLoader
286
284
. Setup ( loader => loader . Load ( "Certificate1.pfx" , "Password1" , It . IsAny < X509KeyStorageFlags > ( ) ) )
287
285
. Returns ( certificate1 ) ;
288
286
certificateFileLoader
289
287
. Setup ( loader => loader . Load ( "Certificate2.pfx" , "Password2" , It . IsAny < X509KeyStorageFlags > ( ) ) )
290
- . Throws ( exception ) ;
288
+ . Throws ( new Exception ( nameof ( Throws_MultipleCertificateNames_File_FileNotFound ) ) ) ;
291
289
292
290
var certificateLoader = new CertificateLoader (
293
291
configuration . GetSection ( "Certificates" ) ,
294
292
certificateFileLoader . Object ,
295
293
Mock . Of < ICertificateStoreLoader > ( ) ) ;
296
294
297
- Assert . Same ( exception , Assert . Throws < Exception > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ) ;
295
+ var exception = Assert . Throws < CertificateConfigurationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
296
+ Assert . Equal ( $ "Failed to load certificate from file 'Certificate2.pfx': { nameof ( Throws_MultipleCertificateNames_File_FileNotFound ) } ", exception . Message ) ;
298
297
}
299
298
300
299
[ Fact ]
@@ -377,7 +376,7 @@ public void Throws_MultipleCertificateNames_Store_KeyNotFound(string certificate
377
376
Mock . Of < ICertificateFileLoader > ( ) ,
378
377
certificateStoreLoader . Object ) ;
379
378
380
- var exception = Assert . Throws < InvalidOperationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
379
+ var exception = Assert . Throws < CertificateConfigurationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
381
380
Assert . Equal ( "No certificate named NotFound found in configuration" , exception . Message ) ;
382
381
}
383
382
@@ -509,7 +508,7 @@ public void Throws_MultipleCertificateNames_FileAndStore_KeyNotFound(string cert
509
508
certificateFileLoader . Object ,
510
509
certificateStoreLoader . Object ) ;
511
510
512
- var exception = Assert . Throws < InvalidOperationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
511
+ var exception = Assert . Throws < CertificateConfigurationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
513
512
Assert . Equal ( "No certificate named NotFound found in configuration" , exception . Message ) ;
514
513
}
515
514
@@ -532,13 +531,12 @@ public void Throws_MultipleCertificateNames_FileAndStore_FileNotFound(string cer
532
531
} )
533
532
. Build ( ) ;
534
533
535
- var exception = new Exception ( ) ;
536
534
var storeCertificate = new X509Certificate2 ( ) ;
537
535
538
536
var certificateFileLoader = new Mock < ICertificateFileLoader > ( ) ;
539
537
certificateFileLoader
540
538
. Setup ( loader => loader . Load ( "Certificate1.pfx" , "Password1" , It . IsAny < X509KeyStorageFlags > ( ) ) )
541
- . Throws ( exception ) ;
539
+ . Throws ( new Exception ( nameof ( Throws_MultipleCertificateNames_FileAndStore_FileNotFound ) ) ) ;
542
540
543
541
var certificateStoreLoader = new Mock < ICertificateStoreLoader > ( ) ;
544
542
certificateStoreLoader
@@ -550,7 +548,8 @@ public void Throws_MultipleCertificateNames_FileAndStore_FileNotFound(string cer
550
548
certificateFileLoader . Object ,
551
549
certificateStoreLoader . Object ) ;
552
550
553
- Assert . Same ( exception , Assert . Throws < Exception > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ) ;
551
+ var exception = Assert . Throws < CertificateConfigurationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
552
+ Assert . Equal ( $ "Failed to load certificate from file 'Certificate1.pfx': { nameof ( Throws_MultipleCertificateNames_FileAndStore_FileNotFound ) } ", exception . Message ) ;
554
553
}
555
554
556
555
[ Theory ]
@@ -638,19 +637,18 @@ public void Throws_SingleCertificateInline_FileNotFound()
638
637
} )
639
638
. Build ( ) ;
640
639
641
- var exception = new Exception ( ) ;
642
-
643
640
var certificateFileLoader = new Mock < ICertificateFileLoader > ( ) ;
644
641
certificateFileLoader
645
642
. Setup ( loader => loader . Load ( "Certificate1.pfx" , "Password1" , It . IsAny < X509KeyStorageFlags > ( ) ) )
646
- . Throws ( exception ) ;
643
+ . Throws ( new Exception ( nameof ( Throws_SingleCertificateInline_FileNotFound ) ) ) ;
647
644
648
645
var certificateLoader = new CertificateLoader (
649
646
null ,
650
647
certificateFileLoader . Object ,
651
648
Mock . Of < ICertificateStoreLoader > ( ) ) ;
652
649
653
- Assert . Same ( exception , Assert . Throws < Exception > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ) ;
650
+ var exception = Assert . Throws < CertificateConfigurationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificate" ) ) ) ;
651
+ Assert . Equal ( $ "Failed to load certificate from file 'Certificate1.pfx': { nameof ( Throws_SingleCertificateInline_FileNotFound ) } ", exception . Message ) ;
654
652
certificateFileLoader . VerifyAll ( ) ;
655
653
}
656
654
@@ -764,22 +762,22 @@ public void Throws_MultipleCertificatesInline_File_FileNotFound()
764
762
. Build ( ) ;
765
763
766
764
var certificate1 = new X509Certificate2 ( ) ;
767
- var exception = new Exception ( ) ;
768
765
769
766
var certificateFileLoader = new Mock < ICertificateFileLoader > ( ) ;
770
767
certificateFileLoader
771
768
. Setup ( loader => loader . Load ( "Certificate1.pfx" , "Password1" , It . IsAny < X509KeyStorageFlags > ( ) ) )
772
769
. Returns ( certificate1 ) ;
773
770
certificateFileLoader
774
771
. Setup ( loader => loader . Load ( "Certificate2.pfx" , "Password2" , It . IsAny < X509KeyStorageFlags > ( ) ) )
775
- . Throws ( exception ) ;
772
+ . Throws ( new Exception ( nameof ( Throws_MultipleCertificatesInline_File_FileNotFound ) ) ) ;
776
773
777
774
var certificateLoader = new CertificateLoader (
778
775
null ,
779
776
certificateFileLoader . Object ,
780
777
Mock . Of < ICertificateStoreLoader > ( ) ) ;
781
778
782
- Assert . Same ( exception , Assert . Throws < Exception > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificates" ) ) ) ) ;
779
+ var exception = Assert . Throws < CertificateConfigurationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificates" ) ) ) ;
780
+ Assert . Equal ( $ "Failed to load certificate from file 'Certificate2.pfx': { nameof ( Throws_MultipleCertificatesInline_File_FileNotFound ) } ", exception . Message ) ;
783
781
}
784
782
785
783
[ Fact ]
@@ -937,13 +935,12 @@ public void Throws_MultipleCertificatesInline_FileAndStore_FileNotFound()
937
935
} )
938
936
. Build ( ) ;
939
937
940
- var exception = new Exception ( ) ;
941
938
var certificate = new X509Certificate2 ( ) ;
942
939
943
940
var certificateFileLoader = new Mock < ICertificateFileLoader > ( ) ;
944
941
certificateFileLoader
945
942
. Setup ( loader => loader . Load ( "Certificate1.pfx" , "Password1" , It . IsAny < X509KeyStorageFlags > ( ) ) )
946
- . Throws ( exception ) ;
943
+ . Throws ( new Exception ( nameof ( Throws_MultipleCertificatesInline_FileAndStore_FileNotFound ) ) ) ;
947
944
948
945
var certificateStoreLoader = new Mock < ICertificateStoreLoader > ( ) ;
949
946
certificateStoreLoader
@@ -955,7 +952,8 @@ public void Throws_MultipleCertificatesInline_FileAndStore_FileNotFound()
955
952
certificateFileLoader . Object ,
956
953
certificateStoreLoader . Object ) ;
957
954
958
- Assert . Same ( exception , Assert . Throws < Exception > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificates" ) ) ) ) ;
955
+ var exception = Assert . Throws < CertificateConfigurationException > ( ( ) => certificateLoader . Load ( configuration . GetSection ( "TestConfig:Certificates" ) ) ) ;
956
+ Assert . Equal ( $ "Failed to load certificate from file 'Certificate1.pfx': { nameof ( Throws_MultipleCertificatesInline_FileAndStore_FileNotFound ) } ", exception . Message ) ;
959
957
}
960
958
961
959
[ Fact ]
0 commit comments