Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added xSQLServerScript Resource #68

Merged
merged 16 commits into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated Test function to only catch SQL execution exceptions
  • Loading branch information
David Reynolds authored and David Reynolds committed Aug 21, 2016
commit dba7ab8c4485618dc48e6b0f95adfa3c5e06f686
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function Test-TargetResource
return $false
}
}
catch
catch [Microsoft.SqlServer.Management.PowerShell.SqlPowerShellSqlExecutionException]
{
Write-Verbose $_
return $false
Expand Down
24 changes: 17 additions & 7 deletions Tests/Unit/MSFT_xSQLServerScript.Test.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#
.Synopsis
Automated unit test for MSFT_xSQLServerScript DSC Resource
.SYNOPSIS
Automated unit test for MSFT_xSQLServerScript DSC Resource
#>


Expand All @@ -25,6 +25,18 @@ $TestEnvironment = Initialize-TestEnvironment `

#endregion HEADER

Add-Type -ErrorAction SilentlyContinue -TypeDefinition @'
namespace Microsoft.SqlServer.Management.PowerShell
{
public class SqlPowerShellSqlExecutionException : System.Exception
{
public SqlPowerShellSqlExecutionException()
{
}
}
}
'@

# Begin Testing
try
{
Expand Down Expand Up @@ -56,11 +68,9 @@ try
}

It 'Test method returns false' {
$throwMessage = "Failed to run SQL Script"

Mock -CommandName Invoke-SqlCmd -MockWith { Throw $throwMessage }
Mock -CommandName Invoke-SqlCmd -MockWith { throw New-Object Microsoft.SqlServer.Management.PowerShell.SqlPowerShellSqlExecutionException}

Test-TargetResource @testParameters | should be $false
Test-TargetResource @testParameters | should be $false
}

It 'Set method calls Invoke-SqlCmd' {
Expand Down Expand Up @@ -182,7 +192,7 @@ try
}

It 'Test method throws' {
Test-TargetResource @testParameters | should be $false
{ Test-TargetResource @testParameters } | should throw $throwMessage
}

It 'Set method throws' {
Expand Down