Skip to content

Commit e168854

Browse files
committed
Added Join-Domain unit tests
1 parent 96ce46f commit e168854

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Tests/Unit/MSFT_xOfflineDomainJoin.tests.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,39 @@ try
125125
}
126126
}
127127
}
128+
129+
Describe "$($Global:DSCResourceName)\Join-Domain" {
130+
Mock djoin.exe -MockWith { $Global:LASTEXITCODE = 0; return "OK" }
131+
132+
Context 'Domain Join successful' {
133+
It 'should not throw' {
134+
{ Join-Domain -RequestFile 'c:\doesnotmatter.txt' } | Should Not Throw
135+
}
136+
It 'Should do call all the mocks' {
137+
Assert-MockCalled djoin.exe -Times 1
138+
}
139+
}
140+
141+
Mock djoin.exe -MockWith { $Global:LASTEXITCODE = 99; return "ERROR" }
142+
143+
Context 'Domain Join successful' {
144+
$errorId = 'DjoinError'
145+
$errorCategory = [System.Management.Automation.ErrorCategory]::ObjectNotFound
146+
$errorMessage = $($LocalizedData.DjoinError) `
147+
-f 99
148+
$exception = New-Object -TypeName System.ArgumentException `
149+
-ArgumentList $errorMessage
150+
$errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord `
151+
-ArgumentList $exception, $errorId, $errorCategory, $null
152+
153+
It 'should not throw' {
154+
{ Join-Domain -RequestFile 'c:\doesnotmatter.txt' } | Should Throw $errorRecord
155+
}
156+
It 'Should do call all the mocks' {
157+
Assert-MockCalled djoin.exe -Times 1
158+
}
159+
}
160+
}
128161
} #end InModuleScope $DSCResourceName
129162
#endregion
130163
}

0 commit comments

Comments
 (0)