Skip to content

Commit

Permalink
fixing pester tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Svilen committed Apr 3, 2020
1 parent 1965a3e commit d120534
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
17 changes: 15 additions & 2 deletions source/Modules/xExchangeHelper/xExchangeHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ function Get-RemoteExchangeSession
}
else # Import the session globally
{
Import-RemoteExchangeModule -Session $session -Verbose:([System.Management.Automation.ActionPreference]::SilentlyContinue) -CommandsToLoad $CommandsToLoad
if ($CommandsToLoad)
{
$PSDefaultParameterValues = @{
"Import-RemoteExchangeModule:CommandsToLoad" = $CommandsToLoad
}
}

Import-RemoteExchangeModule -Session $session -Verbose:$VerbosePreference
}
}
else
Expand All @@ -99,8 +106,14 @@ function Get-RemoteExchangeSession
{
$session = New-RemoteExchangeSession -Credential $Credential -Verbose:$VerbosePreference
}
if ($CommandsToLoad)
{
$PSDefaultParameterValues = @{
"Import-Module:Function" = $CommandsToLoad
}
}

Import-Module $env:Temp\DSCExchangeModule\DSCExchangeModule.psm1 -ArgumentList $session -Global -DisableNameChecking -Function $CommandsToLoad -Force
Import-Module $env:Temp\DSCExchangeModule\DSCExchangeModule.psm1 -ArgumentList $session -Global -DisableNameChecking -Force
}
}

Expand Down
8 changes: 5 additions & 3 deletions tests/Unit/xExchangeHelper.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,9 @@ try
}

Describe 'xExchangeHelper\Get-RemoteExchangeSession' -Tag 'Helper' {
function Export-PSSession {

}
AfterEach {
Assert-VerifiableMock
}
Expand Down Expand Up @@ -1325,12 +1328,11 @@ try
State = 'Opened'
}
}
Mock -CommandName New-RemoteExchangeSession -Verifiable
Mock -CommandName Import-Module -ParameterFilter -Verifiable
Mock -CommandName Test-Path -ParameterFilter { $Path -eq "$env:TEMP\DSCExchangeModule" } -Verifiable -MockWith { $true }
Mock -CommandName Import-Module -Verifiable

Get-RemoteExchangeSession

Assert-MockCalled -CommandName New-RemoteExchangeSession -Times 0
Assert-MockCalled -CommandName Import-Module -Times 1
}
}
Expand Down

0 comments on commit d120534

Please sign in to comment.