From 23b18b18d1da57a94afe5d116713b3c3bb354407 Mon Sep 17 00:00:00 2001 From: Artem Iarmoliuk Date: Wed, 30 Nov 2016 02:29:06 +0200 Subject: [PATCH] Fixes SiteName beeing required (#126) * Adds unit test for this scenario * Add chack if sitename was specified or not * Fixes #119 --- .../MSFT_xADDomainController.psm1 | 2 +- README.md | 1 + Tests/Unit/MSFT_xADDomainController.Tests.ps1 | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/DSCResources/MSFT_xADDomainController/MSFT_xADDomainController.psm1 b/DSCResources/MSFT_xADDomainController/MSFT_xADDomainController.psm1 index 985909cec..59f920cd6 100644 --- a/DSCResources/MSFT_xADDomainController/MSFT_xADDomainController.psm1 +++ b/DSCResources/MSFT_xADDomainController/MSFT_xADDomainController.psm1 @@ -147,7 +147,7 @@ function Set-TargetResource elseif ($targetResource.Ensure) { ## Node is a domain controller. We check if other properties are in desired state - if ($targetResource.SiteName -ne $SiteName) + if ($PSBoundParameters["SiteName"] -and $targetResource.SiteName -ne $SiteName) { ## DC is not in correct site. Move it. Write-Verbose "Moving Domain Controller from '$($targetResource.SiteName)' to '$SiteName'" diff --git a/README.md b/README.md index d2a834a87..7fe393dad 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,7 @@ Setting an ODJ Request file path for a configuration that creates a computer acc ## Versions ### Unreleased +* xAdDomainController: Fixes SiteName being required field. ### 2.14.0.0 * xADDomainController: Adds Site option. diff --git a/Tests/Unit/MSFT_xADDomainController.Tests.ps1 b/Tests/Unit/MSFT_xADDomainController.Tests.ps1 index 891328cd1..50b3eb0f1 100644 --- a/Tests/Unit/MSFT_xADDomainController.Tests.ps1 +++ b/Tests/Unit/MSFT_xADDomainController.Tests.ps1 @@ -217,6 +217,21 @@ try Assert-MockCalled Move-ADDirectoryServer -Times 0 @commonAssertParams } + + It 'Does not call "Move-ADDirectoryServer" when "SiteName" is not specified' { + Mock Get-TargetResource { + return $stubTargetResource = @{ + Ensure = $true + SiteName = 'PresentSite' + } + } @commonMockParams + + Mock Move-ADDirectoryServer {} @commonMockParams + + Set-TargetResource @testDefaultParams -DomainName $correctDomainName + + Assert-MockCalled Move-ADDirectoryServer -Times 0 @commonAssertParams + } } #endregion }