From f6ce7958fe327fbcdf73923e120689dcfadc3863 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 25 Feb 2023 16:08:11 +0100 Subject: [PATCH] SqlServerDsc: Re-enable Pester's new code coverage method (#1857) - SqlServerDsc - Add empty constructor to classes to be able to use Pester's new code coverage method. See more information can be found in [pester/Pester#2306] --- CHANGELOG.md | 2 ++ build.yaml | 4 +--- source/Classes/002.DatabasePermission.ps1 | 4 ++++ source/Classes/002.ServerPermission.ps1 | 5 +++++ source/Classes/004.StartupParameters.ps1 | 4 ++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31ab241fc..766f3258b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -144,6 +144,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 is loaded into the session. This will make it possible for classes and commands to use and return SQL types. If no module is found it will output a warning to install any of the dependent modules. + - Add empty constructor to classes to be able to use Pester's new code + coverage method. See more information can be found in [pester/Pester#2306](https://github.com/pester/Pester/issues/2306). - `Install-SqlServerDsc` - No longer throws an exception when parameter `AgtSvcAccount` is not specified. - SqlAgReplica diff --git a/build.yaml b/build.yaml index 997d42971..154589062 100644 --- a/build.yaml +++ b/build.yaml @@ -98,9 +98,7 @@ Pester: CoveragePercentTarget: 85 OutputPath: JaCoCo_coverage.xml OutputEncoding: ascii - # There is a bug in Pester when running unit tests for classes when 'UseBreakpoints' is turned off. - # See error in gist: https://gist.github.com/johlju/c16dfd9587c7e066e8825fc54b33a703 - UseBreakpoints: true + UseBreakpoints: false TestResult: OutputFormat: NUnitXML OutputEncoding: ascii diff --git a/source/Classes/002.DatabasePermission.ps1 b/source/Classes/002.DatabasePermission.ps1 index e3980ac5b..e71fbd04b 100644 --- a/source/Classes/002.DatabasePermission.ps1 +++ b/source/Classes/002.DatabasePermission.ps1 @@ -114,6 +114,10 @@ class DatabasePermission : IComparable, System.IEquatable[Object] [System.String[]] $Permission + DatabasePermission () + { + } + [System.Boolean] Equals([System.Object] $object) { $isEqual = $false diff --git a/source/Classes/002.ServerPermission.ps1 b/source/Classes/002.ServerPermission.ps1 index d5587cadd..56eb06d43 100644 --- a/source/Classes/002.ServerPermission.ps1 +++ b/source/Classes/002.ServerPermission.ps1 @@ -81,6 +81,11 @@ class ServerPermission : IComparable, System.IEquatable[Object] [System.String[]] $Permission + + ServerPermission () + { + } + <# TODO: It was not possible to move this to a parent class. But since these are generic functions for DatabasePermission and ServerPermission we diff --git a/source/Classes/004.StartupParameters.ps1 b/source/Classes/004.StartupParameters.ps1 index eca737fec..b496fc45d 100644 --- a/source/Classes/004.StartupParameters.ps1 +++ b/source/Classes/004.StartupParameters.ps1 @@ -34,6 +34,10 @@ class StartupParameters [System.UInt32[]] $InternalTraceFlag + StartupParameters () + { + } + static [StartupParameters] Parse([System.String] $InstanceStartupParameters) { Write-Debug -Message (