From 7dbc75687fd58ffdf80f4d56fe1c24acc22137b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=A5hlin?= Date: Thu, 23 Apr 2015 17:49:13 +0200 Subject: [PATCH 1/3] Pester Test file created, one test fails since resource doesnt handle domain flat name correctly --- Tests/xComputermanagement.Tests.ps1 | 148 ++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 Tests/xComputermanagement.Tests.ps1 diff --git a/Tests/xComputermanagement.Tests.ps1 b/Tests/xComputermanagement.Tests.ps1 new file mode 100644 index 00000000..75483aa5 --- /dev/null +++ b/Tests/xComputermanagement.Tests.ps1 @@ -0,0 +1,148 @@ +$Module = "$PSScriptRoot\..\DSCResources\MSFT_xComputer\MSFT_xComputer.psm1" +Remove-Module -Name MSFT_xComputer -Force -ErrorAction SilentlyContinue +Import-Module -Name $Module -Force -ErrorAction Stop + +InModuleScope MSFT_xComputer { + + Describe 'xComputermanagement' { + + #$VerbosePreference = 'Continue' + + $SecPassword = ConvertTo-SecureString -String 'password' -AsPlainText -Force + $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'USER',$SecPassword + $NotComputerName = if($env:COMPUTERNAME -ne 'othername'){'othername'}else{'name'} + + Context Test-TargetResource { + It 'Throws if both DomainName and WorkGroupName are specified' { + {Test-TargetResource -Name $Env:ComputerName -DomainName 'contoso.com' -WorkGroupName 'workgroup'} | Should Throw + } + It 'Throws if Domain is specified without Credentials' { + {Test-TargetResource -Name $Env:ComputerName -DomainName 'contoso.com'} | Should Throw + } + It 'Should return True if Domain name is same as specified' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Test-TargetResource -Name $Env:ComputerName -DomainName 'Contoso.com' -Credential $Credential | Should Be $true + } + It 'Should return True if Workgroup name is same as specified' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Workgroup';Workgroup='Workgroup';PartOfDomain=$false}} + Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'workgroup' -Verbose | Should Be $true + } + It 'Should return True if ComputerName and Domain name is same as specified' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Test-TargetResource -Name $Env:ComputerName -DomainName 'contoso.com' -Credential $Credential | Should Be $true + } + It 'Should return True if ComputerName and Workgroup is same as specified' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Workgroup';Workgroup='Workgroup';PartOfDomain=$false}} + Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'workgroup' | Should Be $true + } + It 'Should return True if current Domain flat name (Netbios) is specified' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'contoso.com';Workgroup='contoso.com';PartOfDomain=$true}} + Mock Get-WMIObject {[PSCustomObject]@{DomainName = 'ContosoLtd'}} -ParameterFilter {$Class -eq 'Win32_NTDomain'} + Test-TargetResource -Name $Env:ComputerName -DomainName 'contosoltd' -Credential $Credential | Should Be $true + } + It 'Should return False if Domain name is not same as specified' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Test-TargetResource -Name $Env:ComputerName -DomainName 'adventure-works.com' -Credential $Credential | Should Be $false + } + It 'Should return False if Workgroup name is not same as specified' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Workgroup';Workgroup='Workgroup';PartOfDomain=$false}} + Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'NOTworkgroup' | Should Be $false + } + It 'Should return False if ComputerName is not same as specified' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Workgroup';Workgroup='Workgroup';PartOfDomain=$false}} + Test-TargetResource -Name $NotComputerName -WorkGroupName 'workgroup' | Should Be $false + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Test-TargetResource -Name $NotComputerName -DomainName 'contoso.com' -Credential $Credential | Should Be $false + } + It 'Should return False if Computer is in Workgroup and Domain is specified' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso';Workgroup='Contoso';PartOfDomain=$false}} + Test-TargetResource -Name $Env:ComputerName -DomainName 'contoso.com' -Credential $Credential | Should Be $false + } + It 'Should return False if ComputerName is in Domain and Workgroup is specified' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'Contoso' -Credential $Credential | Should Be $false + } + } + Context Get-TargetResource { + It 'should not throw' { + {Get-TargetResource -Name $env:COMPUTERNAME} | Should Not Throw + } + It 'Should return a hashtable containing Name,DomainName, Credential, UnjoinCredential and WorkGroupName' { + $Result = Get-TargetResource -Name $env:COMPUTERNAME + $Result.GetType().Fullname | Should Be 'System.Collections.Hashtable' + $Result.Keys | Should Be @('Name','DomainName','Credential','UnjoinCredential','WorkGroupName') + } + } + Context Set-TargetResource { + Mock Rename-Computer {} + Mock Add-Computer {} + It 'Throws if both DomainName and WorkGroupName are specified' { + {Set-TargetResource -Name $Env:ComputerName -DomainName 'contoso.com' -WorkGroupName 'workgroup'} | Should Throw + Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It + } + It 'Throws if Domain is specified without Credentials' { + {Set-TargetResource -Name $Env:ComputerName -DomainName 'contoso.com'} | Should Throw + Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It + } + It 'Changes ComputerName and changes Domain to new Domain' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Set-TargetResource -Name $NotComputerName -DomainName 'adventure-works.com' -Credential $Credential -UnjoinCredential $Credential | Should BeNullOrEmpty + Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName -and $NewName} + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName} + } + It 'Changes ComputerName and changes Domain to Workgroup' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Set-TargetResource -Name $NotComputerName -WorkGroupName 'contoso' -UnjoinCredential $Credential | Should BeNullOrEmpty + Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$WorkGroupName -and $NewName} + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$DomainName} + } + It 'Changes ComputerName and changes Workgroup to Domain' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso';Workgroup='Contoso';PartOfDomain=$false}} + Set-TargetResource -Name $NotComputerName -DomainName 'Contoso.com' -Credential $Credential | Should BeNullOrEmpty + Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName -and $NewName} + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName} + } + It 'Changes ComputerName and changes Workgroup to new Workgroup' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso';Workgroup='Contoso';PartOfDomain=$false}} + Set-TargetResource -Name $NotComputerName -WorkGroupName 'adventure-works' | Should BeNullOrEmpty + Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$WorkGroupName -and $NewName} + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$DomainName} + } + It 'Changes only the Domain to new Domain' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Set-TargetResource -Name $Env:ComputerName -DomainName 'adventure-works.com' -Credential $Credential -UnjoinCredential $Credential | Should BeNullOrEmpty + Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName} + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$NewName} + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName} + } + It 'Changes only Domain to Workgroup' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Set-TargetResource -Name $Env:ComputerName -WorkGroupName 'Contoso' -UnjoinCredential $Credential | Should BeNullOrEmpty + Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$NewName} + Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$WorkGroupName} + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$DomainName} + } + It 'Changes only ComputerName in Domain' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Set-TargetResource -Name $NotComputerName -Credential $Credential | Should BeNullOrEmpty + Assert-MockCalled -CommandName Rename-Computer -Exactly 1 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It + } + It 'Changes only ComputerName in Workgroup' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso';Workgroup='Contoso';PartOfDomain=$false}} + Set-TargetResource -Name $NotComputerName | Should BeNullOrEmpty + Assert-MockCalled -CommandName Rename-Computer -Exactly 1 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It + } + } + } +} + From 9e92c0ab41c4e2f579a611eac981a23ba164016d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=A5hlin?= Date: Fri, 24 Apr 2015 10:43:09 +0200 Subject: [PATCH 2/3] Moved Win32_NTDomain Mock, added -UnjoinCredential to unjoin test and removed one -Verbose parameter. --- Tests/xComputermanagement.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/xComputermanagement.Tests.ps1 b/Tests/xComputermanagement.Tests.ps1 index 75483aa5..81c22d69 100644 --- a/Tests/xComputermanagement.Tests.ps1 +++ b/Tests/xComputermanagement.Tests.ps1 @@ -13,6 +13,7 @@ InModuleScope MSFT_xComputer { $NotComputerName = if($env:COMPUTERNAME -ne 'othername'){'othername'}else{'name'} Context Test-TargetResource { + Mock Get-WMIObject {[PSCustomObject]@{DomainName = 'ContosoLtd'}} -ParameterFilter {$Class -eq 'Win32_NTDomain'} It 'Throws if both DomainName and WorkGroupName are specified' { {Test-TargetResource -Name $Env:ComputerName -DomainName 'contoso.com' -WorkGroupName 'workgroup'} | Should Throw } @@ -25,7 +26,7 @@ InModuleScope MSFT_xComputer { } It 'Should return True if Workgroup name is same as specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Workgroup';Workgroup='Workgroup';PartOfDomain=$false}} - Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'workgroup' -Verbose | Should Be $true + Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'workgroup' | Should Be $true } It 'Should return True if ComputerName and Domain name is same as specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} @@ -37,7 +38,6 @@ InModuleScope MSFT_xComputer { } It 'Should return True if current Domain flat name (Netbios) is specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'contoso.com';Workgroup='contoso.com';PartOfDomain=$true}} - Mock Get-WMIObject {[PSCustomObject]@{DomainName = 'ContosoLtd'}} -ParameterFilter {$Class -eq 'Win32_NTDomain'} Test-TargetResource -Name $Env:ComputerName -DomainName 'contosoltd' -Credential $Credential | Should Be $true } It 'Should return False if Domain name is not same as specified' { @@ -60,7 +60,7 @@ InModuleScope MSFT_xComputer { } It 'Should return False if ComputerName is in Domain and Workgroup is specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} - Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'Contoso' -Credential $Credential | Should Be $false + Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'Contoso' -Credential $Credential -UnjoinCredential $Credential | Should Be $false } } Context Get-TargetResource { From cb7e6cee018a65846564d7d807c632b0beba590c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=A5hlin?= Date: Fri, 24 Apr 2015 13:22:32 +0200 Subject: [PATCH 3/3] updated test to reflect changes in version 1.2.2 from PSGallery --- Tests/xComputermanagement.Tests.ps1 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Tests/xComputermanagement.Tests.ps1 b/Tests/xComputermanagement.Tests.ps1 index 81c22d69..a10cadfd 100644 --- a/Tests/xComputermanagement.Tests.ps1 +++ b/Tests/xComputermanagement.Tests.ps1 @@ -22,44 +22,55 @@ InModuleScope MSFT_xComputer { } It 'Should return True if Domain name is same as specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Mock GetComputerDomain {'contoso.com'} Test-TargetResource -Name $Env:ComputerName -DomainName 'Contoso.com' -Credential $Credential | Should Be $true } It 'Should return True if Workgroup name is same as specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Workgroup';Workgroup='Workgroup';PartOfDomain=$false}} + Mock GetComputerDomain {''} Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'workgroup' | Should Be $true } It 'Should return True if ComputerName and Domain name is same as specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Mock GetComputerDomain {'contoso.com'} Test-TargetResource -Name $Env:ComputerName -DomainName 'contoso.com' -Credential $Credential | Should Be $true } It 'Should return True if ComputerName and Workgroup is same as specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Workgroup';Workgroup='Workgroup';PartOfDomain=$false}} + Mock GetComputerDomain {''} Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'workgroup' | Should Be $true } It 'Should return True if current Domain flat name (Netbios) is specified' { + Mock GetComputerDomain {'contoso.com'} Mock Get-WMIObject {[PSCustomObject]@{Domain = 'contoso.com';Workgroup='contoso.com';PartOfDomain=$true}} Test-TargetResource -Name $Env:ComputerName -DomainName 'contosoltd' -Credential $Credential | Should Be $true } It 'Should return False if Domain name is not same as specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Mock GetComputerDomain {'contoso.com'} Test-TargetResource -Name $Env:ComputerName -DomainName 'adventure-works.com' -Credential $Credential | Should Be $false } It 'Should return False if Workgroup name is not same as specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Workgroup';Workgroup='Workgroup';PartOfDomain=$false}} + Mock GetComputerDomain {''} Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'NOTworkgroup' | Should Be $false } It 'Should return False if ComputerName is not same as specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Workgroup';Workgroup='Workgroup';PartOfDomain=$false}} + Mock GetComputerDomain {''} Test-TargetResource -Name $NotComputerName -WorkGroupName 'workgroup' | Should Be $false Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Mock GetComputerDomain {'contoso.com'} Test-TargetResource -Name $NotComputerName -DomainName 'contoso.com' -Credential $Credential | Should Be $false } It 'Should return False if Computer is in Workgroup and Domain is specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso';Workgroup='Contoso';PartOfDomain=$false}} + Mock GetComputerDomain {''} Test-TargetResource -Name $Env:ComputerName -DomainName 'contoso.com' -Credential $Credential | Should Be $false } It 'Should return False if ComputerName is in Domain and Workgroup is specified' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Mock GetComputerDomain {'contoso.com'} Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'Contoso' -Credential $Credential -UnjoinCredential $Credential | Should Be $false } } @@ -88,6 +99,7 @@ InModuleScope MSFT_xComputer { } It 'Changes ComputerName and changes Domain to new Domain' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Mock GetComputerDomain {'contoso.com'} Set-TargetResource -Name $NotComputerName -DomainName 'adventure-works.com' -Credential $Credential -UnjoinCredential $Credential | Should BeNullOrEmpty Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName -and $NewName} @@ -95,6 +107,7 @@ InModuleScope MSFT_xComputer { } It 'Changes ComputerName and changes Domain to Workgroup' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Mock GetComputerDomain {'contoso.com'} Set-TargetResource -Name $NotComputerName -WorkGroupName 'contoso' -UnjoinCredential $Credential | Should BeNullOrEmpty Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$WorkGroupName -and $NewName} @@ -102,6 +115,7 @@ InModuleScope MSFT_xComputer { } It 'Changes ComputerName and changes Workgroup to Domain' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso';Workgroup='Contoso';PartOfDomain=$false}} + Mock GetComputerDomain {''} Set-TargetResource -Name $NotComputerName -DomainName 'Contoso.com' -Credential $Credential | Should BeNullOrEmpty Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName -and $NewName} @@ -109,6 +123,7 @@ InModuleScope MSFT_xComputer { } It 'Changes ComputerName and changes Workgroup to new Workgroup' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso';Workgroup='Contoso';PartOfDomain=$false}} + Mock GetComputerDomain {''} Set-TargetResource -Name $NotComputerName -WorkGroupName 'adventure-works' | Should BeNullOrEmpty Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$WorkGroupName -and $NewName} @@ -116,6 +131,7 @@ InModuleScope MSFT_xComputer { } It 'Changes only the Domain to new Domain' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Mock GetComputerDomain {'contoso.com'} Set-TargetResource -Name $Env:ComputerName -DomainName 'adventure-works.com' -Credential $Credential -UnjoinCredential $Credential | Should BeNullOrEmpty Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName} @@ -124,6 +140,7 @@ InModuleScope MSFT_xComputer { } It 'Changes only Domain to Workgroup' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Mock GetComputerDomain {''} Set-TargetResource -Name $Env:ComputerName -WorkGroupName 'Contoso' -UnjoinCredential $Credential | Should BeNullOrEmpty Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$NewName} @@ -132,11 +149,13 @@ InModuleScope MSFT_xComputer { } It 'Changes only ComputerName in Domain' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Mock GetComputerDomain {'contoso.com'} Set-TargetResource -Name $NotComputerName -Credential $Credential | Should BeNullOrEmpty Assert-MockCalled -CommandName Rename-Computer -Exactly 1 -Scope It Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It } It 'Changes only ComputerName in Workgroup' { + Mock GetComputerDomain {''} Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso';Workgroup='Contoso';PartOfDomain=$false}} Set-TargetResource -Name $NotComputerName | Should BeNullOrEmpty Assert-MockCalled -CommandName Rename-Computer -Exactly 1 -Scope It