Public/InstallHelpers/Install.Database.Functions.Tests.ps1
#Requires -Version 5.0 #Requires -Modules @{ ModuleName="Pester"; ModuleVersion="3.4.0" } $ErrorActionPreference = "Stop"; Set-StrictMode -Version 'Latest' $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.ps1', '.psm1' Import-Module "$PSScriptRoot\$sut" -Force # DANGER: This test will drop a specified database # NOTE: This test requires an unnamed SqlServer instance running locally # on the standard port(1433) and SSMS (for Invoke-Sqlcmd), # so we'll only run this manually. (Uncomment to run) # Describe 'RunSchemaBuilder' { # # Arrange # [string] $dbName = 'TrainingNotifier_Test' # [string] $exeArgs = "-v true -h localhost -d $dbName -i true" # [string] $dropDbCmd = "ALTER DATABASE [$dbName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE [$dbName]" # Invoke-Sqlcmd -Query $dropDbCmd -HostName 'Localhost' | Out-Null # [string] $pathToExe = "$PSScriptRoot\Fixtures\TN.SchemaBuilder\App.SchemaBuilder.exe" # # Act # RunSchemaBuilder -pathToExe $pathToExe -argsString $exeArgs # $actual = Invoke-Sqlcmd -Query "SELECT DB_ID('$dbName')" -HostName 'Localhost' # # Assert # It "returns expected" { # $actual.Column1 | Should Not Be $null # } # } # Describe 'RunSql' { # It 'can run non-parameterized SQL' { # # Arrange # $expected = 1 # [System.Collections.Hashtable] $dbaQueryParams = @{ # SqlInstance = $Env:ComputerName # Query = 'SELECT 1 UNION SELECT 2' # } # # Act # [System.Data.DataRow[]] $actual = RunSql $dbaQueryParams # # Assert # $actual.Length | Should Be 2 # $actual[0]['Column1'] | Should Be $expected # } # It 'can run parameterized SQL' { # # Arrange # $expected = 'Bob' # $testColumnName = 'Name' # [System.Collections.Hashtable] $dbaQueryParams = @{ # SqlInstance = $Env:ComputerName # # TODO: Kind of subverting the reason for using parameterization here... # Query = "SELECT * FROM (SELECT $testColumnName = '$expected') AS FauxTable WHERE $testColumnName = @Name" # SqlParameters = @{ Name = "$expected" } # } # # Act # [System.Data.DataRow] $actual = RunSql $dbaQueryParams # # Assert # $actual["$testColumnName"] | Should Be $expected # } # } Describe 'EncryptData' { It 'returns expected' { # Arrange $expected = 'DXdHfp8jLYdyqUPskaBRc+GMck6FDa50' $data = 'diaz-bao' # Act $actual = EncryptData $data # Assert $actual | Should Be $expected } } |