1
- using System ;
2
- using System . Net ;
3
- using System . Net . Http ;
4
- using System . Threading . Tasks ;
5
- using System . Web ;
6
1
using DataPipelineTools . Tests . Common ;
7
2
using Microsoft . Extensions . Logging ;
8
3
using NUnit . Framework ;
4
+ using SqlCollaborative . Azure . DataPipelineTools . Functions . DataLake ;
5
+ using System ;
6
+ using System . Collections . Generic ;
7
+ using System . Net ;
8
+ using System . Threading . Tasks ;
9
+ using SqlCollaborative . Azure . DataPipelineTools . DataLake . Model ;
9
10
10
11
namespace DataPipelineTools . Functions . Tests . DataLake . DataLakeFunctions . Integration
11
12
{
12
13
[ TestFixture ]
13
14
[ Category ( nameof ( TestType . IntegrationTest ) ) ]
15
+ [ Parallelizable ( ParallelScope . Children ) ]
14
16
public class DataLakeGetItemsIntegrationTests : IntegrationTestBase
15
17
{
16
18
protected override string FunctionUri => $ "{ FunctionsAppUrl } /api/DataLakeGetItems";
@@ -25,33 +27,60 @@ public void Setup()
25
27
}
26
28
27
29
[ Test ]
28
- public async Task Test_FunctionIsRunnable ( )
30
+ public async Task Test_FunctionIsRunnable_With_FunctionsServicePrincipalAuth ( )
29
31
{
30
- using ( var client = new HttpClient ( ) )
32
+ var parameters = new Dictionary < string , string >
31
33
{
32
- var queryParams = HttpUtility . ParseQueryString ( string . Empty ) ;
33
- queryParams [ "account" ] = this . StorageAccountName ;
34
- queryParams [ "container" ] = this . StorageContainerName ;
34
+ { DataLakeConfigFactory . AccountParam , StorageAccountName } ,
35
+ { DataLakeConfigFactory . ContainerParam , StorageContainerName }
36
+ } ;
37
+ var response = await RunQueryFromParameters ( parameters ) ;
38
+ LogContent ( response ) ;
39
+ Assert . AreEqual ( HttpStatusCode . OK , response . StatusCode ) ;
35
40
36
- if ( ! IsEmulatorRunning )
37
- queryParams [ "code" ] = this . FunctionsAppKey ;
41
+ // Check response details. Its important to cast the actual or we test against JToken from the dynamic results
42
+ dynamic results = GetResultsObject ( response ) ;
43
+ Assert . AreEqual ( AuthType . FunctionsServicePrincipal , ( AuthType ) results . authType ) ;
44
+ }
38
45
39
- var urlBuilder = new UriBuilder ( FunctionUri )
40
- {
41
- Query = queryParams . ToString ( ) ?? string . Empty
42
- } ;
43
- var queryUrl = urlBuilder . ToString ( ) ;
46
+ [ Test ]
47
+ public async Task Test_FunctionIsRunnable_With_UserServicePrincipalAuthAndPlainTextKey ( )
48
+ {
49
+ var parameters = new Dictionary < string , string >
50
+ {
51
+ { DataLakeConfigFactory . AccountParam , StorageAccountName } ,
52
+ { DataLakeConfigFactory . ContainerParam , StorageContainerName } ,
53
+ { DataLakeConfigFactory . ServicePrincipalClientIdParam , ServicePrincipalName } ,
54
+ { DataLakeConfigFactory . ServicePrincipalClientSecretParam , ServicePrincipalSecretKey } ,
55
+ } ;
56
+ var response = await RunQueryFromParameters ( parameters ) ;
57
+ LogContent ( response ) ;
58
+ Assert . AreEqual ( HttpStatusCode . OK , response . StatusCode ) ;
44
59
45
- if ( ! IsRunningOnCIServer )
46
- Logger . LogInformation ( $ "Query URL: { queryUrl } ") ;
47
-
48
- var result = await client . GetAsync ( queryUrl ) ;
49
- var content = result . Content . ReadAsStringAsync ( ) . Result ;
60
+ // Check response details. Its important to cast the actual or we test against JToken from the dynamic results
61
+ dynamic results = GetResultsObject ( response ) ;
62
+ Assert . AreEqual ( AuthType . UserServicePrincipal , ( AuthType ) results . authType ) ;
63
+ }
50
64
51
- Logger . LogInformation ( $ "Content: { content } ") ;
65
+ [ Test ]
66
+ public async Task Test_FunctionIsRunnable_With_UserServicePrincipalAuthAndKeyVaultKeyName ( )
67
+ {
68
+ var parameters = new Dictionary < string , string >
69
+ {
70
+ { DataLakeConfigFactory . AccountParam , StorageAccountName } ,
71
+ { DataLakeConfigFactory . ContainerParam , StorageContainerName } ,
72
+ { DataLakeConfigFactory . ServicePrincipalClientIdParam , ServicePrincipalName } ,
73
+ { DataLakeConfigFactory . ServicePrincipalClientSecretParam , ServicePrincipalSecretKeyName } ,
74
+ { DataLakeConfigFactory . KeyVaultParam , KeyVaultName }
75
+ } ;
76
+ var response = await RunQueryFromParameters ( parameters ) ;
77
+ LogContent ( response ) ;
78
+ Assert . AreEqual ( HttpStatusCode . OK , response . StatusCode ) ;
52
79
53
- Assert . AreEqual ( HttpStatusCode . OK , result . StatusCode ) ;
54
- }
80
+ // Check response details. Its important to cast the actual or we test against JToken from the dynamic results
81
+ dynamic results = GetResultsObject ( response ) ;
82
+ Assert . AreEqual ( AuthType . UserServicePrincipal , ( AuthType ) results . authType ) ;
55
83
}
84
+
56
85
}
57
86
}
0 commit comments