Skip to content

Commit

Permalink
Move Set-DscADComputer to xActiveDirectory.Common
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed May 25, 2019
1 parent 9cb46af commit 8229604
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 48 deletions.
24 changes: 0 additions & 24 deletions DSCResources/MSFT_xADComputer/MSFT_xADComputer.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -953,30 +953,6 @@ function Set-TargetResource
}
}

<#
.SYNOPSIS
This is a wrapper for Set-ADComputer.
.PARAMETER Parameters
A hash table containing all parameters that will be passed trough to
Set-ADComputer.
.NOTES
This is needed because of how Pester is unable to handle mocking the
cmdlet Set-ADComputer.
#>
function Set-DscADComputer
{
param
(
[Parameter(Mandatory = $true)]
[System.Collections.Hashtable]
$Parameters
)

Set-ADComputer @Parameters | Out-Null
}

<#
.SYNOPSIS
This evaluates the service principal names current state against the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,27 +352,3 @@ function Set-TargetResource
}
}
}

<#
.SYNOPSIS
This is a wrapper for Set-ADComputer.
.PARAMETER Parameters
A hash table containing all parameters that will be passed trough to
Set-ADComputer.
.NOTES
This is needed because of how Pester is unable to handle mocking the
cmdlet Set-ADComputer.
#>
function Set-DscADComputer
{
param
(
[Parameter(Mandatory = $true)]
[System.Collections.Hashtable]
$Parameters
)

Set-ADComputer @Parameters | Out-Null
}
26 changes: 26 additions & 0 deletions Modules/xActiveDirectory.Common/xActiveDirectory.Common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,31 @@ function Start-ProcessWithTimeout
return $sqlSetupProcess.ExitCode
}

<#
.SYNOPSIS
This is a wrapper for Set-ADComputer.
.PARAMETER Parameters
A hash table containing all parameters that will be passed trough to
Set-ADComputer.
.NOTES
This is needed because of how Pester is unable to handle mocking the
cmdlet Set-ADComputer.
#>
function Set-DscADComputer
{
param
(
[Parameter(Mandatory = $true)]
[System.Collections.Hashtable]
$Parameters
)

Set-ADComputer @Parameters | Out-Null
}

# This row should be last in the module, just before the cmdlet Export-ModuleMember.
$script:localizedData = Get-LocalizedData -ResourceName 'xActiveDirectory.Common' -ScriptRoot $PSScriptRoot

Export-ModuleMember -Function @(
Expand All @@ -478,4 +503,5 @@ Export-ModuleMember -Function @(
'Get-LocalizedData'
'Test-DscParameterState'
'Start-ProcessWithTimeout'
'Set-DscADComputer'
)
37 changes: 37 additions & 0 deletions Tests/Unit/xActiveDirectory.Common.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -512,5 +512,42 @@ InModuleScope 'xActiveDirectory.Common' {
}
}
}

Describe 'DscResource.Common\Set-DscADComputer' {
Context 'When calling with a hashtable' {
BeforeAll {
<#
Pester is unable to mock the real cmdlet Set-ADComputer,
so this a dummy function to be able to mock the cmdlet
Set-ADComputer.
#>
function Set-ADComputer
{
param
(
[Parameter()]
[System.Collections.Hashtable]
$Replace
)
}

Mock -CommandName Set-ADComputer
}

It 'Should call Set-ADComputer with the correct parameter' {
{
Set-DscADComputer -Parameters @{
Replace = @{
Location = 'New location'
}
}
} | Should -Not -Throw

Assert-MockCalled -CommandName Set-ADComputer -ParameterFilter {
$Replace.ContainsKey('Location') -eq $true
} -Exactly -Times 1 -Scope It
}
}
}
}

0 comments on commit 8229604

Please sign in to comment.