From 2cd1a6c229242abd062b990a147187cf1d894368 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 23 Jun 2020 18:18:47 +0100 Subject: [PATCH] ADDomainController: ReadOnlyReplica Fix --- CHANGELOG.md | 3 +++ .../MSFT_ADDomainController.psm1 | 2 +- tests/Unit/MSFT_ADDomainController.Tests.ps1 | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 809a7092e..1ec8949d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,9 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md) - Restored importing the `DscResource.Common` module import in the `ActiveDirectoryDsc.Common` module that was incorrectly disabled. ([issue #612](https://github.com/dsccommunity/ActiveDirectoryDsc/issues/612)). +- ADDomainController + - Fixed `Test-TargetResource` error when the `ReadOnlyReplica` property is set to `true` + ([issue #611](https://github.com/dsccommunity/ActiveDirectoryDsc/issues/611)). - ADReplicationSiteLink - Fixed setting options after the resource is initially created ([issue #605](https://github.com/dsccommunity/ActiveDirectoryDsc/issues/605)). diff --git a/source/DSCResources/MSFT_ADDomainController/MSFT_ADDomainController.psm1 b/source/DSCResources/MSFT_ADDomainController/MSFT_ADDomainController.psm1 index c0654d5de..c0a26c6a3 100644 --- a/source/DSCResources/MSFT_ADDomainController/MSFT_ADDomainController.psm1 +++ b/source/DSCResources/MSFT_ADDomainController/MSFT_ADDomainController.psm1 @@ -709,7 +709,7 @@ function Test-TargetResource if ($PSBoundParameters.ContainsKey('ReadOnlyReplica') -and $ReadOnlyReplica) { - if ($testTargetResourceReturnValue -and -not $testTargetResourceReturnValue.ReadOnlyReplica) + if ($testTargetResourceReturnValue -and -not $existingResource.ReadOnlyReplica) { New-InvalidOperationException -Message $script:localizedData.CannotConvertToRODC } diff --git a/tests/Unit/MSFT_ADDomainController.Tests.ps1 b/tests/Unit/MSFT_ADDomainController.Tests.ps1 index d5f49ce30..6296b1ff3 100644 --- a/tests/Unit/MSFT_ADDomainController.Tests.ps1 +++ b/tests/Unit/MSFT_ADDomainController.Tests.ps1 @@ -370,6 +370,7 @@ try AllowPasswordReplicationAccountName = @($allowedAccount) DenyPasswordReplicationAccountName = @($deniedAccount) FlexibleSingleMasterOperationRole = @('DomainNamingMaster', 'RIDMaster') + ReadOnlyReplica = $true Ensure = $true } } @@ -452,6 +453,18 @@ try Assert-MockCalled -CommandName Get-TargetResource -Exactly -Times 1 } } + + Context 'When property ReadOnlyReplica and SiteName are in desired state' { + It 'Should return $true' { + $result = Test-TargetResource @testDefaultParams -DomainName $correctDomainName ` + -ReadOnlyReplica $true -SiteName $correctSiteName + $result | Should -Be $true + } + + It 'Should call the expected mocks' { + Assert-MockCalled -CommandName Get-TargetResource -Exactly -Times 1 + } + } } Context 'When the system is not in the desired state' {