23
23
// </summary>
24
24
// --------------------------------------------------------------------------------------------------------------------
25
25
26
+ using System ;
26
27
using System . IO ;
27
- using System . Net . Http ;
28
- using System . Threading . Tasks ;
29
28
using Aspose . Pdf . Cloud . Sdk . Api ;
30
29
using Aspose . Pdf . Cloud . Sdk . Client ;
31
30
using Newtonsoft . Json ;
32
31
using NUnit . Framework ;
33
32
34
- namespace Aspose . Pdf . Cloud . Sdk . Test
35
- {
36
- public abstract class TestsBase
37
- {
38
- private const string BaseProductUri = @"https://api.aspose.cloud" ;
33
+ namespace Aspose . Pdf . Cloud . Sdk . Test {
39
34
40
- protected const string TestDataFolder = @"..\..\..\..\testData" ;
41
- private const string ServerCredsFile = @"..\..\..\Settings\servercreds.json" ;
35
+ public abstract class TestsBase {
42
36
43
- protected const string TempFolder = "TempPdfCloud" ;
37
+ private const string BaseProductUri = @"https://api.aspose.cloud" ;
38
+ protected const string TestDataFolder = @"..\..\..\..\testData" ;
39
+ private const string ServerCredsFile = @"Settings\servercreds.json" ;
40
+ protected const string TempFolder = "TempPdfCloud" ;
44
41
45
- private Keys keys ;
46
-
47
- [ SetUp ]
48
- public virtual void SetUp ( )
49
- {
50
- // To run tests with your own credentials please uncomment following line of code
51
- // this.keys = new Keys { AppKey = "your app key", AppSID = "your app sid" };
52
- if ( null == keys )
53
- {
54
- keys = JsonConvert . DeserializeObject < Keys > ( File . ReadAllText ( ServerCredsFile ) ) ;
55
- }
42
+ private class Keys {
43
+ public string AppSID { get ; set ; }
44
+ public string AppKey { get ; set ; }
45
+ }
56
46
57
- if ( string . IsNullOrEmpty ( keys ? . AppKey ) || string . IsNullOrEmpty ( keys . AppSID ) )
58
- {
59
- throw new FileNotFoundException ( "servercreds.json doesn't contain AppKey and AppSid" ) ;
60
- }
47
+ private Keys keys ;
61
48
62
- Configuration = new Configuration ( keys . AppKey , keys . AppSID , BaseProductUri ) ;
63
- PdfApi = new PdfApi ( Configuration ) ;
64
- }
65
-
66
- [ TearDown ]
67
- public virtual void TearDown ( )
68
- {
49
+ private string _GetServercredsJson ( ) {
50
+ DirectoryInfo di = Directory . GetParent ( Directory . GetCurrentDirectory ( ) ) ;
51
+ while ( di != null ) {
52
+ string servercreds_json = Path . Combine ( di . FullName , ServerCredsFile ) ;
53
+ if ( File . Exists ( servercreds_json ) ) {
54
+ return servercreds_json ;
69
55
}
56
+ di = Directory . GetParent ( di . FullName ) ;
57
+ }
58
+ return null ;
59
+ }
70
60
71
- protected PdfApi PdfApi { get ; set ; }
72
- protected Configuration Configuration { get ; private set ; }
61
+ private Keys _GetKeys ( ) {
62
+ return JsonConvert . DeserializeObject < Keys > ( File . ReadAllText ( _GetServercredsJson ( ) ) ) ;
63
+ }
73
64
65
+ [ SetUp ]
66
+ public virtual void SetUp ( ) {
67
+ Console . WriteLine ( TestContext . CurrentContext . Test . Name ) ;
68
+ // To run tests with your own credentials please uncomment following line of code
69
+ // this.keys = new Keys { AppKey = "your app key", AppSID = "your app sid" };
70
+ if ( keys == null ) {
71
+ keys = _GetKeys ( ) ;
72
+ }
73
+ if ( string . IsNullOrEmpty ( keys . AppKey ) || string . IsNullOrEmpty ( keys . AppSID ) ) {
74
+ throw new FileNotFoundException ( "servercreds.json doesn't contain AppSID and/or AppKey" ) ;
75
+ }
76
+ Configuration = new Configuration ( keys . AppKey , keys . AppSID , BaseProductUri ) ;
77
+ PdfApi = new PdfApi ( Configuration ) ;
78
+ }
74
79
75
- protected void UploadFile ( string sourcePath , string serverFileName )
76
- {
77
- using ( var file = File . OpenRead ( Path . Combine ( TestDataFolder , sourcePath ) ) )
78
- {
79
- var response = PdfApi . UploadFile ( Path . Combine ( TempFolder , serverFileName ) , file ) ;
80
- }
81
- }
80
+ [ TearDown ]
81
+ public virtual void TearDown ( ) { }
82
82
83
- private class Keys
84
- {
85
- public string AppSID { get ; set ; }
83
+ protected PdfApi PdfApi { get ; set ; }
84
+ protected Configuration Configuration { get ; private set ; }
86
85
87
- public string AppKey { get ; set ; }
88
- }
86
+ protected void UploadFile ( string sourcePath , string serverFileName ) {
87
+ using ( var file = File . OpenRead ( Path . Combine ( TestDataFolder , sourcePath ) ) ) {
88
+ Model . FilesUploadResult response = PdfApi . UploadFile ( Path . Combine ( TempFolder , serverFileName ) , file ) ;
89
+ }
89
90
}
90
- }
91
+ }
92
+ }
0 commit comments