@@ -24,8 +24,14 @@ function Test-AdfCode {
2424 [String ] $ConfigPath
2525 )
2626
27- $ErrorCount = 0
28- $WarningCount = 0
27+ class ReturnClass {
28+ [int ] $ErrorCount
29+ [int ] $WarningCount
30+ }
31+ $result = New-Object ' ReturnClass'
32+
33+ $result.ErrorCount = 0
34+ $result.WarningCount = 0
2935 $adfName = Split-Path - Path " $RootFolder " - Leaf
3036
3137 Write-Host " === Loading files from location: $RootFolder ..."
@@ -38,7 +44,7 @@ function Test-AdfCode {
3844 $ErrorActionPreference = ' Continue'
3945
4046 if ($ObjectsCount -eq 0 ) {
41- $WarningCount += 1
47+ $result . WarningCount += 1
4248 Write-Warning " No Azure Data Factory files have been found in a given location."
4349 }
4450
@@ -47,22 +53,22 @@ function Test-AdfCode {
4753 Write-Host " Checking: $FullName ..."
4854 $HasBody = $null -ne $_.Body
4955 if (-not $HasBody ) {
50- $ErrorCount += 1
51- Write-Error - Message " Object $FullName was not loaded properly."
56+ $result . ErrorCount += 1
57+ Write-Error - Message " Object $FullName was not loaded properly." - ErrorAction ' Continue '
5258 }
5359 if ($HasBody ) {
5460
5561 if ($_.name -ne $_.Body.name ) {
56- $ErrorCount += 1
57- Write-Error - Message " Object $FullName has mismatch file name."
62+ $result . ErrorCount += 1
63+ Write-Error - Message " Object $FullName has mismatch file name." - ErrorAction ' Continue '
5864 }
5965
6066 $_.DependsOn | ForEach-Object {
6167 Write-Verbose - Message " - Checking dependency: [$_ ]"
6268 $ref_arr = $adf.GetObjectsByFullName (" $_ " )
6369 if ($ref_arr.Count -eq 0 ) {
64- $ErrorCount += 1
65- Write-Error - Message " Couldn't find referenced object $_ ."
70+ $result . ErrorCount += 1
71+ Write-Error - Message " Couldn't find referenced object $_ ." - ErrorAction ' Continue '
6672 }
6773 }
6874 }
@@ -74,15 +80,15 @@ function Test-AdfCode {
7480 $r = $adf.GetObjectsByFullName (" *." + $_ )
7581 if ($r.Count -gt 1 ) {
7682 Write-Warning " Duplication of object name: $_ "
77- $WarningCount += 1
83+ $result . WarningCount += 1
7884 }
7985 }
8086
8187 $adf.LinkedServices + $adf.DataSets + $adf.Pipelines + $adf.DataFlows | ForEach-Object {
8288 [string ] $name = $_.Name
8389 if ($name.Contains (' -' )) {
8490 Write-Warning " Dashes ('-') are not allowed in the names of linked services, data flows, and datasets ($name )."
85- $WarningCount += 1
91+ $result . WarningCount += 1
8692 }
8793 }
8894
@@ -91,7 +97,7 @@ function Test-AdfCode {
9197 [string ] $name = $_.Name
9298 if ($name.Contains (' -' )) {
9399 Write-Warning " Dashes ('-') are not allowed in the names of global parameters ($name )."
94- $WarningCount += 1
100+ $result . WarningCount += 1
95101 }
96102 }
97103 }
@@ -115,7 +121,7 @@ function Test-AdfCode {
115121 Update-PropertiesFromFile - adf $adf - stage $FileName - ErrorVariable err - ErrorAction ' Stop' - dryRun:$True
116122 }
117123 catch {
118- $ErrorCount += 1
124+ $result . ErrorCount += 1
119125 Write-Host " ERROR: $ ( $_.Exception.Message ) " - ForegroundColor ' Red'
120126 Write-Debug - Message $_.Exception
121127 # $_.Exception
@@ -125,13 +131,13 @@ function Test-AdfCode {
125131
126132
127133 $msg = " Test code completed ($ObjectsCount objects)."
128- if ($ErrorCount -gt 0 ) { $msg = " Test code failed." }
129- $line1 = $adf.Name.PadRight (63 ) + " # of Errors: $ErrorCount " .PadLeft(28 )
130- $line2 = $msg.PadRight (63 ) + " # of Warnings: $WarningCount " .PadLeft(28 )
134+ if ($result . ErrorCount -gt 0 ) { $msg = " Test code failed." }
135+ $line1 = $adf.Name.PadRight (63 ) + " # of Errors: $ ( $result . ErrorCount) " .PadLeft(28 )
136+ $line2 = $msg.PadRight (63 ) + " # of Warnings: $ ( $result . WarningCount) " .PadLeft(28 )
131137 Write-Host " ============================================================================================="
132138 Write-Host " $line1 "
133139 Write-Host " $line2 "
134140 Write-Host " ============================================================================================="
135141
136- return $ErrorCount ;
142+ return $result ;
137143}
0 commit comments