Skip to content

Commit

Permalink
Remove semi-colon from missed file
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Jun 15, 2019
1 parent e7e001a commit f9ccbb0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ function Set-TargetResource
if ($Ensure -eq 'Present')
{
$isEnsureNonCompliant = $false

if ($compareTargetResourceNonCompliant |
Where-Object -FilterScript { $_.Parameter -eq 'Ensure' })
{
Expand Down
96 changes: 48 additions & 48 deletions Tests/Unit/MSFT_xADGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ try
Mock -CommandName Assert-Module -ParameterFilter { $ModuleName -eq 'ActiveDirectory' }

It 'Calls "Assert-Module" to check AD module is installed' {
Mock -CommandName Get-ADGroup { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroup { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember {return @($fakeADUser1, $fakeADUser2) }

$result = Get-TargetResource @testPresentParams; # -DomainName $correctDomainName
$result = Get-TargetResource @testPresentParams

Assert-MockCalled -CommandName Assert-Module -ParameterFilter { $ModuleName -eq 'ActiveDirectory' } -Scope It
}

It "Returns 'Ensure' is 'Present' when group exists" {
Mock -CommandName Get-ADGroup { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroup { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2) }

(Get-TargetResource @testPresentParams).Ensure | Should -Be 'Present'
}
Expand All @@ -128,35 +128,35 @@ try


It "Calls 'Get-ADGroup' with 'Server' parameter when 'DomainController' specified" {
Mock -CommandName Get-ADGroup -ParameterFilter { $Server -eq $testDomainController } -MockWith { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroup -ParameterFilter { $Server -eq $testDomainController } -MockWith { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2) }

Get-TargetResource @testPresentParams -DomainController $testDomainController

Assert-MockCalled -CommandName Get-ADGroup -ParameterFilter { $Server -eq $testDomainController } -Scope It
}

It "Calls 'Get-ADGroup' with 'Credential' parameter when specified" {
Mock -CommandName Get-ADGroup -ParameterFilter { $Credential -eq $testCredentials } -MockWith { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroup -ParameterFilter { $Credential -eq $testCredentials } -MockWith { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2) }

Get-TargetResource @testPresentParams -Credential $testCredentials

Assert-MockCalled -CommandName Get-ADGroup -ParameterFilter { $Credential -eq $testCredentials } -Scope It
}

It "Calls 'Get-ADGroupMember' with 'Server' parameter when 'DomainController' specified" {
Mock -CommandName Get-ADGroup -MockWith { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember -ParameterFilter { $Server -eq $testDomainController } -MockWith { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroup -MockWith { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember -ParameterFilter { $Server -eq $testDomainController } -MockWith { return @($fakeADUser1, $fakeADUser2) }

Get-TargetResource @testPresentParams -DomainController $testDomainController

Assert-MockCalled -CommandName Get-ADGroupMember -ParameterFilter { $Server -eq $testDomainController } -Scope It
}

It "Calls 'Get-ADGroupMember' with 'Credential' parameter when specified" {
Mock -CommandName Get-ADGroup -MockWith { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember -ParameterFilter { $Credential -eq $testCredentials } -MockWith { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroup -MockWith { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember -ParameterFilter { $Credential -eq $testCredentials } -MockWith { return @($fakeADUser1, $fakeADUser2) }

Get-TargetResource @testPresentParams -Credential $testCredentials

Expand All @@ -173,62 +173,62 @@ try
foreach ($attribute in @('SamAccountName','DistinguishedName','ObjectGUID','SID'))
{
It "Passes when group 'Members' match using '$attribute'" {
Mock -CommandName Get-ADGroup { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroup { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2) }

$targetResource = Test-TargetResource @testPresentParams -Members $fakeADUser1.$attribute, $fakeADUser2.$attribute -MembershipAttribute $attribute

$targetResource | Should -Be $true
}

It "Fails when group membership counts do not match using '$attribute'" {
Mock -CommandName Get-ADGroup { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1); }
Mock -CommandName Get-ADGroup { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1) }

$targetResource = Test-TargetResource @testPresentParams -Members $fakeADUser2.$attribute, $fakeADUser3.$attribute -MembershipAttribute $attribute

$targetResource | Should -Be $false
}

It "Fails when group 'Members' do not match using '$attribute'" {
Mock -CommandName Get-ADGroup { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroup { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2) }

$targetResource = Test-TargetResource @testPresentParams -Members $fakeADUser2.$attribute, $fakeADUser3.$attribute -MembershipAttribute $attribute

$targetResource | Should -Be $false
}

It "Passes when specified 'MembersToInclude' match using '$attribute'" {
Mock -CommandName Get-ADGroup { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroup { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2) }

$targetResource = Test-TargetResource @testPresentParams -MembersToInclude $fakeADUser2.$attribute -MembershipAttribute $attribute

$targetResource | Should -Be $true
}

It "Fails when specified 'MembersToInclude' are missing using '$attribute'" {
Mock -CommandName Get-ADGroup { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroup { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2) }

$targetResource = Test-TargetResource @testPresentParams -MembersToInclude $fakeADUser3.$attribute -MembershipAttribute $attribute

$targetResource | Should -Be $false
}

It "Passes when specified 'MembersToExclude' are missing using '$attribute'" {
Mock -CommandName Get-ADGroup { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroup { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2) }

$targetResource = Test-TargetResource @testPresentParams -MembersToExclude $fakeADUser3.$attribute -MembershipAttribute $attribute

$targetResource | Should -Be $true
}

It "Fails when when specified 'MembersToExclude' match using '$attribute'" {
Mock -CommandName Get-ADGroup { return $fakeADGroup; }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroup { return $fakeADGroup }
Mock -CommandName Get-ADGroupMember { return @($fakeADUser1, $fakeADUser2) }

$targetResource = Test-TargetResource @testPresentParams -MembersToExclude $fakeADUser2.$attribute -MembershipAttribute $attribute

Expand Down Expand Up @@ -341,7 +341,7 @@ try
It "Calls 'New-ADGroup' when 'Ensure' is 'Present' and the group does not exist" {
Mock -CommandName Get-ADGroup -MockWith { throw New-Object Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException }
Mock -CommandName Set-ADGroup
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }

Set-TargetResource @testPresentParams

Expand Down Expand Up @@ -417,7 +417,7 @@ try
Mock -CommandName Get-ADGroup -MockWith { throw New-Object Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException }
Mock -CommandName Set-ADGroup
Mock -CommandName Add-ADCommonGroupMember
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }

Set-TargetResource @testPresentParams -Members @($fakeADUser1.SamAccountName, $fakeADUser2.SamAccountName)

Expand All @@ -428,7 +428,7 @@ try
Mock -CommandName Get-ADGroup -MockWith { throw New-Object Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException }
Mock -CommandName Set-ADGroup
Mock -CommandName Add-ADCommonGroupMember
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }
Mock -CommandName Get-DomainName -MockWith { return 'contoso.com' }
Mock -CommandName Get-ADDomainNameFromDistinguishedName -MockWith { return 'contoso.com' }
Mock -CommandName Write-Verbose -ParameterFilter { $Message -and $Message -match 'Group membership objects are in .* different AD Domains.'}
Expand All @@ -444,7 +444,7 @@ try
Mock -CommandName Get-ADGroup -MockWith { throw New-Object Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException }
Mock -CommandName Set-ADGroup
Mock -CommandName Add-ADCommonGroupMember
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }
Mock -CommandName Get-DomainName -MockWith {return 'contoso.com'}
Mock -CommandName Get-ADDomainNameFromDistinguishedName -MockWith {
param (
Expand Down Expand Up @@ -475,7 +475,7 @@ try
Mock -CommandName Get-ADGroup -MockWith { throw New-Object Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException }
Mock -CommandName Set-ADGroup
Mock -CommandName Add-ADCommonGroupMember
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }

Set-TargetResource @testPresentParams -MembersToInclude @($fakeADUser1.SamAccountName, $fakeADUser2.SamAccountName)

Expand All @@ -498,9 +498,9 @@ try
}

It "Resets group membership when 'Ensure' is 'Present' and 'Members' is incorrect" {
Mock -CommandName Get-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName Get-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }
Mock -CommandName Set-ADGroup
Mock -CommandName Get-ADGroupMember -MockWith { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroupMember -MockWith { return @($fakeADUser1, $fakeADUser2) }
Mock -CommandName Add-ADCommonGroupMember
Mock -CommandName Remove-ADGroupMember

Expand All @@ -511,7 +511,7 @@ try
}

It "Does not reset group membership when 'Ensure' is 'Present' and existing group is empty" {
Mock -CommandName Get-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName Get-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }
Mock -CommandName Set-ADGroup
Mock -CommandName Get-ADGroupMember
Mock -CommandName Remove-ADGroupMember
Expand All @@ -522,9 +522,9 @@ try
}

It "Removes members when 'Ensure' is 'Present' and 'MembersToExclude' is incorrect" {
Mock -CommandName Get-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName Get-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }
Mock -CommandName Set-ADGroup
Mock -CommandName Get-ADGroupMember -MockWith { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroupMember -MockWith { return @($fakeADUser1, $fakeADUser2) }
Mock -CommandName Remove-ADGroupMember

Set-TargetResource @testPresentParams -MembersToExclude $fakeADuser1.SamAccountName
Expand All @@ -533,9 +533,9 @@ try
}

It "Adds members when 'Ensure' is 'Present' and 'MembersToInclude' is incorrect" {
Mock -CommandName Get-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName Get-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }
Mock -CommandName Set-ADGroup
Mock -CommandName Get-ADGroupMember -MockWith { return @($fakeADUser1, $fakeADUser2); }
Mock -CommandName Get-ADGroupMember -MockWith { return @($fakeADUser1, $fakeADUser2) }
Mock -CommandName Add-ADCommonGroupMember

Set-TargetResource @testPresentParams -MembersToInclude $fakeADuser3.SamAccountName
Expand All @@ -544,7 +544,7 @@ try
}

It "Removes group when 'Ensure' is 'Absent' and group exists" {
Mock -CommandName Get-ADGroup -MockWith { return $fakeADGroup; }
Mock -CommandName Get-ADGroup -MockWith { return $fakeADGroup }
Mock -CommandName Remove-ADGroup

Set-TargetResource @testAbsentParams
Expand All @@ -553,8 +553,8 @@ try
}

It "Calls 'Set-ADGroup' with credentials when 'Ensure' is 'Present' and the group exists (#106)" {
Mock -CommandName Get-ADGroup -MockWith { return $fakeADGroup; }
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName Get-ADGroup -MockWith { return $fakeADGroup }
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }
Mock -CommandName Get-ADGroupMember
Mock -CommandName Set-ADGroup -ParameterFilter { $Credential -eq $testCredentials }

Expand All @@ -566,7 +566,7 @@ try
It "Calls 'Set-ADGroup' with credentials when 'Ensure' is 'Present' and the group does not exist (#106)" {
Mock -CommandName Get-ADGroup -MockWith { throw New-Object Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException }
Mock -CommandName Set-ADGroup -ParameterFilter { $Credential -eq $testCredentials }
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }

Set-TargetResource @testPresentParams -Credential $testCredentials

Expand Down Expand Up @@ -656,8 +656,8 @@ try
$restoreParam.RestoreFromRecycleBin = $true
Mock -CommandName Get-ADGroup -MockWith { throw New-Object Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException }
Mock -CommandName Set-ADGroup
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName Restore-ADCommonObject -MockWith { return [PSCustomObject] $fakeADGroup;}
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }
Mock -CommandName Restore-ADCommonObject -MockWith { return [PSCustomObject] $fakeADGroup}

Set-TargetResource @restoreParam

Expand All @@ -671,7 +671,7 @@ try
$restoreParam.RestoreFromRecycleBin = $true
Mock -CommandName Get-ADGroup -MockWith { throw New-Object Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException }
Mock -CommandName Set-ADGroup
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }
Mock -CommandName Restore-ADCommonObject

Set-TargetResource @restoreParam
Expand All @@ -685,10 +685,10 @@ try
$restoreParam.RestoreFromRecycleBin = $true
Mock -CommandName Get-ADGroup -MockWith { throw New-Object Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException }
Mock -CommandName Set-ADGroup
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup; }
Mock -CommandName New-ADGroup -MockWith { return [PSCustomObject] $fakeADGroup }
Mock -CommandName Restore-ADCommonObject -MockWith { throw (New-Object -TypeName System.InvalidOperationException)}

{Set-TargetResource @restoreParam;} | Should -Throw
{Set-TargetResource @restoreParam} | Should -Throw

Assert-MockCalled -CommandName Restore-AdCommonObject -Scope It
Assert-MockCalled -CommandName New-ADGroup -Scope It -Exactly -Times 0
Expand Down

0 comments on commit f9ccbb0

Please sign in to comment.