@@ -121,16 +121,25 @@ try
121121 It ' Should not Throw if name is localhost' {
122122 {Test-TargetResource - Name " localhost" } | Should Not Throw
123123 }
124-
124+ It ' Should return true if description is same as specified' {
125+ Mock Get-CimInstance {[PSCustomObject ]@ {Description = ' This is my computer' }}
126+ Test-TargetResource - Name $env: COMPUTERNAME - Description " This is my computer" | Should Be $true
127+ Test-TargetResource - Name ' localhost' - Description " This is my computer" | Should Be $true
128+ }
129+ It ' Should return false if description is same as specified' {
130+ Mock Get-CimInstance {[PSCustomObject ]@ {Description = ' This is not my computer' }}
131+ Test-TargetResource - Name $env: COMPUTERNAME - Description " This is my computer" | Should Be $false
132+ Test-TargetResource - Name ' localhost' - Description " This is my computer" | Should Be $false
133+ }
125134 }
126135 Context " $ ( $Global :DSCResourceName ) \Get-TargetResource" {
127136 It ' should not throw' {
128137 {Get-TargetResource - Name $env: COMPUTERNAME } | Should Not Throw
129138 }
130- It ' Should return a hashtable containing Name, DomainName, JoinOU, CurrentOU, Credential, UnjoinCredential and WorkGroupName ' {
139+ It ' Should return a hashtable containing Name, DomainName, JoinOU, CurrentOU, Credential, UnjoinCredential, WorkGroupName and Description ' {
131140 $Result = Get-TargetResource - Name $env: COMPUTERNAME
132141 $Result.GetType ().Fullname | Should Be ' System.Collections.Hashtable'
133- $Result.Keys | Sort-Object | Should Be @ (' Credential' , ' CurrentOU' , ' DomainName' , ' JoinOU' , ' Name' , ' UnjoinCredential' , ' WorkGroupName' )
142+ $Result.Keys | Sort-Object | Should Be @ (' Credential' , ' CurrentOU' , ' Description ' , ' DomainName' , ' JoinOU' , ' Name' , ' UnjoinCredential' , ' WorkGroupName' )
134143 }
135144 It ' Throws if name is to long' {
136145 {Get-TargetResource - Name " ThisNameIsTooLong" } | Should Throw
142151 Context " $ ( $Global :DSCResourceName ) \Set-TargetResource" {
143152 Mock Rename-Computer {}
144153 Mock Add-Computer {}
154+ Mock Set-CimInstance {}
145155 It ' Throws if both DomainName and WorkGroupName are specified' {
146156 {Set-TargetResource - Name $Env: ComputerName - DomainName ' contoso.com' - WorkGroupName ' workgroup' } | Should Throw
147157 Assert-MockCalled - CommandName Rename-Computer - Exactly 0 - Scope It
274284 It ' Throws if name contains illigal characters' {
275285 {Set-TargetResource - Name " ThisIsBad<>" } | Should Throw
276286 }
287+ It ' Changes computer description in a workgroup' {
288+ Mock Get-ComputerDomain {' ' }
289+ Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso' ;Workgroup = ' Contoso' ;PartOfDomain = $false }}
290+ Set-TargetResource - Name $env: COMPUTERNAME - Description = ' This is my computer' - DomainName " " | Should BeNullOrEmpty
291+ Assert-MockCalled - CommandName Set-CimInstance - Exactly 1 - Scope It
292+ }
293+ It ' Changes computer description in a domain' {
294+ Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso.com' ;Workgroup = ' Contoso.com' ;PartOfDomain = $true }}
295+ Mock Get-ComputerDomain {' contoso.com' }
296+ Set-TargetResource - Name $Env: ComputerName | Should BeNullOrEmpty
297+ Set-TargetResource - Name $env: COMPUTERNAME - DomainName ' Contoso.com' - Credential $Credential - UnjoinCredential $Credential - Description = ' This is my computer' | Should BeNullOrEmpty
298+ Assert-MockCalled - CommandName Set-CimInstance - Exactly 2 - Scope It
299+ }
277300 }
278301 }
279302 } # end InModuleScope $DSCResourceName
0 commit comments