1- using ApexUtilLib ;
1+ using ApexUtilLib ;
22using ApiUtilLib ;
33using System ;
44using System . Collections . Generic ;
55using System . IO ;
66using System . Security . Cryptography ;
77using System . Text ;
8+ using System . IO . Compression ;
9+ using System . Reflection ;
810
911namespace ApexUtilLibTest
1012{
1113 public class BaseService
1214 {
13- internal string testDataPath = @"/Users/nsearch/OneDrive/Projects/GovTech/testData/" ;
14- internal string testCertPath = @"/Users/nsearch/OneDrive/Projects/GovTech/" ;
15+ internal string apexTestSuitePath = "https://github.com/GovTechSG/test-suites-apex-api-security/archive/master.zip" ;
16+ internal string testDataPath = GetLocalPath ( "temp/test-suites-apex-api-security-master/testData/" ) ;
17+ internal string testCertPath = GetLocalPath ( "temp/test-suites-apex-api-security-master/" ) ;
1518
1619 internal ApiUtilLib . SignatureMethod signatureMethod { get ; set ; }
1720 internal ApiUtilLib . HttpMethod httpMethod { get ; set ; }
@@ -33,6 +36,59 @@ public class BaseService
3336
3437 public BaseService ( )
3538 {
39+ downloadFile ( apexTestSuitePath , GetLocalPath ( "testSuite.zip" ) ) ;
40+ }
41+
42+
43+
44+ internal static string GetLocalPath ( string relativeFileName )
45+ {
46+ var localPath = Path . Combine ( Path . GetDirectoryName ( new Uri ( Assembly . GetExecutingAssembly ( ) . CodeBase ) . LocalPath ) , relativeFileName . Replace ( '/' , Path . DirectorySeparatorChar ) ) ;
47+ return localPath ;
48+ }
49+ internal void downloadFile ( string sourceURL , string downloadPath )
50+ {
51+ try
52+ {
53+ long fileSize = 0 ;
54+ int bufferSize = 1024 ;
55+ bufferSize *= 1000 ;
56+ long existLen = 0 ;
57+ System . IO . FileStream saveFileStream ;
58+ saveFileStream = new System . IO . FileStream ( downloadPath ,
59+ System . IO . FileMode . Create ,
60+ System . IO . FileAccess . Write ,
61+ System . IO . FileShare . ReadWrite ) ;
62+
63+ System . Net . HttpWebRequest httpReq ;
64+ System . Net . HttpWebResponse httpRes ;
65+ httpReq = ( System . Net . HttpWebRequest ) System . Net . WebRequest . Create ( sourceURL ) ;
66+ httpReq . AddRange ( ( int ) existLen ) ;
67+ System . IO . Stream resStream ;
68+ httpRes = ( System . Net . HttpWebResponse ) httpReq . GetResponse ( ) ;
69+ resStream = httpRes . GetResponseStream ( ) ;
70+
71+ fileSize = httpRes . ContentLength ;
72+ int byteSize ;
73+ byte [ ] downBuffer = new byte [ bufferSize ] ;
74+
75+ while ( ( byteSize = resStream . Read ( downBuffer , 0 , downBuffer . Length ) ) > 0 )
76+ {
77+ saveFileStream . Write ( downBuffer , 0 , byteSize ) ;
78+ }
79+ saveFileStream . Close ( ) ;
80+
81+ if ( System . IO . Directory . Exists ( GetLocalPath ( "temp/" ) ) )
82+ {
83+ Directory . Delete ( GetLocalPath ( "temp/" ) , true ) ;
84+ }
85+ ZipFile . ExtractToDirectory ( downloadPath , GetLocalPath ( "temp/" ) ) ;
86+ }
87+ catch ( Exception ex )
88+ {
89+ Console . WriteLine ( "Exception: " + ex ) ;
90+ throw ex ;
91+ }
3692 }
3793
3894 internal void SetDetaultParams ( TestParam paramFile )
@@ -109,7 +165,7 @@ internal void SetApiList(Dictionary<object, object> data = null)
109165 }
110166 }
111167
112- internal IEnumerable < TestParam >
168+ internal IEnumerable < TestParam >
113169 GetJsonFile ( string fileName )
114170 {
115171 string path = testDataPath + fileName ;
0 commit comments