diff --git a/CHANGELOG.md b/CHANGELOG.md index ab28a2a5a..9763e08e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +- Changes to ADReplicationSite + - Added 'Description' attribute parameter ([issue #500](https://github.com/PowerShell/ActiveDirectoryDsc/issues/500)). + - Added Integration testing ([issue #355](https://github.com/PowerShell/ActiveDirectoryDsc/issues/355)). + - Correct value returned for RenameDefaultFirstSiteName ([issue #502](https://github.com/PowerShell/ActiveDirectoryDsc/issues/502)). + ## 4.1.0.0 - Changes to ActiveDirectoryDsc diff --git a/DSCResources/MSFT_ADReplicationSite/MSFT_ADReplicationSite.psm1 b/DSCResources/MSFT_ADReplicationSite/MSFT_ADReplicationSite.psm1 index b90fde471..d4531b55b 100644 --- a/DSCResources/MSFT_ADReplicationSite/MSFT_ADReplicationSite.psm1 +++ b/DSCResources/MSFT_ADReplicationSite/MSFT_ADReplicationSite.psm1 @@ -21,13 +21,17 @@ function Get-TargetResource ( [Parameter(Mandatory = $true)] [System.String] - $Name + $Name, + + [Parameter()] + [System.Boolean] + $RenameDefaultFirstSiteName ) # Get the replication site filtered by it's name. If the site is not # present, the command will return $null. Write-Verbose -Message ($script:localizedData.GetReplicationSite -f $Name) - $replicationSite = Get-ADReplicationSite -Filter { Name -eq $Name } + $replicationSite = Get-ADReplicationSite -Filter { Name -eq $Name } -ErrorAction SilentlyContinue if ($null -eq $replicationSite) { @@ -35,7 +39,8 @@ function Get-TargetResource $returnValue = @{ Ensure = 'Absent' Name = $Name - RenameDefaultFirstSiteName = '' + Description = $null + RenameDefaultFirstSiteName = $RenameDefaultFirstSiteName } } else @@ -44,7 +49,8 @@ function Get-TargetResource $returnValue = @{ Ensure = 'Present' Name = $Name - RenameDefaultFirstSiteName = '' + Description = $replicationSite.Description + RenameDefaultFirstSiteName = $RenameDefaultFirstSiteName } } @@ -82,29 +88,54 @@ function Set-TargetResource [Parameter()] [System.Boolean] - $RenameDefaultFirstSiteName = $false + $RenameDefaultFirstSiteName = $false, + + [Parameter()] + [System.String] + $Description ) + $getTargetResourceResult = Get-TargetResource -Name $Name -RenameDefaultFirstSiteName $RenameDefaultFirstSiteName + if ($Ensure -eq 'Present') { - $defaultFirstSiteName = Get-ADReplicationSite -Filter { Name -eq 'Default-First-Site-Name' } - - <# - Check if the user specified to rename the Default-First-Site-Name - and if it still exists. If both is true, rename the replication site - instead of creating a new site. - #> - if ($RenameDefaultFirstSiteName -and ($null -ne $defaultFirstSiteName)) + if ($getTargetResourceResult.Ensure -eq 'Absent') { - Write-Verbose -Message ($script:localizedData.AddReplicationSiteDefaultFirstSiteName -f $Name) - - Rename-ADObject -Identity $defaultFirstSiteName.DistinguishedName -NewName $Name -ErrorAction Stop + $defaultFirstSiteName = Get-ADReplicationSite -Filter { Name -eq 'Default-First-Site-Name' } -ErrorAction SilentlyContinue + + <# + Check if the user specified to rename the Default-First-Site-Name + and if it still exists. If both is true, rename the replication site + instead of creating a new site. + #> + if ($RenameDefaultFirstSiteName -and $null -ne $defaultFirstSiteName) + { + Write-Verbose -Message ($script:localizedData.AddReplicationSiteDefaultFirstSiteName -f $Name) + + Rename-ADObject -Identity $defaultFirstSiteName.DistinguishedName -NewName $Name -ErrorAction Stop + } + else + { + Write-Verbose -Message ($script:localizedData.AddReplicationSite -f $Name) + + $newADReplicationSiteParameters = @{ + Name = $Name + ErrorAction = 'Stop' + } + + if ($PSBoundParameters.ContainsKey('Description')) + { + $newADReplicationSiteParameters['Description'] = $Description + } + + New-ADReplicationSite @newADReplicationSiteParameters + } } - else - { - Write-Verbose -Message ($script:localizedData.AddReplicationSite -f $Name) - New-ADReplicationSite -Name $Name -ErrorAction Stop + if ($PSBoundParameters.ContainsKey('Description') -and $getTargetResourceResult.Description -ne $Description) + { + Write-Verbose -Message ($script:localizedData.UpdateReplicationSite -f $Name) + Set-ADReplicationSite -Identity $Name -Description $Description } } @@ -130,6 +161,11 @@ function Set-TargetResource .PARAMETER RenameDefaultFirstSiteName Specify if the Default-First-Site-Name should be renamed, if it exists. Dafult value is 'false'. + + .PARAMETER Description + Specifies a description of the object. This parameter sets the value of + the Description property for the object. The LDAP Display Name + (ldapDisplayName) for this property is 'description'. #> function Test-TargetResource { @@ -148,18 +184,54 @@ function Test-TargetResource [Parameter()] [System.Boolean] - $RenameDefaultFirstSiteName = $false + $RenameDefaultFirstSiteName = $false, + + [Parameter()] + [System.String] + $Description ) - $currentConfiguration = Get-TargetResource -Name $Name + $getTargetResourceResult = Get-TargetResource -Name $Name -RenameDefaultFirstSiteName $RenameDefaultFirstSiteName + $configurationCompliant = $true - if ($currentConfiguration.Ensure -eq $Ensure) + if ($getTargetResourceResult.Ensure -eq 'Absent') { - Write-Verbose -Message ($script:localizedData.ReplicationSiteInDesiredState -f $Name) + # Site doesn't exist + if ($getTargetResourceResult.Ensure -eq $Ensure) + { + # Site should not exist + Write-Verbose -Message ($script:localizedData.ReplicationSiteInDesiredState -f $Name) + } + else + { + #Site should exist + Write-Verbose -Message ($script:localizedData.ReplicationSiteNotInDesiredState -f $Name) + $configurationCompliant = $false + } } else { - Write-Verbose -Message ($script:localizedData.ReplicationSiteNotInDesiredState -f $Name) + # Site Exists + if ($getTargetResourceResult.Ensure -eq $Ensure) + { + # Site should exist + if ($getTargetResourceResult.Description -ne $Description) + { + Write-Verbose -Message ($script:localizedData.ReplicationSiteNotInDesiredState -f $Name) + $configurationCompliant = $false + } + else + { + Write-Verbose -Message ($script:localizedData.ReplicationSiteInDesiredState -f $Name) + } + } + else + { + # Site should not exist + Write-Verbose -Message ($script:localizedData.ReplicationSiteNotInDesiredState -f $Name) + $configurationCompliant = $false + } } - return $currentConfiguration.Ensure -eq $Ensure + + return $configurationCompliant } diff --git a/DSCResources/MSFT_ADReplicationSite/MSFT_ADReplicationSite.schema.mof b/DSCResources/MSFT_ADReplicationSite/MSFT_ADReplicationSite.schema.mof index 024c63c7f..2993c35bf 100644 --- a/DSCResources/MSFT_ADReplicationSite/MSFT_ADReplicationSite.schema.mof +++ b/DSCResources/MSFT_ADReplicationSite/MSFT_ADReplicationSite.schema.mof @@ -4,4 +4,5 @@ class MSFT_ADReplicationSite : OMI_BaseResource [Write, Description("Specifies if the Active Directory replication site should be present or absent. Default value is 'Present'."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; [Key, Description("Specifies the name of the Active Directory replication site.")] String Name; [Write, Description("Specifies if the Default-First-Site-Name should be renamed if it exists. Default value is $false.")] Boolean RenameDefaultFirstSiteName; + [Write, Description("Specifies a description of the object. This parameter sets the value of the Description property for the object. The LDAP Display Name (ldapDisplayName) for this property is 'description'.")] String Description; }; diff --git a/DSCResources/MSFT_ADReplicationSite/en-US/MSFT_ADReplicationSite.strings.psd1 b/DSCResources/MSFT_ADReplicationSite/en-US/MSFT_ADReplicationSite.strings.psd1 index 533ed8515..7a30f4d3b 100644 --- a/DSCResources/MSFT_ADReplicationSite/en-US/MSFT_ADReplicationSite.strings.psd1 +++ b/DSCResources/MSFT_ADReplicationSite/en-US/MSFT_ADReplicationSite.strings.psd1 @@ -8,4 +8,5 @@ ConvertFrom-StringData @' ReplicationSitePresent = Replication site '{0}' is present. (ADRS0006) ReplicationSiteInDesiredState = The replication site '{0}' is in the desired state. (ADRS0007) ReplicationSiteNotInDesiredState = The replication site '{0}' is not in the desired state. (ADRS0008) + UpdateReplicationSite = The replication site '{0}' needs to be updated. '@ diff --git a/DSCResources/MSFT_ADReplicationSite/en-US/about_ADReplicationSite.help.txt b/DSCResources/MSFT_ADReplicationSite/en-US/about_ADReplicationSite.help.txt index bfe0abf62..5239711ba 100644 --- a/DSCResources/MSFT_ADReplicationSite/en-US/about_ADReplicationSite.help.txt +++ b/DSCResources/MSFT_ADReplicationSite/en-US/about_ADReplicationSite.help.txt @@ -21,6 +21,10 @@ Write - Boolean Specifies if the Default-First-Site-Name should be renamed if it exists. Default value is $false. +.PARAMETER Description + Write - String + Specifies a description of the object. This parameter sets the value of the Description property for the object. The LDAP Display Name (ldapDisplayName) for this property is 'description'. + .EXAMPLE 1 This configuration will create an Active Directory replication site @@ -80,4 +84,22 @@ Configuration ADReplicationSite_RemoveADReplicationSite_Config } } +.EXAMPLE 4 + +This configuration will set the AD Relication Site description for +a site called SeattleSite + +Configuration ADReplicationSite_CreateADReplicationSite_Config +{ + Import-DscResource -Module ActiveDirectoryDsc + Node localhost + { + ADReplicationSite 'SeattleSite' + { + Ensure = 'Present' + Name = 'Seattle' + Description = 'Seattle Head Office' + } + } +} diff --git a/Tests/Integration/MSFT_ADReplicationSite.Integration.Tests.ps1 b/Tests/Integration/MSFT_ADReplicationSite.Integration.Tests.ps1 new file mode 100644 index 000000000..da5674fed --- /dev/null +++ b/Tests/Integration/MSFT_ADReplicationSite.Integration.Tests.ps1 @@ -0,0 +1,192 @@ +if ($env:APPVEYOR -eq $true) +{ + Write-Warning -Message 'Integration test is not supported in AppVeyor.' + return +} + +$script:dscModuleName = 'ActiveDirectoryDsc' +$script:dscResourceFriendlyName = 'ADReplicationSite' +$script:dscResourceName = "MSFT_$($script:dscResourceFriendlyName)" + +#region HEADER +# Integration Test Template Version: 1.3.3 +[System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) +} + +Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force +$TestEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -TestType Integration +#endregion + +try +{ + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" + . $configFile + + Describe "$($script:dscResourceName)_Integration" { + + BeforeAll { + $resourceId = "[$($script:dscResourceFriendlyName)]Integration_Test" + } + + $configurationName = "$($script:dscResourceName)_CreateSite_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq $configurationName ` + -and $_.ResourceId -eq $resourceId + } + + $resourceCurrentState.Name | Should -Be 'NewADSite' + $resourceCurrentState.Description | Should -Be 'New AD site description' + } + + It 'Should return $true when Test-DscConfiguration is run' { + Test-DscConfiguration -Verbose | Should -Be 'True' + } + } + + $configurationName = "$($script:dscResourceName)_RemoveSite_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq $configurationName ` + -and $_.ResourceId -eq $resourceId + } + + $resourceCurrentState.IsSingleInstance | Should -BeNullOrEmpty + } + + It 'Should return $true when Test-DscConfiguration is run' { + Test-DscConfiguration -Verbose | Should -Be 'True' + } + } + + $configurationName = "$($script:dscResourceName)_RenameDefaultSite_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq $configurationName ` + -and $_.ResourceId -eq $resourceId + } + + $resourceCurrentState.Name | Should -Be 'RenamedDefaultADSite' + $resourceCurrentState.Description | Should -Be 'Renaming Default Site' + } + + It 'Should return $true when Test-DscConfiguration is run' { + Test-DscConfiguration -Verbose | Should -Be 'True' + } + } + } +} +finally +{ + #region FOOTER + + # Rename Site back to Default + $renamedSite = Get-ADReplicationSite -Filter { Name -eq 'RenamedDefaultADSite' } + if ($null -ne $renamedSite) + { + Set-ADReplicationSite -Identity $RenamedSite -Description $null + Rename-ADObject -Identity $RenamedSite.DistinguishedName -NewName 'Default-First-Site-Name' -ErrorAction Stop + } + Restore-TestEnvironment -TestEnvironment $TestEnvironment + #endregion +} diff --git a/Tests/Integration/MSFT_ADReplicationSite.config.ps1 b/Tests/Integration/MSFT_ADReplicationSite.config.ps1 new file mode 100644 index 000000000..6b6d01eaa --- /dev/null +++ b/Tests/Integration/MSFT_ADReplicationSite.config.ps1 @@ -0,0 +1,83 @@ +#region HEADER +# Integration Test Config Template Version: 1.2.0 +#endregion + +$configFile = [System.IO.Path]::ChangeExtension($MyInvocation.MyCommand.Path, 'json') +if (Test-Path -Path $configFile) +{ + <# + Allows reading the configuration data from a JSON file, for real testing + scenarios outside of the CI. + #> + $ConfigurationData = Get-Content -Path $configFile | ConvertFrom-Json +} +else +{ + $ConfigurationData = @{ + AllNodes = @( + @{ + NodeName = 'localhost' + CertificateFile = $env:DscPublicCertificatePath + } + ) + } +} + +<# + .SYNOPSIS + Creates a brand new Site in AD Sites and Services. +#> +Configuration MSFT_ADReplicationSite_CreateSite_Config +{ + Import-DscResource -ModuleName 'ActiveDirectoryDsc' + + node $AllNodes.NodeName + { + ADReplicationSite 'Integration_Test' + { + Name = 'NewADSite' + Description = 'New AD site description' + Ensure = 'Present' + } + } +} + +<# + .SYNOPSIS + Remove site from AD Sites and Services +#> +Configuration MSFT_ADReplicationSite_RemoveSite_Config +{ + Import-DscResource -ModuleName 'ActiveDirectoryDsc' + + node $AllNodes.NodeName + { + ADReplicationSite 'Integration_Test' + { + Name = 'NewADSite' + Description = 'New AD site description' + Ensure = 'Absent' + } + } +} + +<# + .SYNOPSIS + Rename the Default Site in Active Directory +#> +Configuration MSFT_ADReplicationSite_RenameDefaultSite_Config +{ + Import-DscResource -ModuleName 'ActiveDirectoryDsc' + + node $AllNodes.NodeName + { + ADReplicationSite 'Integration_Test' + { + Name = 'RenamedDefaultADSite' + Description = 'Renaming Default Site' + Ensure = 'Present' + RenameDefaultFirstSiteName = $true + } + } +} + diff --git a/Tests/Unit/MSFT_ADReplicationSite.Tests.ps1 b/Tests/Unit/MSFT_ADReplicationSite.Tests.ps1 index 005b3f4b4..4d33b035e 100644 --- a/Tests/Unit/MSFT_ADReplicationSite.Tests.ps1 +++ b/Tests/Unit/MSFT_ADReplicationSite.Tests.ps1 @@ -46,12 +46,14 @@ try # Load stub cmdlets and classes. Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectory_2019.psm1') -Force - $presentSiteName = 'DemoSite' - $absentSiteName = 'MissingSite' + $presentSiteName = 'DemoSite' + $absentSiteName = 'MissingSite' + $genericDescription = "Demonstration Site Description" $presentSiteMock = [PSCustomObject] @{ Name = $presentSiteName DistinguishedName = "CN=$presentSiteName,CN=Sites,CN=Configuration,DC=contoso,DC=com" + Description = $genericDescription } $defaultFirstSiteNameSiteMock = [PSCustomObject] @{ @@ -59,33 +61,51 @@ try DistinguishedName = "CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=contoso,DC=com" } + $absentSiteDefaultRenameMock = @{ + Ensure = 'Absent' + Name = $presentSiteTestPresent + Description = $null + RenameDefaultFirstSiteName = $true + } + $presentSiteTestPresent = @{ - Ensure = 'Present' - Name = $presentSiteName + Ensure = 'Present' + Name = $presentSiteName + Description = $genericDescription } $presentSiteTestAbsent = @{ Ensure = 'Absent' Name = $presentSiteName + Description = $genericDescription + } + + $presentSiteTestMismatchDescription = @{ + Ensure = 'Present' + Name = $presentSiteName + Description = 'Some random test description' } $absentSiteTestPresent = @{ Ensure = 'Present' Name = $absentSiteName + Description = $genericDescription } $absentSiteTestAbsent = @{ Ensure = 'Absent' Name = $absentSiteName + Description = $genericDescription } $presentSiteTestPresentRename = @{ Ensure = 'Present' Name = $presentSiteName + Description = $genericDescription RenameDefaultFirstSiteName = $true } #region Function Get-TargetResource - Describe 'ADReplicationSite\Get-TargetResource' { - It 'Should return a "System.Collections.Hashtable" object type' { + Describe 'When getting the Target Resource Information' { + It 'Should return a "System.Collections.Hashtable" object type with specified attributes' { # Arrange Mock -CommandName Get-ADReplicationSite -MockWith { $presentSiteMock } @@ -95,6 +115,9 @@ try # Assert $targetResource -is [System.Collections.Hashtable] | Should -BeTrue + $targetResource.Description | Should -BeOfType String + $targetResource.Name | Should -Not -BeNullOrEmpty + $targetResource.Ensure | Should -Not -BeNullOrEmpty } It 'Should return present if the site exists' { @@ -108,6 +131,7 @@ try # Assert $targetResource.Ensure | Should -Be 'Present' $targetResource.Name | Should -Be $presentSiteName + $targetResource.Description | Should -Be $genericDescription } It 'Should return absent if the site does not exist' { @@ -121,12 +145,13 @@ try # Assert $targetResource.Ensure | Should -Be 'Absent' $targetResource.Name | Should -Be $absentSiteName + $targetResource.Description | Should -BeNullOrEmpty } } #endregion #region Function Test-TargetResource - Describe 'ADReplicationSite\Test-TargetResource' { + Describe 'When testing the Target Resource configuration' { It 'Should return a "System.Boolean" object type' { # Arrange @@ -139,7 +164,7 @@ try $targetResourceState -is [System.Boolean] | Should -BeTrue } - It 'Should return true if the site should exists and does exists' { + It 'Should return true if the site should exist and does exist' { # Arrange Mock -CommandName Get-ADReplicationSite -MockWith { $presentSiteMock } @@ -151,7 +176,7 @@ try $targetResourceState | Should -BeTrue } - It 'Should return false if the site should exists but does not exists' { + It 'Should return false if the site should exist but does not exist' { # Arrange Mock -CommandName Get-ADReplicationSite @@ -163,7 +188,7 @@ try $targetResourceState | Should -BeFalse } - It 'Should return false if the site should not exists but does exists' { + It 'Should return false if the site should not exist but does exist' { # Arrange Mock -CommandName Get-ADReplicationSite -MockWith { $presentSiteMock } @@ -175,7 +200,7 @@ try $targetResourceState | Should -BeFalse } - It 'Should return true if the site should not exists and does not exists' { + It 'Should return true if the site should not exist and does not exist' { # Arrange Mock -CommandName Get-ADReplicationSite @@ -186,6 +211,18 @@ try # Assert $targetResourceState | Should -BeTrue } + + It 'Should return false if the site exists but the description is mismatched' { + + # Arrange + Mock -CommandName Get-ADReplicationSite { $presentSiteTestPresent } + + # Act + $targetResourceState = Test-TargetResource @presentSiteTestMismatchDescription + + # Assert + $targetResourceState | Should -BeFalse + } } #endregion @@ -197,6 +234,7 @@ try # Arrange Mock -CommandName Get-ADReplicationSite Mock -CommandName 'New-ADReplicationSite' -Verifiable + Mock -CommandName 'Set-ADReplicationSite' -Verifiable # Act Set-TargetResource @presentSiteTestPresent @@ -208,9 +246,11 @@ try It 'Should rename the Default-First-Site-Name if it exists' { # Arrange + Mock -CommandName Get-TargetResource -MockWith { $absentSiteDefaultRenameMock } Mock -CommandName Get-ADReplicationSite -MockWith { $defaultFirstSiteNameSiteMock } Mock -CommandName 'Rename-ADObject' -Verifiable Mock -CommandName 'New-ADReplicationSite' -Verifiable + Mock -CommandName Set-ADReplicationSite -Verifiable # Act Set-TargetResource @presentSiteTestPresentRename @@ -235,6 +275,16 @@ try Assert-MockCalled -CommandName 'New-ADReplicationSite' -Times 1 -Scope It } + It 'Should update a site if the description does not match' { + Mock -CommandName Get-ADReplicationSite -MockWith { $presentSiteTestPresent } + Mock -CommandName Set-ADReplicationSite -Verifiable + + Set-TargetResource @presentSiteTestMismatchDescription + + Assert-MockCalled -CommandName Set-ADReplicationSite -Times 1 -Scope It + Assert-MockCalled -CommandName Get-ADReplicationSite -Times 1 -Scope It -Exactly + } + It 'Should remove an existing site' { # Arrange