Skip to content

Commit

Permalink
ActiveDirectoryDsc: Remove Verbose Parameters from Unit Tests (#544)
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
X-Guardian authored and johlju committed Jan 12, 2020
1 parent 278d1d3 commit 4b2be8e
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 83 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)
- ActiveDirectoryDsc
- Updated PowerShell help files.
- Updated Wiki link in README.md.
- Remove verbose parameters from unit tests.

### Fixed

Expand Down
43 changes: 21 additions & 22 deletions Tests/Unit/ActiveDirectoryDsc.Common.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -914,28 +914,28 @@ InModuleScope 'ActiveDirectoryDsc.Common' {
$testExistingMembers = @('USER1', 'USER2')
$testMembers = $null

Test-Members -ExistingMembers $testExistingMembers -Members $testMembers -Verbose | Should -BeFalse
Test-Members -ExistingMembers $testExistingMembers -Members $testMembers | Should -BeFalse
}

It 'Should fail when multiple Members are the wrong members' {
$testExistingMembers = @('USER1', 'USER2')
$testMembers = @('USER3', 'USER4')

Test-Members -ExistingMembers $testExistingMembers -Members $testMembers -Verbose | Should -BeFalse
Test-Members -ExistingMembers $testExistingMembers -Members $testMembers | Should -BeFalse
}

It 'Should fail when multiple MembersToInclude are not present in existing members' {
$testExistingMembers = @('USER1', 'USER2')
$testMembersToInclude = @('USER3', 'USER4')

Test-Members -ExistingMembers $testExistingMembers -MembersToInclude $testMembersToInclude -Verbose | Should -BeFalse
Test-Members -ExistingMembers $testExistingMembers -MembersToInclude $testMembersToInclude | Should -BeFalse
}

It 'Should fail when multiple MembersToExclude are present in existing members' {
$testExistingMembers = @('USER1', 'USER2')
$testMembersToExclude = @('USER1', 'USER2')

Test-Members -ExistingMembers $testExistingMembers -MembersToExclude $testMembersToExclude -Verbose | Should -BeFalse
Test-Members -ExistingMembers $testExistingMembers -MembersToExclude $testMembersToExclude | Should -BeFalse
}
}

Expand Down Expand Up @@ -1513,7 +1513,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {
}

It 'Should throw the correct error' {
{ Get-DomainControllerObject -DomainName 'contoso.com' -Verbose } | Should -Throw $localizedString.FailedEvaluatingDomainController
{ Get-DomainControllerObject -DomainName 'contoso.com' } | Should -Throw $localizedString.FailedEvaluatingDomainController

Assert-MockCalled -CommandName Get-ADDomainController -Exactly -Times 1 -Scope It
}
Expand All @@ -1528,7 +1528,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {
}

It 'Should return $null' {
$getDomainControllerObjectResult = Get-DomainControllerObject -DomainName 'contoso.com' -Verbose
$getDomainControllerObjectResult = Get-DomainControllerObject -DomainName 'contoso.com'
$getDomainControllerObjectResult | Should -BeNullOrEmpty

Assert-MockCalled -CommandName Get-ADDomainController -Exactly -Times 1 -Scope It
Expand All @@ -1544,7 +1544,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {
}

It 'Should throw the correct error' {
{ Get-DomainControllerObject -DomainName 'contoso.com' -Verbose } | Should -Throw $script:localizedData.WasExpectingDomainController
{ Get-DomainControllerObject -DomainName 'contoso.com' } | Should -Throw $script:localizedData.WasExpectingDomainController

Assert-MockCalled -CommandName Get-ADDomainController -Exactly -Times 1 -Scope It
}
Expand All @@ -1562,7 +1562,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {
}

It 'Should return the correct values for each property' {
$getDomainControllerObjectResult = Get-DomainControllerObject -DomainName 'contoso.com' -Verbose
$getDomainControllerObjectResult = Get-DomainControllerObject -DomainName 'contoso.com'

$getDomainControllerObjectResult.Site | Should -Be 'MySite'
$getDomainControllerObjectResult.Domain | Should -Be 'contoso.com'
Expand All @@ -1588,7 +1588,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {
}

It 'Should return the correct values for each property' {
$getDomainControllerObjectResult = Get-DomainControllerObject -DomainName 'contoso.com' -Credential $mockAdministratorCredential -Verbose
$getDomainControllerObjectResult = Get-DomainControllerObject -DomainName 'contoso.com' -Credential $mockAdministratorCredential

$getDomainControllerObjectResult.Site | Should -Be 'MySite'
$getDomainControllerObjectResult.Domain | Should -Be 'contoso.com'
Expand Down Expand Up @@ -1883,7 +1883,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {
DesiredValue = $null
}

Test-DscPropertyState -Values $mockValues -Verbose | Should -BeTrue
Test-DscPropertyState -Values $mockValues | Should -BeTrue
}

It 'Should return true when evaluating an array, when both values are an empty array' {
Expand All @@ -1892,7 +1892,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {
DesiredValue = @()
}

Test-DscPropertyState -Values $mockValues -Verbose | Should -BeTrue
Test-DscPropertyState -Values $mockValues | Should -BeTrue
}
}

Expand Down Expand Up @@ -2055,7 +2055,6 @@ InModuleScope 'ActiveDirectoryDsc.Common' {

$mockDesiredValues = @{
ComputerName = 'DC01'
Verbose = $true
}
}

Expand Down Expand Up @@ -2193,7 +2192,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {
}

It 'Should not throw' {
{ Assert-ADPSProvider -Verbose } | Should -Not -Throw
{ Assert-ADPSProvider } | Should -Not -Throw
}

It 'Should call the expected mocks' {
Expand Down Expand Up @@ -2534,7 +2533,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {

Context 'When the calling with only the parameter DomainName' {
It 'Should not throw and call the correct mocks' {
{ Find-DomainController -DomainName $mockDomainName -Verbose } | Should -Not -Throw
{ Find-DomainController -DomainName $mockDomainName } | Should -Not -Throw

Assert-MockCalled -CommandName Get-ADDirectoryContext -ParameterFilter {
$Name -eq $mockDomainName `
Expand All @@ -2548,7 +2547,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {

Context 'When the calling with the parameter SiteName' {
It 'Should not throw and call the correct mocks' {
{ Find-DomainController -DomainName $mockDomainName -SiteName 'Europe' -Verbose } | Should -Not -Throw
{ Find-DomainController -DomainName $mockDomainName -SiteName 'Europe' } | Should -Not -Throw

Assert-MockCalled -CommandName Get-ADDirectoryContext -ParameterFilter {
$Name -eq $mockDomainName `
Expand All @@ -2562,7 +2561,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {

Context 'When the calling with the parameter Credential' {
It 'Should not throw and call the correct mocks' {
{ Find-DomainController -DomainName $mockDomainName -Credential $mockAdministratorCredential -Verbose } | Should -Not -Throw
{ Find-DomainController -DomainName $mockDomainName -Credential $mockAdministratorCredential } | Should -Not -Throw

Assert-MockCalled -CommandName Get-ADDirectoryContext -ParameterFilter {
$Name -eq $mockDomainName `
Expand Down Expand Up @@ -2592,12 +2591,12 @@ InModuleScope 'ActiveDirectoryDsc.Common' {
Mock -CommandName Write-Verbose -ParameterFilter {
$Message -eq ($script:localizedData.FailedToFindDomainController -f $mockDomainName)
} -MockWith {
Write-Verbose -Message ('VERBOSE OUTPUT FROM MOCK: {0}' -f $Message) -Verbose
Write-Verbose -Message ('VERBOSE OUTPUT FROM MOCK: {0}' -f $Message)
}
}

It 'Should not throw and call the correct mocks' {
{ Find-DomainController -DomainName $mockDomainName -Verbose } | Should -Not -Throw
{ Find-DomainController -DomainName $mockDomainName } | Should -Not -Throw

Assert-MockCalled -Command Find-DomainControllerFindOneWrapper -Exactly -Times 1 -Scope It
Assert-MockCalled -Command Write-Verbose -Exactly -Times 1 -Scope It
Expand All @@ -2622,7 +2621,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {
}

It 'Should throw the correct error' {
{ Find-DomainController -DomainName $mockDomainName -Verbose } | Should -Throw $mockErrorMessage
{ Find-DomainController -DomainName $mockDomainName } | Should -Throw $mockErrorMessage

Assert-MockCalled -Command Find-DomainControllerFindOneWrapper -Exactly -Times 1 -Scope It
}
Expand Down Expand Up @@ -2657,15 +2656,15 @@ InModuleScope 'ActiveDirectoryDsc.Common' {

Context 'When the parameter WaitForValidCredentials is not specified' {
It 'Should throw the correct error' {
{ Find-DomainController -DomainName $mockDomainName -Verbose } | Should -Throw $mockErrorMessage
{ Find-DomainController -DomainName $mockDomainName } | Should -Throw $mockErrorMessage

Assert-MockCalled -Command Find-DomainControllerFindOneWrapper -Exactly -Times 1 -Scope It
}
}

Context 'When the parameter WaitForValidCredentials is set to $false' {
It 'Should throw the correct error' {
{ Find-DomainController -DomainName $mockDomainName -WaitForValidCredentials:$false -Verbose } | Should -Throw $mockErrorMessage
{ Find-DomainController -DomainName $mockDomainName -WaitForValidCredentials:$false } | Should -Throw $mockErrorMessage

Assert-MockCalled -Command Find-DomainControllerFindOneWrapper -Exactly -Times 1 -Scope It
}
Expand All @@ -2677,7 +2676,7 @@ InModuleScope 'ActiveDirectoryDsc.Common' {
}

It 'Should not throw an exception' {
{ Find-DomainController -DomainName $mockDomainName -WaitForValidCredentials -Verbose } | Should -Not -Throw
{ Find-DomainController -DomainName $mockDomainName -WaitForValidCredentials } | Should -Not -Throw

Assert-MockCalled -Command Find-DomainControllerFindOneWrapper -Exactly -Times 1 -Scope It
Assert-MockCalled -CommandName Write-Warning -Exactly -Times 1 -Scope It
Expand Down
25 changes: 0 additions & 25 deletions Tests/Unit/MSFT_ADComputer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ try
RequestFile = 'TestDrive:\ODJ.txt'
RestoreFromRecycleBin = $false
EnabledOnCreation = $false
Verbose = $true
}
}

Expand Down Expand Up @@ -166,7 +165,6 @@ try
RequestFile = 'TestDrive:\ODJ.txt'
RestoreFromRecycleBin = $false
EnabledOnCreation = $false
Verbose = $true
}
}

Expand Down Expand Up @@ -210,7 +208,6 @@ try

$getTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
Verbose = $true
}
}

Expand All @@ -233,7 +230,6 @@ try
$getTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
DomainController = 'DC01'
Verbose = $true
}
}

Expand All @@ -256,7 +252,6 @@ try
$getTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
Credential = $mockCredential
Verbose = $true
}
}

Expand Down Expand Up @@ -335,7 +330,6 @@ try
$testTargetResourceParameters = @{
Ensure = 'Absent'
ComputerName = $mockComputerNamePresent
Verbose = $true
}
}

Expand All @@ -358,7 +352,6 @@ try
RequestFile = 'TestDrive:\ODJ.txt'
RestoreFromRecycleBin = $false
EnabledOnCreation = $false
Verbose = $true
}
}

Expand All @@ -377,7 +370,6 @@ try
$testTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
ServicePrincipalNames = $mockServicePrincipalNames
Verbose = $true
}
}

Expand All @@ -398,7 +390,6 @@ try
$testTargetResourceParameters = @{
Ensure = 'Present'
ComputerName = $mockComputerNamePresent
Verbose = $true
}
}

Expand All @@ -417,7 +408,6 @@ try
$testTargetResourceParameters = @{
Ensure = 'Absent'
ComputerName = $mockComputerNamePresent
Verbose = $true
}
}

Expand Down Expand Up @@ -552,7 +542,6 @@ try
$testTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
$ParameterName = $Value
Verbose = $true
}

$testTargetResourceResult = Test-TargetResource @testTargetResourceParameters
Expand Down Expand Up @@ -633,7 +622,6 @@ try
$setTargetResourceParameters = @{
Ensure = 'Absent'
ComputerName = $mockComputerNamePresent
Verbose = $true
}
}

Expand All @@ -658,7 +646,6 @@ try
RequestFile = 'TestDrive:\ODJ.txt'
RestoreFromRecycleBin = $false
EnabledOnCreation = $false
Verbose = $true
}
}

Expand All @@ -679,7 +666,6 @@ try
$setTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
ServicePrincipalNames = $mockServicePrincipalNames_DefaultValues
Verbose = $true
}
}

Expand Down Expand Up @@ -732,7 +718,6 @@ try
$setTargetResourceParameters = @{
Ensure = 'Present'
ComputerName = $mockComputerNamePresent
Verbose = $true
}
}

Expand All @@ -752,7 +737,6 @@ try
Ensure = 'Present'
ComputerName = $mockComputerNamePresent
Path = $mockParentContainer
Verbose = $true
}
}

Expand All @@ -774,7 +758,6 @@ try
$setTargetResourceParameters = @{
Ensure = 'Absent'
ComputerName = $mockComputerNamePresent
Verbose = $true
}
}

Expand All @@ -795,7 +778,6 @@ try
$setTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
EnabledOnCreation = $true
Verbose = $true
}
}

Expand All @@ -818,7 +800,6 @@ try
$setTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
EnabledOnCreation = $false
Verbose = $true
}
}

Expand Down Expand Up @@ -870,7 +851,6 @@ try
Path = $mockParentContainer
DomainController = 'dc01.contoso.com'
RequestFile = 'c:\ODJTest.txt'
Verbose = $true
}
}

Expand Down Expand Up @@ -908,7 +888,6 @@ try
$setTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
RequestFile = 'c:\ODJTest.txt'
Verbose = $true
}
}

Expand Down Expand Up @@ -981,7 +960,6 @@ try
$setTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
$ParameterName = $Value
Verbose = $true
}

{ Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw
Expand Down Expand Up @@ -1048,7 +1026,6 @@ try
$setTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
$ParameterName = $Value
Verbose = $true
}

{ Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw
Expand All @@ -1067,7 +1044,6 @@ try
$setTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
Path = 'OU=New,CN=Computers,DC=contoso,DC=com'
Verbose = $true
}
}

Expand Down Expand Up @@ -1102,7 +1078,6 @@ try
$setTargetResourceParameters = @{
ComputerName = $mockComputerNamePresent
RestoreFromRecycleBin = $true
Verbose = $true
}
}

Expand Down
Loading

0 comments on commit 4b2be8e

Please sign in to comment.