diff --git a/CHANGELOG.md b/CHANGELOG.md index 86df8f67f..3afa24932 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -238,6 +238,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 current state ([issue #1834](https://github.com/dsccommunity/SqlServerDsc/issues/1834)). - `Set-TargetResource` was updated to correctly include or exclude a single flag ([issue #1834](https://github.com/dsccommunity/SqlServerDsc/issues/1834)). +- SqlAudit + - Return the correct type for parameter `LogType` when calling method `Get()`. ## [16.0.0] - 2022-09-09 diff --git a/tests/Unit/Classes/SqlReason.Tests.ps1 b/tests/Unit/Classes/SqlReason.Tests.ps1 new file mode 100644 index 000000000..d0c9ca061 --- /dev/null +++ b/tests/Unit/Classes/SqlReason.Tests.ps1 @@ -0,0 +1,80 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')] +param () + +BeforeDiscovery { + try + { + if (-not (Get-Module -Name 'DscResource.Test')) + { + # Assumes dependencies has been resolved, so if this module is not available, run 'noop' task. + if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable)) + { + # Redirect all streams to $null, except the error stream (stream 2) + & "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null + } + + # If the dependencies has not been resolved, this will throw an error. + Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop' + } + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' + } +} + +BeforeAll { + $script:dscModuleName = 'SqlServerDsc' + + $env:SqlServerDscCI = $true + + Import-Module -Name $script:dscModuleName + + $PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:dscModuleName + $PSDefaultParameterValues['Mock:ModuleName'] = $script:dscModuleName + $PSDefaultParameterValues['Should:ModuleName'] = $script:dscModuleName +} + +AfterAll { + $PSDefaultParameterValues.Remove('InModuleScope:ModuleName') + $PSDefaultParameterValues.Remove('Mock:ModuleName') + $PSDefaultParameterValues.Remove('Should:ModuleName') + + # Unload the module being tested so that it doesn't impact any other tests. + Get-Module -Name $script:dscModuleName -All | Remove-Module -Force + + Remove-Item -Path 'env:SqlServerDscCI' +} + +Describe 'SqlReason' -Tag 'SqlReason' { + Context 'When instantiating the class' { + It 'Should not throw an error' { + $script:mockSqlReasonInstance = InModuleScope -ScriptBlock { + [SqlReason]::new() + } + } + + It 'Should be of the correct type' { + $mockSqlReasonInstance | Should -Not -BeNullOrEmpty + $mockSqlReasonInstance.GetType().Name | Should -Be 'SqlReason' + } + } + + Context 'When setting an reading values' { + It 'Should be able to set value in instance' { + $script:mockSqlReasonInstance = InModuleScope -ScriptBlock { + $sqlReasonInstance = [SqlReason]::new() + + $sqlReasonInstance.Code = 'SqlAudit:SqlAudit:Ensure' + $sqlReasonInstance.Phrase = 'The property Ensure should be "Present", but was "Absent"' + + return $sqlReasonInstance + } + } + + It 'Should be able read the values from instance' { + $mockSqlReasonInstance.Code | Should -Be 'SqlAudit:SqlAudit:Ensure' + $mockSqlReasonInstance.Phrase = 'The property Ensure should be "Present", but was "Absent"' + } + } +}