Skip to content

Commit ce84cfa

Browse files
committed
Added a few tests for Set
1 parent 3fa99a6 commit ce84cfa

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Tests/xComputermanagement.Tests.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ InModuleScope MSFT_xComputer {
115115
Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName -and $NewName}
116116
Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName}
117117
}
118+
It 'Changes ComputerName and changes Domain to new Domain with specified OU' {
119+
Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}}
120+
Mock GetComputerDomain {'contoso.com'}
121+
Set-TargetResource -Name $NotComputerName -DomainName 'adventure-works.com' -JoinOU 'OU=Computers,DC=contoso,DC=com' -Credential $Credential -UnjoinCredential $Credential | Should BeNullOrEmpty
122+
Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It
123+
Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName -and $NewName}
124+
Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName}
125+
}
118126
It 'Changes ComputerName and changes Domain to Workgroup' {
119127
Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}}
120128
Mock GetComputerDomain {'contoso.com'}
@@ -148,6 +156,15 @@ InModuleScope MSFT_xComputer {
148156
Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$NewName}
149157
Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName}
150158
}
159+
It 'Changes only the Domain to new Domain with specified OU' {
160+
Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}}
161+
Mock GetComputerDomain {'contoso.com'}
162+
Set-TargetResource -Name $Env:ComputerName -DomainName 'adventure-works.com' -JoinOU 'OU=Computers,DC=contoso,DC=com' -Credential $Credential -UnjoinCredential $Credential | Should BeNullOrEmpty
163+
Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It
164+
Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName}
165+
Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$NewName}
166+
Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName}
167+
}
151168
It 'Changes only Domain to Workgroup' {
152169
Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}}
153170
Mock GetComputerDomain {''}

0 commit comments

Comments
 (0)