diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fc8585d2..ae1285601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,15 @@ - New resource ADDomainControllerProperties ([issue #301](https://github.com/PowerShell/ActiveDirectoryDsc/issues/301)). - New resource ADForestFunctionalLevel ([issue #200](https://github.com/PowerShell/ActiveDirectoryDsc/issues/200)). - New resource ADDomainFunctionalLevel ([issue #200](https://github.com/PowerShell/ActiveDirectoryDsc/issues/200)). -- Changes to xWaitforADDomain + - Split the meta tests and the unit and integration tests in different + AppVeyor jobs ([issue #437](https://github.com/PowerShell/ActiveDirectoryDsc/issues/437)). + - Fixed all stub cmdlets and unit tests so the unit test can be run locally + without having the ActiveDirectory module installed on the computer. + This will also be reflected in the AppVeyor build worker where there + will no longer be an ActiveDirectory module installed. This is + to make sure that if the unit tests work locally they should also work + in the CI pipeline. +- Changes to xWaitForADDomain - Correct Grammar Issues in Example Descriptions. ## 4.0.0.0 diff --git a/DSCResources/MSFT_ADDomainDefaultPasswordPolicy/MSFT_ADDomainDefaultPasswordPolicy.psm1 b/DSCResources/MSFT_ADDomainDefaultPasswordPolicy/MSFT_ADDomainDefaultPasswordPolicy.psm1 index d6a6a8cf1..7ed0a9019 100644 --- a/DSCResources/MSFT_ADDomainDefaultPasswordPolicy/MSFT_ADDomainDefaultPasswordPolicy.psm1 +++ b/DSCResources/MSFT_ADDomainDefaultPasswordPolicy/MSFT_ADDomainDefaultPasswordPolicy.psm1 @@ -75,6 +75,7 @@ function Get-TargetResource [System.Management.Automation.CredentialAttribute()] $Credential ) + Assert-Module -ModuleName 'ActiveDirectory' $PSBoundParameters['Identity'] = $DomainName diff --git a/DSCResources/MSFT_ADDomainFunctionalLevel/en-US/about_ADDomainFunctionalLevel.help.txt b/DSCResources/MSFT_ADDomainFunctionalLevel/en-US/about_ADDomainFunctionalLevel.help.txt index 138cbc3b7..4a0f232c6 100644 --- a/DSCResources/MSFT_ADDomainFunctionalLevel/en-US/about_ADDomainFunctionalLevel.help.txt +++ b/DSCResources/MSFT_ADDomainFunctionalLevel/en-US/about_ADDomainFunctionalLevel.help.txt @@ -2,7 +2,7 @@ ADDomainFunctionalLevel .DESCRIPTION - This resource change the forest functional level. Functional levels can + This resource change the domain functional level. Functional levels can be read more about in the article [Forest and Domain Functional Levels](https://docs.microsoft.com/sv-se/windows-server/identity/ad-ds/active-directory-functional-levels). **WARNING: This action might be irreversibel!** Make sure to understand @@ -15,6 +15,8 @@ ## Requirements * Target machine must be running Windows Server 2008 R2 or later. + * Target machine must be running the minimum required operating system + version for the domain functional level to set. .PARAMETER DomainIdentity Key - String @@ -30,13 +32,13 @@ This configuration will change the domain functional level to a Windows Server 2012 R2 Domain. -Configuration ADDomainControllerProperties_SetContentFreshness_Config +Configuration ADDomainFunctionalLevel_SetLevel_Config { Import-DscResource -ModuleName ActiveDirectoryDsc node localhost { - ADDomainControllerProperties 'ChangeForestFunctionalLevel' + ADDomainFunctionalLevel 'ChangeDomainFunctionalLevel' { DomainIdentity = 'contoso.com' DomainMode = 'Windows2012R2Domain' diff --git a/DSCResources/MSFT_ADForestFunctionalLevel/en-US/about_ADForestFunctionalLevel.help.txt b/DSCResources/MSFT_ADForestFunctionalLevel/en-US/about_ADForestFunctionalLevel.help.txt index 794cfe6f1..4acff6d78 100644 --- a/DSCResources/MSFT_ADForestFunctionalLevel/en-US/about_ADForestFunctionalLevel.help.txt +++ b/DSCResources/MSFT_ADForestFunctionalLevel/en-US/about_ADForestFunctionalLevel.help.txt @@ -15,6 +15,8 @@ ## Requirements * Target machine must be running Windows Server 2008 R2 or later. + * Target machine must be running the minimum required operating system + version for the forest functional level to set. .PARAMETER ForestIdentity Key - String @@ -23,20 +25,20 @@ .PARAMETER ForestMode Required - String Allowed values: Windows2008R2Forest, Windows2012Forest, Windows2012R2Forest, Windows2016Forest - Specifies the the functional level for the Active Directory forest.. + Specifies the the functional level for the Active Directory forest. .EXAMPLE 1 This configuration will change the forest functional level to a Windows Server 2012 R2 Forest. -Configuration ADDomainControllerProperties_SetContentFreshness_Config +Configuration ADForestFunctionalLevel_SetLevel_Config { Import-DscResource -ModuleName ActiveDirectoryDsc node localhost { - ADDomainControllerProperties 'ChangeForestFunctionalLevel' + ADForestFunctionalLevel 'ChangeForestFunctionalLevel' { ForestIdentity = 'contoso.com' ForestMode = 'Windows2012R2Forest' diff --git a/DSCResources/MSFT_ADGroup/MSFT_ADGroup.psm1 b/DSCResources/MSFT_ADGroup/MSFT_ADGroup.psm1 index 44041186b..8ad323910 100644 --- a/DSCResources/MSFT_ADGroup/MSFT_ADGroup.psm1 +++ b/DSCResources/MSFT_ADGroup/MSFT_ADGroup.psm1 @@ -152,7 +152,16 @@ function Get-TargetResource try { - $adGroup = Get-ADGroup @adGroupParams -Property Name, GroupScope, GroupCategory, DistinguishedName, Description, DisplayName, ManagedBy, Info + $adGroup = Get-ADGroup @adGroupParams -Properties @( + 'Name', + 'GroupScope', + 'GroupCategory', + 'DistinguishedName', + 'Description', + 'DisplayName', + 'ManagedBy', + 'Info' + ) Write-Verbose -Message ($script:localizedData.RetrievingGroupMembers -f $MembershipAttribute) @@ -595,7 +604,16 @@ function Set-TargetResource } } - $adGroup = Get-ADGroup @adGroupParams -Property Name, GroupScope, GroupCategory, DistinguishedName, Description, DisplayName, ManagedBy, Info + $adGroup = Get-ADGroup @adGroupParams -Properties @( + 'Name', + 'GroupScope', + 'GroupCategory', + 'DistinguishedName', + 'Description', + 'DisplayName', + 'ManagedBy', + 'Info' + ) if ($Ensure -eq 'Present') { diff --git a/DSCResources/MSFT_ADManagedServiceAccount/MSFT_ADManagedServiceAccount.psm1 b/DSCResources/MSFT_ADManagedServiceAccount/MSFT_ADManagedServiceAccount.psm1 index ec26f1938..99f843f26 100644 --- a/DSCResources/MSFT_ADManagedServiceAccount/MSFT_ADManagedServiceAccount.psm1 +++ b/DSCResources/MSFT_ADManagedServiceAccount/MSFT_ADManagedServiceAccount.psm1 @@ -87,7 +87,7 @@ function Get-TargetResource { Write-Verbose -Message ($script:localizedData.RetrievingServiceAccount -f $ServiceAccountName) - $adServiceAccount = Get-ADServiceAccount @adServiceAccountParameters -Property @( + $adServiceAccount = Get-ADServiceAccount @adServiceAccountParameters -Properties @( 'Name' 'DistinguishedName' 'Description' @@ -117,7 +117,7 @@ function Get-TargetResource Write-Verbose -Message ($script:localizedData.RetrievingPrincipalMembers -f $MembershipAttribute) $adServiceAccount.PrincipalsAllowedToRetrieveManagedPassword | ForEach-Object { - $member = (Get-ADObject -Identity $_ -Property $MembershipAttribute).$MembershipAttribute + $member = (Get-ADObject -Identity $_ -Properties $MembershipAttribute).$MembershipAttribute $targetResource['Members'] += $member } diff --git a/DSCResources/MSFT_WaitForADDomain/en-US/about_WaitForADDomain.help.txt b/DSCResources/MSFT_WaitForADDomain/en-US/about_WaitForADDomain.help.txt index 848eac46e..ef75bdb52 100644 --- a/DSCResources/MSFT_WaitForADDomain/en-US/about_WaitForADDomain.help.txt +++ b/DSCResources/MSFT_WaitForADDomain/en-US/about_WaitForADDomain.help.txt @@ -45,7 +45,7 @@ This configuration will wait for an Active Directory domain controller to respond within 300 seconds (default) in the domain 'contoso.com' -before returning and allowing the configuration to continue run. +before returning and allowing the configuration to continue to run. If the timeout is reached an error will be thrown. This will use the current user when determining if the domain is available, if run though LCM this will use SYSTEM (which might not have access). @@ -67,9 +67,9 @@ Configuration WaitForADDomain_WaitForDomainController_Config This configuration will wait for an Active Directory domain controller to respond within 300 seconds (default) in the domain 'contoso.com' -before returning and allowing the configuration to continue run. +before returning and allowing the configuration to continue to run. If the timeout is reached an error will be thrown. -This will use the user credential passes to the built-in PsDscRunAsCredential +This will use the user credential passed in the built-in PsDscRunAsCredential parameter when determining if the domain is available. Configuration WaitForADDomain_WaitForDomainControllerUsingBuiltInCredential_Config @@ -99,9 +99,9 @@ Configuration WaitForADDomain_WaitForDomainControllerUsingBuiltInCredential_Conf This configuration will wait for an Active Directory domain controller to respond within 300 seconds (default) in the domain 'contoso.com' -before returning and allowing the configuration to continue run. +before returning and allowing the configuration to continue to run. If the timeout is reached an error will be thrown. -This will use the user credential passes to the parameter Credential +This will use the user credential passed in the parameter Credential when determining if the domain is available. Configuration WaitForADDomain_WaitForDomainControllerUsingCredential_Config @@ -131,9 +131,9 @@ Configuration WaitForADDomain_WaitForDomainControllerUsingCredential_Config This configuration will wait for an Active Directory domain controller in the site 'Europe' to respond within 300 seconds (default) in the domain 'contoso.com' before returning and allowing the configuration to -continue run. +continue to run. If the timeout is reached an error will be thrown. -This will use the user credential passes to the built-in PsDscRunAsCredential +This will use the user credential passed in the built-in PsDscRunAsCredential parameter when determining if the domain is available. Configuration WaitForADDomain_WaitForDomainControllerInSite_Config @@ -164,11 +164,11 @@ Configuration WaitForADDomain_WaitForDomainControllerInSite_Config This configuration will wait for an Active Directory domain controller to respond within 300 seconds (default) in the domain 'contoso.com' -before returning and allowing the configuration to continue run. +before returning and allowing the configuration to continue to run. If the timeout is reached the node will be restarted up to two times -and again wait after each restart. If the no domain controller is found +and again wait after each restart. If no domain controller is found after the second restart an error will be thrown. -This will use the user credential passes to the built-in PsDscRunAsCredential +This will use the user credential passed in the built-in PsDscRunAsCredential parameter when determining if the domain is available. Configuration WaitForADDomain_WaitForDomainControllerWithReboot_Config @@ -187,9 +187,9 @@ Configuration WaitForADDomain_WaitForDomainControllerWithReboot_Config { WaitForADDomain 'contoso.com' { - DomainName = 'contoso.com' + DomainName = 'contoso.com' RestartCount = 2 - + PsDscRunAsCredential = $Credential } } @@ -199,9 +199,9 @@ Configuration WaitForADDomain_WaitForDomainControllerWithReboot_Config This configuration will wait for an Active Directory domain controller to respond within 600 seconds in the domain 'contoso.com' before -returning and allowing the configuration to continue run. If the timeout +returning and allowing the configuration to continue to run. If the timeout is reached an error will be thrown. -This will use the user credential passes to the built-in PsDscRunAsCredential +This will use the user credential passed in the built-in PsDscRunAsCredential parameter when determining if the domain is available. Configuration WaitForADDomain_WaitForDomainControllerWithLongerDelay_Config @@ -220,7 +220,7 @@ Configuration WaitForADDomain_WaitForDomainControllerWithLongerDelay_Config { WaitForADDomain 'contoso.com' { - DomainName = 'contoso.com' + DomainName = 'contoso.com' WaitTimeout = 600 PsDscRunAsCredential = $Credential diff --git a/Tests/TestHelpers/ActiveDirectoryDsc.TestHelper.psm1 b/Tests/TestHelpers/ActiveDirectoryDsc.TestHelper.psm1 new file mode 100644 index 000000000..12aa5d82a --- /dev/null +++ b/Tests/TestHelpers/ActiveDirectoryDsc.TestHelper.psm1 @@ -0,0 +1,91 @@ +<# + .SYNOPSIS + Returns $true if the the environment variable APPVEYOR is set to $true, + and the environment variable CONFIGURATION is set to the value passed + in the parameter Type. + + .PARAMETER Name + Name of the test script that is called. Defaults to the name of the + calling script. + + .PARAMETER Type + Type of tests in the test file. Can be set to Unit or Integration. + + .PARAMETER Category + Optional. One or more categories to check if they are set in + $env:CONFIGURATION. If this are not set, the parameter Type + is used as category. +#> +function Test-RunForCITestCategory +{ + [OutputType([System.Boolean])] + [CmdletBinding()] + param + ( + [Parameter()] + [ValidateNotNullOrEmpty()] + [System.String] + $Name = $MyInvocation.PSCommandPath.Split('\')[-1], + + [Parameter(Mandatory = $true)] + [ValidateSet('Unit', 'Integration')] + [System.String] + $Type, + + [Parameter()] + [System.String[]] + $Category + ) + + # Support the use of having the Type parameter as the only category names. + if (-not $Category) + { + $Category = @($Type) + } + + $result = $true + + if ($Type -eq 'Integration' -and -not $env:CI -eq $true) + { + Write-Warning -Message ('{0} test for {1} will be skipped unless $env:CI is set to $true' -f $Type, $Name) + $result = $false + } + + if (-not (Test-ContinuousIntegrationTaskCategory -Category $Category)) + { + Write-Verbose -Message ('Tests in category ''{0}'' will be skipped unless $env:CONFIGURATION is set to ''{0}''.' -f ($Category -join ''', or '''), $Name) -Verbose + $result = $false + } + + return $result +} + +<# + .SYNOPSIS + Returns $true if the the environment variable CI is set to $true, + and the environment variable CONFIGURATION is set to the value passed + in the parameter Type. + + .PARAMETER Category + One or more categories to check if they are set in $env:CONFIGURATION. +#> +function Test-ContinuousIntegrationTaskCategory +{ + [OutputType([System.Boolean])] + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [System.String[]] + $Category + ) + + $result = $true + + if ($env:CI -eq $true -and $env:CONFIGURATION -notin $Category) + { + $result = $false + } + + return $result +} diff --git a/Tests/Unit/ActiveDirectory.Common.Tests.ps1 b/Tests/Unit/ActiveDirectory.Common.Tests.ps1 index 568d768fb..58a127455 100644 --- a/Tests/Unit/ActiveDirectory.Common.Tests.ps1 +++ b/Tests/Unit/ActiveDirectory.Common.Tests.ps1 @@ -8,25 +8,35 @@ #> Get-Module -Name 'ActiveDirectoryDsc.Common' -All | Remove-Module -Force +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + # Import the ActiveDirectoryDsc.Common module to test $script:resourceModulePath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent $script:modulesFolderPath = Join-Path -Path $script:resourceModulePath -ChildPath 'Modules\ActiveDirectoryDsc.Common' Import-Module -Name (Join-Path -Path $script:modulesFolderPath -ChildPath 'ActiveDirectoryDsc.Common.psm1') -Force -# If one type does not exist, it's assumed the other ones does not exist either. -if (-not ('Microsoft.DirectoryServices.Deployment.Types.ForestMode' -as [Type])) -{ - Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.DirectoryServices.Deployment.Types.cs') -} +InModuleScope 'ActiveDirectoryDsc.Common' { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force -# If one type does not exist, it's assumed the other ones does not exist either. -if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) -{ - Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') -} + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.DirectoryServices.Deployment.Types.ForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.DirectoryServices.Deployment.Types.cs') + } + + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') + } -InModuleScope 'ActiveDirectoryDsc.Common' { Describe 'ActiveDirectoryDsc.Common\Test-DscParameterState' -Tag TestDscParameterState { Context 'When passing values' { It 'Should return true for two identical tables' { diff --git a/Tests/Unit/MSFT_ADComputer.Tests.ps1 b/Tests/Unit/MSFT_ADComputer.Tests.ps1 index 3aebc6b2c..29f1ba6a8 100644 --- a/Tests/Unit/MSFT_ADComputer.Tests.ps1 +++ b/Tests/Unit/MSFT_ADComputer.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADComputer' diff --git a/Tests/Unit/MSFT_ADDomain.Tests.ps1 b/Tests/Unit/MSFT_ADDomain.Tests.ps1 index ff804864b..0c6cf2196 100644 --- a/Tests/Unit/MSFT_ADDomain.Tests.ps1 +++ b/Tests/Unit/MSFT_ADDomain.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADDomain' @@ -47,6 +54,15 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') + } + $correctDomainName = 'present.com' $incorrectDomainName = 'incorrect.com' $missingDomainName = 'missing.com' @@ -148,7 +164,7 @@ try It 'Throws "Invalid credentials" when domain is available but authentication fails' { Mock -CommandName Get-ADDomain -ParameterFilter { $Identity.ToString() -eq $incorrectDomainName } -MockWith { - throw New-Object System.Security.Authentication.AuthenticationException + throw New-Object -TypeName 'System.Security.Authentication.AuthenticationException' } # Match operator is case-sensitive! @@ -157,7 +173,7 @@ try It 'Throws "Computer is already a domain member" when is already a domain member' { Mock -CommandName Get-ADDomain -ParameterFilter { $Identity.ToString() -eq $incorrectDomainName } -MockWith { - throw New-Object Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException + throw New-Object -TypeName 'Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException' } { Get-TargetResource @testDefaultParams -DomainName $incorrectDomainName } | Should -Throw ($script:localizedData.ExistingDomainMemberError -f $incorrectDomainName) @@ -165,7 +181,7 @@ try It 'Does not throw when domain cannot be located' { Mock -CommandName Get-ADDomain -ParameterFilter { $Identity.ToString() -eq $missingDomainName } -MockWith { - throw New-Object Microsoft.ActiveDirectory.Management.ADServerDownException + throw New-Object -TypeName 'Microsoft.ActiveDirectory.Management.ADServerDownException' } { Get-TargetResource @testDefaultParams -DomainName $missingDomainName } | Should -Not -Throw diff --git a/Tests/Unit/MSFT_ADDomainController.Tests.ps1 b/Tests/Unit/MSFT_ADDomainController.Tests.ps1 index 811a375ab..0af5ff13e 100644 --- a/Tests/Unit/MSFT_ADDomainController.Tests.ps1 +++ b/Tests/Unit/MSFT_ADDomainController.Tests.ps1 @@ -1,6 +1,13 @@ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')] param () +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + #region HEADER $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADDomainController' @@ -141,6 +148,10 @@ try #region Function Get-TargetResource Describe 'ADDomainController\Get-TargetResource' -Tag 'Get' { + BeforeAll { + Mock -CommandName Assert-Module + } + Context 'When the domain name is not available' { BeforeAll { Mock -CommandName Get-ADDomain -MockWith { diff --git a/Tests/Unit/MSFT_ADDomainControllerProperties.Tests.ps1 b/Tests/Unit/MSFT_ADDomainControllerProperties.Tests.ps1 index 2e22143ca..0b9008fe9 100644 --- a/Tests/Unit/MSFT_ADDomainControllerProperties.Tests.ps1 +++ b/Tests/Unit/MSFT_ADDomainControllerProperties.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADDomainControllerProperties' diff --git a/Tests/Unit/MSFT_ADDomainDefaultPasswordPolicy.Tests.ps1 b/Tests/Unit/MSFT_ADDomainDefaultPasswordPolicy.Tests.ps1 index 699bf4d3f..5ebaa6a16 100644 --- a/Tests/Unit/MSFT_ADDomainDefaultPasswordPolicy.Tests.ps1 +++ b/Tests/Unit/MSFT_ADDomainDefaultPasswordPolicy.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADDomainDefaultPasswordPolicy' @@ -36,6 +43,9 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + $testDomainName = 'contoso.com' $testDefaultParams = @{ DomainName = $testDomainName diff --git a/Tests/Unit/MSFT_ADDomainFunctionalLevel.Tests.ps1 b/Tests/Unit/MSFT_ADDomainFunctionalLevel.Tests.ps1 index 4305684a4..c492c7b83 100644 --- a/Tests/Unit/MSFT_ADDomainFunctionalLevel.Tests.ps1 +++ b/Tests/Unit/MSFT_ADDomainFunctionalLevel.Tests.ps1 @@ -238,6 +238,32 @@ try Assert-MockCalled -CommandName Set-ADDomainMode -Exactly -Times 1 -Scope It } } + + Context 'When desired domain mode should be ''Windows2016Domain''' { + BeforeAll { + Mock -CommandName Set-ADDomainMode + Mock -CommandName Compare-TargetResourceState -MockWith { + return @( + @{ + ParameterName = 'DomainMode' + Actual = 'Windows2012R2Domain' + Expected = 'Windows2016Domain' + InDesiredState = $false + } + ) + } + + $setTargetResourceParameters = $mockDefaultParameters.Clone() + $setTargetResourceParameters['DomainMode'] = 'Windows2016Domain' + } + + It 'Should not throw and call the correct mocks' { + { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + + Assert-MockCalled -CommandName Compare-TargetResourceState -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-ADDomainMode -Exactly -Times 1 -Scope It + } + } } } } diff --git a/Tests/Unit/MSFT_ADDomainTrust.Tests.ps1 b/Tests/Unit/MSFT_ADDomainTrust.Tests.ps1 index c61e4eeec..c11b68712 100644 --- a/Tests/Unit/MSFT_ADDomainTrust.Tests.ps1 +++ b/Tests/Unit/MSFT_ADDomainTrust.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADDomainTrust' diff --git a/Tests/Unit/MSFT_ADForestProperties.Tests.ps1 b/Tests/Unit/MSFT_ADForestProperties.Tests.ps1 index 5f9acd488..c2eca3532 100644 --- a/Tests/Unit/MSFT_ADForestProperties.Tests.ps1 +++ b/Tests/Unit/MSFT_ADForestProperties.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADForestProperties' @@ -36,6 +43,15 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') + } + $forestName = 'contoso.com' $testCredential = [System.Management.Automation.PSCredential]::Empty diff --git a/Tests/Unit/MSFT_ADGroup.Tests.ps1 b/Tests/Unit/MSFT_ADGroup.Tests.ps1 index fcd496023..44de37575 100644 --- a/Tests/Unit/MSFT_ADGroup.Tests.ps1 +++ b/Tests/Unit/MSFT_ADGroup.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADGroup' @@ -36,6 +43,15 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') + } + $testPresentParams = @{ GroupName = 'TestGroup' GroupScope = 'Global' diff --git a/Tests/Unit/MSFT_ADKDSKey.Tests.ps1 b/Tests/Unit/MSFT_ADKDSKey.Tests.ps1 index 595cef416..78d47a9bb 100644 --- a/Tests/Unit/MSFT_ADKDSKey.Tests.ps1 +++ b/Tests/Unit/MSFT_ADKDSKey.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADKDSKey' @@ -36,6 +43,15 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') + } + # Need to do a deep copy of the Array of objects that compare returns function Copy-ArrayObjects { diff --git a/Tests/Unit/MSFT_ADManagedServiceAccount.Tests.ps1 b/Tests/Unit/MSFT_ADManagedServiceAccount.Tests.ps1 index b045f775b..c8e3a659d 100644 --- a/Tests/Unit/MSFT_ADManagedServiceAccount.Tests.ps1 +++ b/Tests/Unit/MSFT_ADManagedServiceAccount.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADManagedServiceAccount' @@ -36,6 +43,15 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') + } + # Need to do a deep copy of the Array of objects that compare returns function Copy-ArrayObjects { diff --git a/Tests/Unit/MSFT_ADObjectEnabledState.Tests.ps1 b/Tests/Unit/MSFT_ADObjectEnabledState.Tests.ps1 index e9169090b..7e2b8b5e6 100644 --- a/Tests/Unit/MSFT_ADObjectEnabledState.Tests.ps1 +++ b/Tests/Unit/MSFT_ADObjectEnabledState.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADObjectEnabledState' @@ -37,6 +44,15 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') + } + $mockComputerNamePresent = 'TEST01' $mockDomain = 'contoso.com' $mockEnabled = $true diff --git a/Tests/Unit/MSFT_ADObjectPermissionEntry.Tests.ps1 b/Tests/Unit/MSFT_ADObjectPermissionEntry.Tests.ps1 index eb6909d9e..ef2720a46 100644 --- a/Tests/Unit/MSFT_ADObjectPermissionEntry.Tests.ps1 +++ b/Tests/Unit/MSFT_ADObjectPermissionEntry.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADObjectPermissionEntry' @@ -36,6 +43,9 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + #region Pester Test Initialization $testDefaultParameters = @{ Path = 'CN=PC01,CN=Computers,DC=contoso,DC=com' diff --git a/Tests/Unit/MSFT_ADOptionalFeature.Tests.ps1 b/Tests/Unit/MSFT_ADOptionalFeature.Tests.ps1 index 6fec77e2a..eae56411d 100644 --- a/Tests/Unit/MSFT_ADOptionalFeature.Tests.ps1 +++ b/Tests/Unit/MSFT_ADOptionalFeature.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADOptionalFeature' @@ -36,6 +43,9 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + # If one type does not exist, it's assumed the other ones does not exist either. if (-not ('Microsoft.ActiveDirectory.Management.ADComputer' -as [Type])) { diff --git a/Tests/Unit/MSFT_ADOrganizationalUnit.Tests.ps1 b/Tests/Unit/MSFT_ADOrganizationalUnit.Tests.ps1 index ed6a5986f..9ea7a7b3e 100644 --- a/Tests/Unit/MSFT_ADOrganizationalUnit.Tests.ps1 +++ b/Tests/Unit/MSFT_ADOrganizationalUnit.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADOrganizationalUnit' diff --git a/Tests/Unit/MSFT_ADReplicationSite.Tests.ps1 b/Tests/Unit/MSFT_ADReplicationSite.Tests.ps1 index 1d57f8712..b45792b1b 100644 --- a/Tests/Unit/MSFT_ADReplicationSite.Tests.ps1 +++ b/Tests/Unit/MSFT_ADReplicationSite.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADReplicationSite' @@ -36,7 +43,15 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { - #region Pester Test Initialization + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') + } + $presentSiteName = 'DemoSite' $absentSiteName = 'MissingSite' @@ -73,14 +88,13 @@ try Name = $presentSiteName RenameDefaultFirstSiteName = $true } - # #endregion #region Function Get-TargetResource Describe 'ADReplicationSite\Get-TargetResource' { It 'Should return a "System.Collections.Hashtable" object type' { # Arrange - Mock -CommandName 'Get-ADReplicationSite' -MockWith { $presentSiteMock } + Mock -CommandName Get-ADReplicationSite -MockWith { $presentSiteMock } # Act $targetResource = Get-TargetResource -Name $presentSiteName @@ -92,7 +106,7 @@ try It 'Should return present if the site exists' { # Arrange - Mock -CommandName 'Get-ADReplicationSite' -MockWith { $presentSiteMock } + Mock -CommandName Get-ADReplicationSite -MockWith { $presentSiteMock } # Act $targetResource = Get-TargetResource -Name $presentSiteName @@ -105,7 +119,7 @@ try It 'Should return absent if the site does not exist' { # Arrange - Mock -CommandName 'Get-ADReplicationSite' + Mock -CommandName Get-ADReplicationSite # Act $targetResource = Get-TargetResource -Name $absentSiteName @@ -122,7 +136,7 @@ try It 'Should return a "System.Boolean" object type' { # Arrange - Mock -CommandName 'Get-ADReplicationSite' -MockWith { $presentSiteMock } + Mock -CommandName Get-ADReplicationSite -MockWith { $presentSiteMock } # Act $targetResourceState = Test-TargetResource @presentSiteTestPresent @@ -134,7 +148,7 @@ try It 'Should return true if the site should exists and does exists' { # Arrange - Mock -CommandName 'Get-ADReplicationSite' -MockWith { $presentSiteMock } + Mock -CommandName Get-ADReplicationSite -MockWith { $presentSiteMock } # Act $targetResourceState = Test-TargetResource @presentSiteTestPresent @@ -146,7 +160,7 @@ try It 'Should return false if the site should exists but does not exists' { # Arrange - Mock -CommandName 'Get-ADReplicationSite' + Mock -CommandName Get-ADReplicationSite # Act $targetResourceState = Test-TargetResource @absentSiteTestPresent @@ -158,7 +172,7 @@ try It 'Should return false if the site should not exists but does exists' { # Arrange - Mock -CommandName 'Get-ADReplicationSite' -MockWith { $presentSiteMock } + Mock -CommandName Get-ADReplicationSite -MockWith { $presentSiteMock } # Act $targetResourceState = Test-TargetResource @presentSiteTestAbsent @@ -170,7 +184,7 @@ try It 'Should return true if the site should not exists and does not exists' { # Arrange - Mock -CommandName 'Get-ADReplicationSite' + Mock -CommandName Get-ADReplicationSite # Act $targetResourceState = Test-TargetResource @absentSiteTestAbsent @@ -187,7 +201,7 @@ try It 'Should add a new site' { # Arrange - Mock -CommandName 'Get-ADReplicationSite' + Mock -CommandName Get-ADReplicationSite Mock -CommandName 'New-ADReplicationSite' -Verifiable # Act @@ -200,7 +214,7 @@ try It 'Should rename the Default-First-Site-Name if it exists' { # Arrange - Mock -CommandName 'Get-ADReplicationSite' -MockWith { $defaultFirstSiteNameSiteMock } + Mock -CommandName Get-ADReplicationSite -MockWith { $defaultFirstSiteNameSiteMock } Mock -CommandName 'Rename-ADObject' -Verifiable Mock -CommandName 'New-ADReplicationSite' -Verifiable @@ -215,7 +229,7 @@ try It 'Should add a new site if the Default-First-Site-Name does not exist' { # Arrange - Mock -CommandName 'Get-ADReplicationSite' + Mock -CommandName Get-ADReplicationSite Mock -CommandName 'Rename-ADObject' -Verifiable Mock -CommandName 'New-ADReplicationSite' -Verifiable @@ -230,7 +244,7 @@ try It 'Should remove an existing site' { # Arrange - Mock -CommandName 'Get-ADReplicationSite' -MockWith { $presentSiteMock } + Mock -CommandName Get-ADReplicationSite -MockWith { $presentSiteMock } Mock -CommandName 'Remove-ADReplicationSite' -Verifiable # Act diff --git a/Tests/Unit/MSFT_ADReplicationSiteLink.tests.ps1 b/Tests/Unit/MSFT_ADReplicationSiteLink.tests.ps1 index a32dd7f99..39d6de0f9 100644 --- a/Tests/Unit/MSFT_ADReplicationSiteLink.tests.ps1 +++ b/Tests/Unit/MSFT_ADReplicationSiteLink.tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADReplicationSiteLink' @@ -36,6 +43,15 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') + } + $mockGetADReplicationSiteLinkReturn = @{ Name = 'HQSiteLink' Cost = 100 diff --git a/Tests/Unit/MSFT_ADReplicationSubnet.Tests.ps1 b/Tests/Unit/MSFT_ADReplicationSubnet.Tests.ps1 index e6bfa20ab..ff1115667 100644 --- a/Tests/Unit/MSFT_ADReplicationSubnet.Tests.ps1 +++ b/Tests/Unit/MSFT_ADReplicationSubnet.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADReplicationSubnet' @@ -36,6 +43,15 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') + } + #region Function Get-TargetResource Describe 'ADReplicationSubnet\Get-TargetResource' { $testDefaultParameters = @{ diff --git a/Tests/Unit/MSFT_ADServicePrincipalName.Tests.ps1 b/Tests/Unit/MSFT_ADServicePrincipalName.Tests.ps1 index 55dd468a6..c2a572141 100644 --- a/Tests/Unit/MSFT_ADServicePrincipalName.Tests.ps1 +++ b/Tests/Unit/MSFT_ADServicePrincipalName.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADServicePrincipalName' @@ -36,6 +43,15 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') + } + #region Function Get-TargetResource Describe 'ADServicePrincipalName\Get-TargetResource' { $testDefaultParameters = @{ @@ -43,11 +59,9 @@ try } Context 'No SPN set' { - Mock -CommandName Get-ADObject It 'Should return absent' { - $result = Get-TargetResource @testDefaultParameters $result.Ensure | Should -Be 'Absent' @@ -57,13 +71,13 @@ try } Context 'One SPN set' { - Mock -CommandName Get-ADObject -MockWith { - [PSCustomObject] @{ SamAccountName = 'User' } + return [PSCustomObject] @{ + SamAccountName = 'User' + } } It 'Should return present with the correct account' { - $result = Get-TargetResource @testDefaultParameters $result.Ensure | Should -Be 'Present' @@ -73,14 +87,18 @@ try } Context 'Multiple SPN set' { - Mock -CommandName Get-ADObject -MockWith { - [PSCustomObject] @{ SamAccountName = 'User' }, - [PSCustomObject] @{ SamAccountName = 'Computer' } + return @( + [PSCustomObject] @{ + SamAccountName = 'User' + }, + [PSCustomObject] @{ + SamAccountName = 'Computer' + } + ) } It 'Should return present with the multiple accounts' { - $result = Get-TargetResource @testDefaultParameters $result.Ensure | Should -Be 'Present' @@ -99,75 +117,73 @@ try } Context 'No SPN set' { - Mock -CommandName Get-ADObject It 'Should return false for present' { - $result = Test-TargetResource -Ensure 'Present' @testDefaultParameters $result | Should -BeFalse } It 'Should return true for absent' { - $result = Test-TargetResource -Ensure 'Absent' @testDefaultParameters $result | Should -BeTrue } } Context 'Correct SPN set' { - Mock -CommandName Get-ADObject -MockWith { - [PSCustomObject] @{ SamAccountName = 'User' } + return [PSCustomObject] @{ + SamAccountName = 'User' + } } It 'Should return true for present' { - $result = Test-TargetResource -Ensure 'Present' @testDefaultParameters $result | Should -BeTrue } It 'Should return false for absent' { - $result = Test-TargetResource -Ensure 'Absent' @testDefaultParameters $result | Should -BeFalse } } Context 'Wrong SPN set' { - Mock -CommandName Get-ADObject -MockWith { - [PSCustomObject] @{ SamAccountName = 'Computer' } + return [PSCustomObject] @{ + SamAccountName = 'Computer' + } } It 'Should return false for present' { - $result = Test-TargetResource -Ensure 'Present' @testDefaultParameters $result | Should -BeFalse } It 'Should return false for absent' { - $result = Test-TargetResource -Ensure 'Absent' @testDefaultParameters $result | Should -BeFalse } } Context 'Multiple SPN set' { - Mock -CommandName Get-ADObject -MockWith { - [PSCustomObject] @{ SamAccountName = 'User' }, - [PSCustomObject] @{ SamAccountName = 'Computer' } + return @( + [PSCustomObject] @{ + SamAccountName = 'User' + }, + [PSCustomObject] @{ + SamAccountName = 'Computer' + } + ) } It 'Should return false for present' { - $result = Test-TargetResource -Ensure 'Present' @testDefaultParameters $result | Should -BeFalse } It 'Should return false for absent' { - $result = Test-TargetResource -Ensure 'Absent' @testDefaultParameters $result | Should -BeFalse } @@ -190,44 +206,50 @@ try } Context 'AD Object not existing' { - Mock -CommandName Get-ADObject It 'Should throw the correct exception' { - { Set-TargetResource @testPresentParams } | Should -Throw ($script:localizedData.AccountNotFound -f $testPresentParams.Account) } } Context 'No SPN set' { + Mock -CommandName Set-ADObject + Mock -CommandName Get-ADObject -ParameterFilter { + $Filter -eq ([ScriptBlock]::Create(' ServicePrincipalName -eq $ServicePrincipalName ')) + } - Mock -CommandName Get-ADObject -ParameterFilter { $Filter -eq ([ScriptBlock]::Create(' ServicePrincipalName -eq $ServicePrincipalName ')) } Mock -CommandName Get-ADObject -MockWith { - [PSCustomObject] @{ SamAccountName = 'User' } + return 'User' } - Mock -CommandName Set-ADObject It 'Should call the Set-ADObject' { - $result = Set-TargetResource @testPresentParams - Assert-MockCalled -CommandName Set-ADObject -Scope It -Times 1 -Exactly + Assert-MockCalled -CommandName Set-ADObject -ParameterFilter { + $Identity -eq 'User' + } -Scope It -Times 1 -Exactly } } Context 'Wrong SPN set' { - Mock -CommandName Get-ADObject -ParameterFilter { $Filter -eq ([ScriptBlock]::Create(' ServicePrincipalName -eq $ServicePrincipalName ')) } -MockWith { - [PSCustomObject] @{ SamAccountName = 'Computer'; DistinguishedName = 'CN=Computer,OU=Corp,DC=contoso,DC=com' } + return [PSCustomObject] @{ + SamAccountName = 'Computer' + DistinguishedName = 'CN=Computer,OU=Corp,DC=contoso,DC=com' + } } + Mock -CommandName Get-ADObject -MockWith { - [PSCustomObject] @{ SamAccountName = 'User' } + return [PSCustomObject] @{ + SamAccountName = 'User' + } } + Mock -CommandName Set-ADObject -ParameterFilter { $null -ne $Add } Mock -CommandName Set-ADObject -ParameterFilter { $null -ne $Remove } It 'Should call the Set-ADObject twice' { - $result = Set-TargetResource @testPresentParams Assert-MockCalled -CommandName Set-ADObject -Scope It -Times 1 -Exactly -ParameterFilter { $null -ne $Add } @@ -236,14 +258,12 @@ try } Context 'Remove all SPNs' { - + Mock -CommandName Set-ADObject Mock -CommandName Get-ADObject -ParameterFilter { $Filter -eq ([ScriptBlock]::Create(' ServicePrincipalName -eq $ServicePrincipalName ')) } -MockWith { [PSCustomObject] @{ SamAccountName = 'User'; DistinguishedName = 'CN=User,OU=Corp,DC=contoso,DC=com' } } - Mock -CommandName Set-ADObject It 'Should call the Set-ADObject' { - $result = Set-TargetResource @testAbsentParams Assert-MockCalled -CommandName Set-ADObject -Scope It -Times 1 -Exactly diff --git a/Tests/Unit/MSFT_ADUser.Tests.ps1 b/Tests/Unit/MSFT_ADUser.Tests.ps1 index e88f26225..40401c462 100644 --- a/Tests/Unit/MSFT_ADUser.Tests.ps1 +++ b/Tests/Unit/MSFT_ADUser.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_ADUser' @@ -36,6 +43,15 @@ try Invoke-TestSetup InModuleScope $script:dscResourceName { + #Load the AD Module Stub, so we can mock the cmdlets, then load the AD types + Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectoryStub.psm1') -Force + + # If one type does not exist, it's assumed the other ones does not exist either. + if (-not ('Microsoft.ActiveDirectory.Management.ADForestMode' -as [Type])) + { + Add-Type -Path (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Unit\Stubs\Microsoft.ActiveDirectory.Management.cs') + } + $testPresentParams = @{ DomainName = 'contoso.com' UserName = 'TestUser' @@ -191,6 +207,10 @@ try #region Function Get-TargetResource Describe 'ADUser\Get-TargetResource' { + BeforeAll { + Mock -CommandName Assert-Module + } + It "Returns a 'System.Collections.Hashtable' object type" { Mock -CommandName Get-ADUser -MockWith { return [PSCustomObject] $fakeADUser } @@ -758,6 +778,10 @@ try #region Function Set-TargetResource Describe 'ADUser\Set-TargetResource' { + BeforeAll { + Mock -CommandName Assert-Module + } + Context 'When running unit tests that need refactor' { It "Calls 'New-ADUser' when 'Ensure' is 'Present' and the account does not exist" { $newUserName = 'NewUser' diff --git a/Tests/Unit/MSFT_WaitForADDomain.Tests.ps1 b/Tests/Unit/MSFT_WaitForADDomain.Tests.ps1 index 6ece625e7..8682e4bb0 100644 --- a/Tests/Unit/MSFT_WaitForADDomain.Tests.ps1 +++ b/Tests/Unit/MSFT_WaitForADDomain.Tests.ps1 @@ -1,3 +1,10 @@ +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\ActiveDirectoryDsc.TestHelper.psm1') + +if (-not (Test-RunForCITestCategory -Type 'Unit' -Category 'Tests')) +{ + return +} + $script:dscModuleName = 'ActiveDirectoryDsc' $script:dscResourceName = 'MSFT_WaitForADDomain' diff --git a/Tests/Unit/Stubs/ActiveDirectoryStub.psm1 b/Tests/Unit/Stubs/ActiveDirectoryStub.psm1 index 760d302b9..3166867c6 100644 --- a/Tests/Unit/Stubs/ActiveDirectoryStub.psm1 +++ b/Tests/Unit/Stubs/ActiveDirectoryStub.psm1 @@ -86,7 +86,7 @@ function Add-ADComputerServiceAccount $Server, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADServiceAccount[]] + [System.Object[]] $ServiceAccount ) @@ -204,7 +204,7 @@ function Add-ADGroupMember $Credential, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADGroup] + [System.Object] $Identity, [Parameter(Mandatory = $true)] @@ -468,7 +468,7 @@ function Disable-ADOptionalFeature $Credential, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADOptionalFeature] + [System.Object] $Identity, [Parameter()] @@ -476,7 +476,7 @@ function Disable-ADOptionalFeature $PassThru, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADOptionalFeatureScope] + [System.Object] $Scope, [Parameter()] @@ -484,7 +484,7 @@ function Disable-ADOptionalFeature $Server, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADEntity] + [System.Object] $Target ) @@ -556,7 +556,7 @@ function Enable-ADOptionalFeature $Credential, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADOptionalFeature] + [System.Object] $Identity, [Parameter()] @@ -564,7 +564,7 @@ function Enable-ADOptionalFeature $PassThru, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADOptionalFeatureScope] + [System.Object] $Scope, [Parameter()] @@ -572,7 +572,7 @@ function Enable-ADOptionalFeature $Server, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADEntity] + [System.Object] $Target ) @@ -1150,7 +1150,7 @@ function Get-ADDefaultDomainPasswordPolicy $Current, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADDefaultDomainPasswordPolicy] + [System.Object] $Identity, [Parameter()] @@ -1188,7 +1188,7 @@ function Get-ADDomain $Current, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADDomain] + [System.Object] $Identity, [Parameter()] @@ -1524,7 +1524,7 @@ function Get-ADGroup $Filter, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADGroup] + [System.Object] $Identity, [Parameter(Mandatory = $true, ParameterSetName = 'LdapFilter')] @@ -1590,7 +1590,7 @@ function Get-ADGroupMember $Credential, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADGroup] + [System.Object] $Identity, [Parameter()] @@ -1636,7 +1636,7 @@ function Get-ADObject $Filter, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADObject] + [System.Object] $Identity, [Parameter()] @@ -1710,7 +1710,7 @@ function Get-ADOptionalFeature $Filter, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADOptionalFeature] + [System.Object] $Identity, [Parameter(Mandatory = $true, ParameterSetName = 'LdapFilter')] @@ -2158,7 +2158,7 @@ function Get-ADReplicationSiteLink $Filter, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADReplicationSiteLink] + [System.Object] $Identity, [Parameter()] @@ -2242,7 +2242,7 @@ function Get-ADReplicationSubnet $Filter, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADReplicationSubnet] + [System.Object] $Identity, [Parameter()] @@ -2523,7 +2523,7 @@ function Get-ADServiceAccount $Filter, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADServiceAccount] + [System.Object] $Identity, [Parameter(Mandatory = $true, ParameterSetName = 'LdapFilter')] @@ -2643,7 +2643,7 @@ function Get-ADUser $Filter, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADUser] + [System.Object] $Identity, [Parameter(Mandatory = $true, ParameterSetName = 'LdapFilter')] @@ -2793,7 +2793,7 @@ function Install-ADServiceAccount $Force, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADServiceAccount] + [System.Object] $Identity, [Parameter()] @@ -2857,7 +2857,7 @@ function Move-ADDirectoryServerOperationMasterRole param ( [Parameter()] - [PSObject] + [System.Object] $AuthType, [Parameter()] @@ -2869,7 +2869,7 @@ function Move-ADDirectoryServerOperationMasterRole $Force, [Parameter(Mandatory = $true)] - [PSObject] + [System.Object] $Identity, [Parameter(Mandatory = $true)] @@ -3751,11 +3751,11 @@ function New-ADGroup $DisplayName, [Parameter()] - [System.Nullable[Microsoft.ActiveDirectory.Management.ADGroupCategory]] + [System.Object] $GroupCategory, [Parameter(Mandatory = $true)] - [System.Nullable[Microsoft.ActiveDirectory.Management.ADGroupScope]] + [System.Object] $GroupScope, [Parameter()] @@ -3763,7 +3763,7 @@ function New-ADGroup $HomePage, [Parameter()] - [Microsoft.ActiveDirectory.Management.ADGroup] + [System.Object] $Instance, [Parameter()] @@ -4103,11 +4103,11 @@ function New-ADReplicationSiteLink $Description, [Parameter(ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADReplicationSiteLink] + [System.Object] $Instance, [Parameter(ParameterSetName = 'Identity')] - [System.Nullable[Microsoft.ActiveDirectory.Management.ADInterSiteTransportProtocolType]] + [System.Object] $InterSiteTransportProtocol, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] @@ -4173,7 +4173,7 @@ function New-ADReplicationSiteLinkBridge $Instance, [Parameter(ParameterSetName = 'Identity')] - [System.Nullable[Microsoft.ActiveDirectory.Management.ADInterSiteTransportProtocolType]] + [System.Object] $InterSiteTransportProtocol, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] @@ -4193,7 +4193,7 @@ function New-ADReplicationSiteLinkBridge $Server, [Parameter(ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADReplicationSiteLink[]] + [System.Object[]] $SiteLinksIncluded ) @@ -4227,7 +4227,7 @@ function New-ADReplicationSubnet $Description, [Parameter(ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADReplicationSubnet] + [System.Object] $Instance, [Parameter(ParameterSetName = 'Identity')] @@ -4461,7 +4461,7 @@ function New-ADServiceAccount $HomePage, [Parameter()] - [Microsoft.ActiveDirectory.Management.ADServiceAccount] + [System.Object] $Instance, [Parameter()] @@ -4659,7 +4659,7 @@ function New-ADUser $Initials, [Parameter()] - [Microsoft.ActiveDirectory.Management.ADUser] + [System.Object] $Instance, [Parameter()] @@ -4671,7 +4671,7 @@ function New-ADUser $LogonWorkstations, [Parameter()] - [Microsoft.ActiveDirectory.Management.ADUser] + [System.Object] $Manager, [Parameter()] @@ -5117,7 +5117,7 @@ function Remove-ADComputerServiceAccount $Server, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADServiceAccount[]] + [System.Object[]] $ServiceAccount ) @@ -5261,7 +5261,7 @@ function Remove-ADFineGrainedPasswordPolicySubject #> function Remove-ADGroup { - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter()] @@ -5273,7 +5273,7 @@ function Remove-ADGroup $Credential, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADGroup] + [System.Object] $Identity, [Parameter()] @@ -5299,7 +5299,7 @@ function Remove-ADGroup #> function Remove-ADGroupMember { - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter()] @@ -5311,7 +5311,7 @@ function Remove-ADGroupMember $Credential, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADGroup] + [System.Object] $Identity, [Parameter(Mandatory = $true)] @@ -5345,7 +5345,7 @@ function Remove-ADGroupMember #> function Remove-ADObject { - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter()] @@ -5479,7 +5479,7 @@ function Remove-ADPrincipalGroupMembership #> function Remove-ADReplicationSite { - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter(ParameterSetName = 'Identity')] @@ -5525,7 +5525,7 @@ function Remove-ADReplicationSiteLink $Credential, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADReplicationSiteLink] + [System.Object] $Identity, [Parameter(ParameterSetName = 'Identity')] @@ -5581,7 +5581,7 @@ function Remove-ADReplicationSiteLinkBridge #> function Remove-ADReplicationSubnet { - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter()] @@ -5593,7 +5593,7 @@ function Remove-ADReplicationSubnet $Credential, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADReplicationSubnet] + [System.Object] $Identity, [Parameter()] @@ -5725,7 +5725,7 @@ function Remove-ADResourcePropertyListMember #> function Remove-ADServiceAccount { - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter()] @@ -5737,7 +5737,7 @@ function Remove-ADServiceAccount $Credential, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADServiceAccount] + [System.Object] $Identity, [Parameter()] @@ -5763,7 +5763,7 @@ function Remove-ADServiceAccount #> function Remove-ADUser { - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess = $true)] param ( [Parameter()] @@ -5775,7 +5775,7 @@ function Remove-ADUser $Credential, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADUser] + [System.Object] $Identity, [Parameter()] @@ -5855,7 +5855,7 @@ function Reset-ADServiceAccountPassword $AuthType, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADServiceAccount] + [System.Object] $Identity, [Parameter()] @@ -6259,7 +6259,7 @@ function Set-ADAccountPassword $Credential, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADAccount] + [System.Object] $Identity, [Parameter()] @@ -7112,7 +7112,7 @@ function Set-ADDefaultDomainPasswordPolicy $Credential, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADDefaultDomainPasswordPolicy] + [System.Object] $Identity, [Parameter()] @@ -7508,11 +7508,11 @@ function Set-ADGroup $DisplayName, [Parameter(ParameterSetName = 'Identity')] - [System.Nullable[Microsoft.ActiveDirectory.Management.ADGroupCategory]] + [System.Object] $GroupCategory, [Parameter(ParameterSetName = 'Identity')] - [System.Nullable[Microsoft.ActiveDirectory.Management.ADGroupScope]] + [System.Object] $GroupScope, [Parameter(ParameterSetName = 'Identity')] @@ -7520,11 +7520,11 @@ function Set-ADGroup $HomePage, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADGroup] + [System.Object] $Identity, [Parameter(Mandatory = $true, ParameterSetName = 'Instance')] - [Microsoft.ActiveDirectory.Management.ADGroup] + [System.Object] $Instance, [Parameter(ParameterSetName = 'Identity')] @@ -7597,12 +7597,12 @@ function Set-ADObject [string] $DisplayName, - [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADObject] + [Parameter(Mandatory = $true, ParameterSetName = 'Identity', ValueFromPipeline = $true)] + [System.Object] $Identity, [Parameter(Mandatory = $true, ParameterSetName = 'Instance')] - [Microsoft.ActiveDirectory.Management.ADObject] + [System.Object] $Instance, [Parameter(ParameterSetName = 'Identity')] @@ -7970,11 +7970,11 @@ function Set-ADReplicationSiteLink $Description, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADReplicationSiteLink] + [System.Object] $Identity, [Parameter(ParameterSetName = 'Instance')] - [Microsoft.ActiveDirectory.Management.ADReplicationSiteLink] + [System.Object] $Instance, [Parameter()] @@ -8110,11 +8110,11 @@ function Set-ADReplicationSubnet $Description, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADReplicationSubnet] + [System.Object] $Identity, [Parameter(ParameterSetName = 'Instance')] - [Microsoft.ActiveDirectory.Management.ADReplicationSubnet] + [System.Object] $Instance, [Parameter(ParameterSetName = 'Identity')] @@ -8372,11 +8372,11 @@ function Set-ADServiceAccount $HomePage, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADServiceAccount] + [System.Object] $Identity, [Parameter(Mandatory = $true, ParameterSetName = 'Instance')] - [Microsoft.ActiveDirectory.Management.ADServiceAccount] + [System.Object] $Instance, [Parameter(ParameterSetName = 'Identity')] @@ -8562,7 +8562,7 @@ function Set-ADUser $HomePhone, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADUser] + [System.Object] $Identity, [Parameter(ParameterSetName = 'Identity')] @@ -8570,7 +8570,7 @@ function Set-ADUser $Initials, [Parameter(Mandatory = $true, ParameterSetName = 'Instance')] - [Microsoft.ActiveDirectory.Management.ADUser] + [System.Object] $Instance, [Parameter(ParameterSetName = 'Identity')] @@ -8582,7 +8582,7 @@ function Set-ADUser $LogonWorkstations, [Parameter(ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADUser] + [System.Object] $Manager, [Parameter(ParameterSetName = 'Identity')] @@ -8805,7 +8805,7 @@ function Test-ADServiceAccount $AuthType, [Parameter(Mandatory = $true, ParameterSetName = 'Identity')] - [Microsoft.ActiveDirectory.Management.ADServiceAccount] + [System.Object] $Identity ) @@ -8835,7 +8835,7 @@ function Uninstall-ADServiceAccount $ForceRemoveLocal, [Parameter(Mandatory = $true)] - [Microsoft.ActiveDirectory.Management.ADServiceAccount] + [System.Object] $Identity ) diff --git a/Tests/Unit/Stubs/Microsoft.ActiveDirectory.Management.cs b/Tests/Unit/Stubs/Microsoft.ActiveDirectory.Management.cs index 6fa057f36..60489838e 100644 --- a/Tests/Unit/Stubs/Microsoft.ActiveDirectory.Management.cs +++ b/Tests/Unit/Stubs/Microsoft.ActiveDirectory.Management.cs @@ -94,11 +94,21 @@ public ADDirectoryServer():base(){} public ADDirectoryServer(System.String Identity):base(){} } + public class ADException : System.Exception + { + public ADException():base(){} + } + public class ADIdentityNotFoundException : System.Exception { public ADIdentityNotFoundException():base(){} } + public class ADServerDownException : System.Exception + { + public ADServerDownException():base(){} + } + public class ADObject { public ADObject():base(){} diff --git a/appveyor.yml b/appveyor.yml index 8e1830e19..377e50c9d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,10 +2,18 @@ # environment configuration # #---------------------------------# -version: 2.16.{build}.0 +version: 4.0.{build} environment: gallery_api: secure: 9ekJzfsPCDBkyLrfmov83XbbhZ6E2N3z+B/Io8NbDetbHc6hWS19zsDmy7t0Vvxv + DeployInJobNumber: 2 + +# The configuration that will be used when building the job matrix. +# Meta = Test Framework Common Test +# Tests = Module Unit Tests and Integration Tests. +configuration: + - Meta + - Tests install: - git clone https://github.com/PowerShell/DscResource.Tests @@ -13,7 +21,6 @@ install: Write-Verbose -Message "PowerShell version $($PSVersionTable.PSVersion)" -Verbose Import-Module -Name "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" Invoke-AppveyorInstallTask - Add-WindowsFeature RSAT-AD-PowerShell #---------------------------------# # build configuration # @@ -25,21 +32,50 @@ build: false # test configuration # #---------------------------------# -test_script: +# This will build the job matrix: +# +# Job 1: Run meta test (common tests) on default build worker image. +# Job 2: Run unit tests and integration tests on default build worker image, +# including Codecov report. + +for: +- + matrix: + only: + - configuration: Meta + + test_script: + - ps: | + Invoke-AppveyorTestScriptTask +- + matrix: + only: + - configuration: Tests + environment: + SkipAllCommonTests: True + + test_script: - ps: | Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -# scripts to run before deployment +# Runs for all jobs. after_test: - - ps: | + - ps: | Import-Module -Name "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" - Invoke-AppveyorAfterTestTask ` - -Type 'Wiki' + Invoke-AppveyorAfterTestTask -Type 'Wiki' #---------------------------------# # deployment configuration # #---------------------------------# +# Runs only in a branch (not in PR). deploy_script: - ps: | - Invoke-AppVeyorDeployTask + if ($env:APPVEYOR_JOB_NUMBER -eq $env:DeployInJobNumber) + { + Invoke-AppVeyorDeployTask + } + else + { + Write-Verbose -Message ('Skipping deploy step. Deploy step was requested to run in job number {0}. Current job number is {1}.' -f $env:DeployInJobNumber, $env:APPVEYOR_JOB_NUMBER) -Verbose + }