-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attached unit tests for Start-SqlMonitor
- Loading branch information
Showing
2 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
Import-Module "$PSScriptRoot\..\MonitorFactory.psd1" | ||
. "$PSScriptRoot\..\Wrappers\StartSqlMonitor.ps1" | ||
|
||
Describe "Start-SqlMonitor" { | ||
|
||
Mock Start-Monitor | ||
Context "validates path property" { | ||
|
||
It "throws error if path does not exist" { | ||
{ Start-SqlMonitor -path 'C:\doesnotexist.sql' -server a -database b } | Should Throw 'Cannot find path' | ||
Assert-MockCalled Start-Monitor 0 -Scope It | ||
} | ||
It "throws error if file is empty" { | ||
Mock Get-Content { return "" } | ||
{ Start-SqlMonitor -path 'C:\any.sql' -server a -database b } | Should Throw 'no content found' | ||
Assert-MockCalled Start-Monitor 0 -Scope It | ||
} | ||
} | ||
Context "validates other properties" { | ||
It "throws error if server not specified" { | ||
{ Start-SqlMonitor -path 'C:\any.sql' -database b } | Should Throw 'Server must be specified' | ||
} | ||
It "throws error if database not specified" { | ||
{ Start-SqlMonitor -path 'C:\any.sql' -server a } | Should Throw 'Database must be specified' | ||
} | ||
} | ||
Context "uses query" { | ||
It "from file content if specified" { | ||
$content = 'select foo from bar1' | ||
$targetFile = 'C:\any.sql' | ||
Mock Get-Content { return $content } -param { $Path -eq $targetFile } | ||
Start-SqlMonitor -path $targetFile -server a -database b | ||
Assert-MockCalled Start-Monitor 1 -Scope It { $ArgumentList[0] -eq $content } | ||
} | ||
It "from literal if specified" { | ||
$content = 'select foo from bar2' | ||
Start-SqlMonitor -query $content -server a -database b | ||
Assert-MockCalled Start-Monitor 1 -Scope It { $ArgumentList[0] -eq $content } | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters