Tests/Integration/MSFT_ADReplicationSiteLink.Integration.Tests.ps1
if ($env:APPVEYOR -eq $true) { Write-Warning -Message 'Integration test is not supported in AppVeyor.' return } $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceFriendlyName = 'ADReplicationSiteLink' $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)_CreatePreReqs_Config" Context ('When setting up sites for testing site links') { 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 } } $configurationName = "$($script:dscResourceName)_CreateSiteLink_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 'Integration1-Integration2' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration1' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration2' } It 'Should return $true when Test-DscConfiguration is run' { Test-DscConfiguration -Verbose | Should -Be 'True' } } $configurationName = "$($script:dscResourceName)_AddMembers_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 'Integration1-Integration2' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration1' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration2' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration3' } It 'Should return $true when Test-DscConfiguration is run' { Test-DscConfiguration -Verbose | Should -Be 'True' } } $configurationName = "$($script:dscResourceName)_ExcludeMembers_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 'Integration1-Integration2' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration1' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration2' $resourceCurrentState.SitesIncluded | Should -Not -Contain 'Integration3' $resourceCurrentState.SitesExcluded | Should -Contain 'Integration3' } It 'Should return $true when Test-DscConfiguration is run' { Test-DscConfiguration -Verbose | Should -Be 'True' } } $configurationName = "$($script:dscResourceName)_SetAttributes_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 'Integration1-Integration2' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration1' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration2' $resourceCurrentState.Description | Should -Be 'Integration Test Site Link' $resourceCurrentState.Cost | Should -Be 20 $resourceCurrentState.ReplicationFrequencyInMinutes | Should -Be 15 } It 'Should return $true when Test-DscConfiguration is run' { Test-DscConfiguration -Verbose | Should -Be 'True' } } $configurationName = "$($script:dscResourceName)_SetChangeNotification_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 'Integration1-Integration2' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration1' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration2' $resourceCurrentState.Description | Should -Be 'Integration Test Site Link' $resourceCurrentState.Cost | Should -Be 20 $resourceCurrentState.ReplicationFrequencyInMinutes | Should -Be 15 $resourceCurrentState.OptionChangenotification | Should -BeTrue } It 'Should return $true when Test-DscConfiguration is run' { Test-DscConfiguration -Verbose | Should -Be 'True' } } $configurationName = "$($script:dscResourceName)_SetTwoWaySync_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 'Integration1-Integration2' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration1' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration2' $resourceCurrentState.Description | Should -Be 'Integration Test Site Link' $resourceCurrentState.Cost | Should -Be 20 $resourceCurrentState.ReplicationFrequencyInMinutes | Should -Be 15 $resourceCurrentState.OptionChangeNotification | Should -BeTrue $resourceCurrentState.OptionTwoWaySync | Should -BeTrue } It 'Should return $true when Test-DscConfiguration is run' { Test-DscConfiguration -Verbose | Should -Be 'True' } } $configurationName = "$($script:dscResourceName)_SetDisableCompression_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 'Integration1-Integration2' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration1' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration2' $resourceCurrentState.Description | Should -Be 'Integration Test Site Link' $resourceCurrentState.Cost | Should -Be 20 $resourceCurrentState.ReplicationFrequencyInMinutes | Should -Be 15 $resourceCurrentState.OptionChangeNotification | Should -BeTrue $resourceCurrentState.OptionTwoWaySync | Should -BeTrue $resourceCurrentState.OptionDisableCompression | Should -BeTrue } It 'Should return $true when Test-DscConfiguration is run' { Test-DscConfiguration -Verbose | Should -Be 'True' } } $configurationName = "$($script:dscResourceName)_ClearOptions_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 'Integration1-Integration2' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration1' $resourceCurrentState.SitesIncluded | Should -Contain 'Integration2' $resourceCurrentState.Description | Should -Be 'Integration Test Site Link' $resourceCurrentState.Cost | Should -Be 20 $resourceCurrentState.ReplicationFrequencyInMinutes | Should -Be 15 $resourceCurrentState.OptionChangeNotification | Should -BeFalse $resourceCurrentState.OptionTwoWaySync | Should -BeFalse $resourceCurrentState.OptionDisableCompression | Should -BeFalse } It 'Should return $true when Test-DscConfiguration is run' { Test-DscConfiguration -Verbose | Should -Be 'True' } } $configurationName = "$($script:dscResourceName)_RemoveSiteLink_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.Ensure | Should -Be 'Absent' } It 'Should return $true when Test-DscConfiguration is run' { Test-DscConfiguration -Verbose | Should -Be 'True' } } $configurationName = "$($script:dscResourceName)_DeletePreReqs_Config" Context ('When finishing, it should delete the test sites') { 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 } } } } finally { #region FOOTER Restore-TestEnvironment -TestEnvironment $TestEnvironment #endregion } |