@@ -82,16 +82,28 @@ InModuleScope MSFT_xComputer {
8282 Mock GetComputerDomain {' contoso.com' }
8383 Test-TargetResource - Name $Env: ComputerName - WorkGroupName ' Contoso' - Credential $Credential - UnjoinCredential $Credential | Should Be $false
8484 }
85+ It ' Throws if name is to long' {
86+ {Test-TargetResource - Name " ThisNameIsTooLong" } | Should Throw
87+ }
88+ It ' Throws if name contains illigal characters' {
89+ {Test-TargetResource - Name " ThisIsBad<>" } | Should Throw
90+ }
8591
8692 }
8793 Context Get-TargetResource {
8894 It ' should not throw' {
8995 {Get-TargetResource - Name $env: COMPUTERNAME } | Should Not Throw
9096 }
91- It ' Should return a hashtable containing Name,DomainName, Credential, UnjoinCredential and WorkGroupName' {
97+ It ' Should return a hashtable containing Name, DomainName, JoinOU, CurrentOU , Credential, UnjoinCredential and WorkGroupName' {
9298 $Result = Get-TargetResource - Name $env: COMPUTERNAME
9399 $Result.GetType ().Fullname | Should Be ' System.Collections.Hashtable'
94- $Result.Keys | Should Be @ (' Name' , ' DomainName' , ' Credential' , ' UnjoinCredential' , ' WorkGroupName' )
100+ $Result.Keys | Should Be @ (' Name' , ' DomainName' , ' JoinOU' , ' CurrentOU' , ' Credential' , ' UnjoinCredential' , ' WorkGroupName' )
101+ }
102+ It ' Throws if name is to long' {
103+ {Get-TargetResource - Name " ThisNameIsTooLong" } | Should Throw
104+ }
105+ It ' Throws if name contains illigal characters' {
106+ {Get-TargetResource - Name " ThisIsBad<>" } | Should Throw
95107 }
96108 }
97109 Context Set-TargetResource {
@@ -115,6 +127,14 @@ InModuleScope MSFT_xComputer {
115127 Assert-MockCalled - CommandName Add-Computer - Exactly 1 - Scope It - ParameterFilter {$DomainName -and $NewName }
116128 Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$WorkGroupName }
117129 }
130+ It ' Changes ComputerName and changes Domain to new Domain with specified OU' {
131+ Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso.com' ;Workgroup = ' Contoso.com' ;PartOfDomain = $true }}
132+ Mock GetComputerDomain {' contoso.com' }
133+ Set-TargetResource - Name $NotComputerName - DomainName ' adventure-works.com' - JoinOU ' OU=Computers,DC=contoso,DC=com' - Credential $Credential - UnjoinCredential $Credential | Should BeNullOrEmpty
134+ Assert-MockCalled - CommandName Rename-Computer - Exactly 0 - Scope It
135+ Assert-MockCalled - CommandName Add-Computer - Exactly 1 - Scope It - ParameterFilter {$DomainName -and $NewName }
136+ Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$WorkGroupName }
137+ }
118138 It ' Changes ComputerName and changes Domain to Workgroup' {
119139 Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso.com' ;Workgroup = ' Contoso.com' ;PartOfDomain = $true }}
120140 Mock GetComputerDomain {' contoso.com' }
@@ -131,6 +151,14 @@ InModuleScope MSFT_xComputer {
131151 Assert-MockCalled - CommandName Add-Computer - Exactly 1 - Scope It - ParameterFilter {$DomainName -and $NewName }
132152 Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$WorkGroupName }
133153 }
154+ It ' Changes ComputerName and changes Workgroup to Domain with specified OU' {
155+ Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso' ;Workgroup = ' Contoso' ;PartOfDomain = $false }}
156+ Mock GetComputerDomain {' ' }
157+ Set-TargetResource - Name $NotComputerName - DomainName ' Contoso.com' - JoinOU ' OU=Computers,DC=contoso,DC=com' - Credential $Credential | Should BeNullOrEmpty
158+ Assert-MockCalled - CommandName Rename-Computer - Exactly 0 - Scope It
159+ Assert-MockCalled - CommandName Add-Computer - Exactly 1 - Scope It - ParameterFilter {$DomainName -and $NewName }
160+ Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$WorkGroupName }
161+ }
134162 It ' Changes ComputerName and changes Workgroup to new Workgroup' {
135163 Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso' ;Workgroup = ' Contoso' ;PartOfDomain = $false }}
136164 Mock GetComputerDomain {' ' }
@@ -148,6 +176,15 @@ InModuleScope MSFT_xComputer {
148176 Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$NewName }
149177 Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$WorkGroupName }
150178 }
179+ It ' Changes only the Domain to new Domain with specified OU' {
180+ Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso.com' ;Workgroup = ' Contoso.com' ;PartOfDomain = $true }}
181+ Mock GetComputerDomain {' contoso.com' }
182+ Set-TargetResource - Name $Env: ComputerName - DomainName ' adventure-works.com' - JoinOU ' OU=Computers,DC=contoso,DC=com' - Credential $Credential - UnjoinCredential $Credential | Should BeNullOrEmpty
183+ Assert-MockCalled - CommandName Rename-Computer - Exactly 0 - Scope It
184+ Assert-MockCalled - CommandName Add-Computer - Exactly 1 - Scope It - ParameterFilter {$DomainName }
185+ Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$NewName }
186+ Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$WorkGroupName }
187+ }
151188 It ' Changes only Domain to Workgroup' {
152189 Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso.com' ;Workgroup = ' Contoso.com' ;PartOfDomain = $true }}
153190 Mock GetComputerDomain {' ' }
@@ -171,6 +208,12 @@ InModuleScope MSFT_xComputer {
171208 Assert-MockCalled - CommandName Rename-Computer - Exactly 1 - Scope It
172209 Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It
173210 }
211+ It ' Throws if name is to long' {
212+ {Set-TargetResource - Name " ThisNameIsTooLong" } | Should Throw
213+ }
214+ It ' Throws if name contains illigal characters' {
215+ {Set-TargetResource - Name " ThisIsBad<>" } | Should Throw
216+ }
174217 }
175218 }
176219}
0 commit comments