Skip to content

Suspend-SqlDscDatabase/Resume-SqlDscDatabase: Command proposals#2355

Merged
johlju merged 15 commits intodsccommunity:mainfrom
johlju:fix/suspend-resume-database
Dec 3, 2025
Merged

Suspend-SqlDscDatabase/Resume-SqlDscDatabase: Command proposals#2355
johlju merged 15 commits intodsccommunity:mainfrom
johlju:fix/suspend-resume-database

Conversation

@johlju
Copy link
Copy Markdown
Member

@johlju johlju commented Nov 30, 2025

Pull Request (PR) description

  • Added public command Resume-SqlDscDatabase to bring a SQL Server database back
    online. This command uses the SMO Database.SetOnline() method to make databases
    available after maintenance or downtime. The command supports both Server and
    Database object pipeline input for flexible usage (issue #2191).
  • Added public command Suspend-SqlDscDatabase to take a SQL Server database offline.
    This command uses the SMO Database.SetOffline() method to temporarily make
    databases unavailable for maintenance scenarios. The command includes a Force
    parameter to disconnect active users when necessary and supports both Server and
    Database object pipeline input (issue #2192).

This Pull Request (PR) fixes the following issues

Task list

  • Added an entry to the change log under the Unreleased section of the
    file CHANGELOG.md. Entry should say what was changed and how that
    affects users (if applicable), and reference the issue being resolved
    (if applicable).
  • Resource documentation updated in the resource's README.md.
  • Resource parameter descriptions updated in schema.mof.
  • Comment-based help updated, including parameter descriptions.
  • Localization strings updated.
  • Examples updated.
  • Unit tests updated. See DSC Community Testing Guidelines.
  • Integration tests updated (where possible). See DSC Community Testing Guidelines.
  • Code changes adheres to DSC Community Style Guidelines.

This change is Reviewable

@johlju johlju requested a review from a team as a code owner November 30, 2025 15:47
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 30, 2025

Walkthrough

Adds two public PowerShell cmdlets, Resume-SqlDscDatabase and Suspend-SqlDscDatabase, implementing SMO-backed SetOnline/SetOffline operations, accompanying localized strings, unit and integration tests, SMO test-stub methods, CI test registration, and a changelog entry.

Changes

Cohort / File(s) Summary
New Public Commands
source/Public/Resume-SqlDscDatabase.ps1, source/Public/Suspend-SqlDscDatabase.ps1
Added cmdlets with ServerObject+Name and DatabaseObject parameter sets, pipeline input, ShouldProcess/WhatIf support, Force/Refresh/PassThru switches, idempotence checks, SMO calls (Database.SetOnline() / Database.SetOffline()), user-disconnect handling, and terminating error handling.
Localization Strings
source/en-US/SqlServerDsc.strings.psd1
Added localized ShouldProcess descriptions/captions/warnings and runtime status keys for Resume and Suspend flows (AlreadyOnline/AlreadyOffline, BringingOnline/TakingOffline[WithForce], BroughtOnline/TakenOffline, ResumeFailed/SuspendFailed, KillProcessesFailed).
Unit Tests & SMO Stubs
tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1, tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1, tests/Unit/Stubs/SMO.cs
Added Pester unit tests covering parameter sets, pipeline, WhatIf, PassThru, error paths; extended SMO test stub with SetOnline(), SetOffline() and KillAllProcesses(string).
Integration Tests
tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1, tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
Added integration suites exercising Offline↔Online transitions, idempotence, non-existent DB errors, ServerObject/DatabaseObject and pipeline scenarios, with setup/teardown and cleanup.
CI Pipeline
azure-pipelines.yml
Registered the two new integration test scripts in the Integration_Test_Commands_SqlServer stage.
Changelog
CHANGELOG.md
Documented addition of Resume-SqlDscDatabase and Suspend-SqlDscDatabase.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant User as PowerShell user
participant Cmdlet as Resume/Suspend Cmdlet
participant Resolver as Get-SqlDscDatabase (optional)
participant SMO as SMO Database object
Note over Cmdlet,SMO: Parameter binding selects ServerObject+Name or DatabaseObject
User->>Cmdlet: Invoke (ServerObject+Name or DatabaseObject, [-Force|-WhatIf|-PassThru])
Cmdlet->>Cmdlet: Validate parameter set & ShouldProcess
alt ServerObject+Name
Cmdlet->>Resolver: Resolve DB object
Resolver-->>Cmdlet: Return Database object
end
Cmdlet->>SMO: Call SetOnline() or SetOffline(force?)
alt Success
SMO-->>Cmdlet: Status updated (Online/Offline)
Cmdlet->>User: Verbose/status message; return DB if -PassThru
else Failure
SMO-->>Cmdlet: Throw/error
Cmdlet-->>User: Terminating ErrorRecord
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas to review closely:
    • Parameter-set binding, pipeline input handling, and ShouldProcess/WhatIf behavior
    • ErrorRecord construction and terminating error behavior around SMO.SetOnline/SetOffline
    • Force handling (KillAllProcesses/disconnect) and its failure paths
    • SMO test-stub implementations vs. expected SMO behavior used by tests
    • Localization key consistency and usage in cmdlet messages

Possibly related PRs

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main changes: two new commands Resume-SqlDscDatabase and Suspend-SqlDscDatabase are being added as proposals.
Description check ✅ Passed The description is well-organized and directly related to the changeset, explaining both commands, their purpose, implementation details, and parameter support with issue references.
Linked Issues check ✅ Passed The PR fully implements coding requirements from both linked issues: Resume-SqlDscDatabase [#2191] and Suspend-SqlDscDatabase [#2192] with SMO SetOnline/SetOffline methods, pipeline support, and all proposed parameters including Force functionality.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the linked issues. The PR adds the two new commands with supporting infrastructure (tests, localization, stubs) and includes azure-pipelines updates to run the integration tests.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b9735c6 and 46a050a.

📒 Files selected for processing (1)
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1 (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
CHANGELOG.md (1)

31-39: Condense and wrap the new bullets per Markdown/Changelog guidelines.

Entries are a bit verbose and exceed 80 chars. Suggest tightening wording and wrapping to improve readability while keeping style consistent.

- Added public command `Resume-SqlDscDatabase` to bring a SQL Server database back
- online. This command uses the SMO `Database.SetOnline()` method to make databases
- available after maintenance or downtime. The command supports both Server and
- Database object pipeline input for flexible usage ([issue #2191](https://github.com/dsccommunity/SqlServerDsc/issues/2191)).
+ Added public command `Resume-SqlDscDatabase` to bring a database online using
+ SMO `Database.SetOnline()`. Supports Server and Database pipeline input
+ ([issue #2191](https://github.com/dsccommunity/SqlServerDsc/issues/2191)).

- Added public command `Suspend-SqlDscDatabase` to take a SQL Server database offline.
- This command uses the SMO `Database.SetOffline()` method to temporarily make
- databases unavailable for maintenance scenarios. The command includes a `Force`
- parameter to disconnect active users when necessary and supports both Server and
- Database object pipeline input ([issue #2192](https://github.com/dsccommunity/SqlServerDsc/issues/2192)).
+ Added public command `Suspend-SqlDscDatabase` to take a database offline using
+ SMO `Database.SetOffline()`. Supports Server and Database pipeline input; includes
+ `Force` to disconnect active users ([issue #2192](https://github.com/dsccommunity/SqlServerDsc/issues/2192)).

As per coding guidelines, wrap lines >80 chars and keep changelog items brief.

tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1 (1)

121-127: Consider invoking commands directly instead of wrapping with Should -Not -Throw.

Per coding guidelines, commands should be invoked directly rather than wrapped in Should -Not -Throw. The subsequent assertions will naturally fail if the command throws. This pattern appears in multiple tests in this file.

         It 'Should take the database offline and not throw' {
-            { Suspend-SqlDscDatabase -ServerObject $mockServerObject -Name 'TestDatabase' -Force } | Should -Not -Throw
+            $null = Suspend-SqlDscDatabase -ServerObject $mockServerObject -Name 'TestDatabase' -Force

             $mockDatabaseObject.Status | Should -Be ([Microsoft.SqlServer.Management.Smo.DatabaseStatus]::Offline)

             Should -Invoke -CommandName 'Get-SqlDscDatabase' -Exactly -Times 1 -Scope It
         }
source/Public/Resume-SqlDscDatabase.ps1 (1)

148-188: Avoid Write-Verbose inside ShouldProcess block.

Per coding guidelines, Write-Verbose should be avoided inside the $PSCmdlet.ShouldProcess block. Consider moving verbose output outside the conditional or removing it since ShouldProcess already provides feedback.

Lines 153, 157, and 177 contain Write-Verbose calls inside the ShouldProcess block:

         if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
         {
             # Check if database is already online (idempotence)
             if ($sqlDatabaseObject.Status -eq [Microsoft.SqlServer.Management.Smo.DatabaseStatus]::Normal)
             {
-                Write-Verbose -Message ($script:localizedData.Database_AlreadyOnline -f $sqlDatabaseObject.Name)
+                # Database is already online, no action needed
             }
             else
             {
-                Write-Verbose -Message ($script:localizedData.Database_BringingOnline -f $sqlDatabaseObject.Name)
-
                 try
                 {
                     $sqlDatabaseObject.SetOnline()
                 }
                 catch
                 {
                     # error handling...
                 }
-
-                Write-Verbose -Message ($script:localizedData.Database_BroughtOnline -f $sqlDatabaseObject.Name)
             }
tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1 (1)

121-127: Avoid Should -Not -Throw; invoke commands directly.

Per coding guidelines, Should -Not -Throw should not be used. Instead, invoke commands directly and let any exceptions naturally fail the test.

Apply this pattern throughout the test file:

         It 'Should bring the database online and not throw' {
-            { Resume-SqlDscDatabase -ServerObject $mockServerObject -Name 'TestDatabase' -Force } | Should -Not -Throw
+            $null = Resume-SqlDscDatabase -ServerObject $mockServerObject -Name 'TestDatabase' -Force

             $mockDatabaseObject.Status | Should -Be ([Microsoft.SqlServer.Management.Smo.DatabaseStatus]::Normal)

             Should -Invoke -CommandName 'Get-SqlDscDatabase' -Exactly -Times 1 -Scope It
         }

This pattern applies to all It blocks using Should -Not -Throw (lines 122, 132, 151, 167, 196, 212, 232).

tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1 (1)

108-111: Avoid -ExpectedMessage in integration tests.

Per coding guidelines, integration tests should avoid the -ExpectedMessage parameter for Should -Throw assertions because error messages can vary based on the environment.

         It 'Should throw error when trying to take offline non-existent database' {
-            { Suspend-SqlDscDatabase -ServerObject $script:serverObject -Name 'NonExistentDatabase' -Force -ErrorAction 'Stop' } |
-                Should -Throw -ExpectedMessage '*Database*NonExistentDatabase*not found*'
+            { Suspend-SqlDscDatabase -ServerObject $script:serverObject -Name 'NonExistentDatabase' -Force -ErrorAction 'Stop' } |
+                Should -Throw
         }
source/Public/Suspend-SqlDscDatabase.ps1 (1)

151-188: Consider moving verbose messages outside ShouldProcess block.

Per coding guidelines: "Inside $PSCmdlet.ShouldProcess-block, avoid using Write-Verbose". The ShouldProcess description message already explains the operation, so additional verbose messages inside the block can be redundant.

Consider restructuring to move the idempotency check before ShouldProcess:

+        # Check if database is already offline (idempotence)
+        if ($sqlDatabaseObject.Status -eq [Microsoft.SqlServer.Management.Smo.DatabaseStatus]::Offline)
+        {
+            Write-Verbose -Message ($script:localizedData.Database_AlreadyOffline -f $sqlDatabaseObject.Name)
+
+            if ($PassThru.IsPresent)
+            {
+                $sqlDatabaseObject
+            }
+
+            return
+        }
+
         if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
         {
-            # Check if database is already offline (idempotence)
-            if ($sqlDatabaseObject.Status -eq [Microsoft.SqlServer.Management.Smo.DatabaseStatus]::Offline)
-            {
-                Write-Verbose -Message ($script:localizedData.Database_AlreadyOffline -f $sqlDatabaseObject.Name)
-            }
-            else
-            {
-                if ($Force.IsPresent)
-                {
-                    Write-Verbose -Message ($script:localizedData.Database_TakingOfflineWithForce -f $sqlDatabaseObject.Name)
-                }
-                else
-                {
-                    Write-Verbose -Message ($script:localizedData.Database_TakingOffline -f $sqlDatabaseObject.Name)
-                }

This keeps verbose output before state change and avoids prompting when already in desired state.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 752efb6 and a76cf46.

📒 Files selected for processing (9)
  • CHANGELOG.md (1 hunks)
  • source/Public/Resume-SqlDscDatabase.ps1 (1 hunks)
  • source/Public/Suspend-SqlDscDatabase.ps1 (1 hunks)
  • source/en-US/SqlServerDsc.strings.psd1 (1 hunks)
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1 (1 hunks)
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1 (1 hunks)
  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1 (1 hunks)
  • tests/Unit/Stubs/SMO.cs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (18)
**/*.ps1

📄 CodeRabbit inference engine (.github/instructions/SqlServerDsc-guidelines.instructions.md)

**/*.ps1: Format public commands as {Verb}-SqlDsc{Noun} following PowerShell naming conventions
Format private functions as {Verb}-{Noun} following PowerShell naming conventions

Files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • source/Public/Resume-SqlDscDatabase.ps1
  • source/Public/Suspend-SqlDscDatabase.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
**/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)

**/*.[Tt]ests.ps1: All public commands, private functions and classes must have unit tests
All public commands and class-based resources must have integration tests
Use Pester v5 syntax only
Test code only inside Describe blocks
Assertions only in It blocks
Never test verbose messages, debug messages or parameter binding behavior
Pass all mandatory parameters to avoid prompts
Inside It blocks, assign unused return objects to $null (unless part of pipeline)
Tested entity must be called from within the It blocks
Keep results and assertions in same It block
Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
Avoid unnecessary remove/recreate cycles
One Describe block per file matching the tested entity name
Context descriptions start with 'When'
It descriptions start with 'Should', must not contain 'when'
Mock variables prefix: 'mock'
Public commands: Never use InModuleScope (unless retrieving localized strings or creating an object using an internal class)
Private functions/class resources: Always use InModuleScope
Each class method = separate Context block
Each scenario = separate Context block
Use nested Context blocks for complex scenarios
Mocking in BeforeAll (BeforeEach only when required)
Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage
Spacing between blocks, arrange, act, and assert for readability
PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
Use -BeTrue/-BeFalse never -Be $true/-Be $false
Never use Assert-MockCalled, use Should -Invoke instead
No Should -Not -Throw - invoke commands directly
Never add an empty -MockWith block
Omit -MockWith when returning $null
Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, InModuleScope:ModuleName
Omit -ModuleName parameter on Pester commands
Never use Mock inside InModuleScope-block
Never use param() inside -MockWith scriptblock...

Files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core Requirements

  • All public commands, private functions and classes must have unit tests
  • All public commands and class-based resources must have integration tests
  • Use Pester v5 syntax only
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test verbose messages, debug messages or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Requirements

  • Inside It blocks, assign unused return objects to $null (unless part of pipeline)
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cycles

Naming

  • One Describe block per file matching the tested entity name
  • Context descriptions start with 'When'
  • It descriptions start with 'Should', must not contain 'when'
  • Mock variables prefix: 'mock'

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings or creating an object using an internal class)
  • Private functions/class resources: Always use InModuleScope
  • Each class method = separate Context block
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage
  • Spacing between blocks, arrange, act, and assert for readability

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • Use -BeTrue/-BeFalse never -Be $true/-Be $false
  • Never use Assert-MockCalled, use Should -Invoke instead
  • No Should -Not -Throw - invoke commands directly
  • Never add an empty -MockWith block
  • Omit -MockWith when returning $null
  • Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, `...

Files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
tests/Unit/Public/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)

Public commands: tests/Unit/Public/{Name}.Tests.ps1

Files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
**/*.{ps1,psm1,psd1}

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)

**/*.{ps1,psm1,psd1}: Use descriptive names with 3+ characters and no abbreviations for functions, variables, and identifiers
Functions: Use PascalCase with Verb-Noun format using approved verbs
Parameters: Use PascalCase
Variables: Use camelCase
Keywords: Use lower-case
Classes: Use PascalCase
Include scope for script/global/environment variables: $script:, $global:, $env:
Use 4 spaces for indentation (no tabs)
Use one space around operators: $a = 1 + 2
Use one space between type and variable: [String] $name
Use one space between keyword and parenthesis: if ($condition)
No spaces on empty lines
Try to limit lines to 120 characters
Newline before opening brace (except variable assignments)
One newline after opening brace
Two newlines after closing brace (one if followed by another brace or continuation)
Use single quotes unless variable expansion is needed: 'text' vs "text $variable"
Single-line arrays: @('one', 'two', 'three'); multi-line: each element on separate line with proper indentation
Do not use the unary comma operator (,) in return statements to force an array
Empty hashtables: @{}; each property on separate line with proper indentation; use PascalCase for properties
Single-line comments: # Comment (capitalized, on own line); multi-line: <# Comment #> format with opening/closing brackets on own line
Do not include commented-out code
Always add comment-based help to all functions and scripts with SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, and EXAMPLE sections
Comment-based help indentation: keywords 4 spaces, text 8 spaces
Include examples in comment-based help for all parameter sets and combinations
INPUTS section in comment-based help: list each pipeline-accepted type (one per line) with 1-line description, repeat keyword for each input type
OUTPUTS section in comment-based help: list each return type (one per line) with 1-line description, repeat keyword for each output type; must match both [OutputType()] and actual ret...

Files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • source/Public/Resume-SqlDscDatabase.ps1
  • source/Public/Suspend-SqlDscDatabase.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • source/en-US/SqlServerDsc.strings.psd1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
tests/[Uu]nit/**/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md)

tests/[Uu]nit/**/*.[Tt]ests.ps1: Test with localized strings using InModuleScope -ScriptBlock { $script:localizedData.Key }
Mock files using the $TestDrive variable (path to the test drive)
All public commands require parameter set validation tests
Use the exact setup block with BeforeDiscovery, BeforeAll, and AfterAll blocks including DscResource.Test module import and PSDefaultParameterValues configuration
Parameter set validation tests should use Get-Command with Where-Object filtering and Should assertions to verify ParameterSetName and ParameterListAsString
Parameter property tests should verify mandatory parameter attributes using Get-Command Parameters and Should -BeTrue assertions

Files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1

⚙️ CodeRabbit configuration file

tests/[Uu]nit/**/*.[Tt]ests.ps1: # Unit Tests Guidelines

  • Test with localized strings: Use InModuleScope -ScriptBlock { $script:localizedData.Key }
  • Mock files: Use $TestDrive variable (path to the test drive)
  • All public commands require parameter set validation tests
  • After modifying classes, always run tests in new session (for changes to take effect)

Test Setup Requirements

Use this exact setup block before Describe:

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
    try
    {
        if (-not (Get-Module -Name 'DscResource.Test'))
        {
            # Assumes dependencies have 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' 3>&1 4>&1 5>&1 6>&1 > $null
            }

            # If the dependencies have 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 noop" first.'
    }
}

BeforeAll {
    $script:moduleName = '{MyModuleName}'

    Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'

    $PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
    $PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
    $PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
    $PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
    $PSDefaultParameterValues.Remove('Mock:ModuleNam...

Files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
tests/Unit/**/*.Tests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)

Unit tests should be located in tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1

Files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow Requirements

  • Run PowerShell script files from repository root
  • Setup build and test environment (once per pwsh session): ./build.ps1 -Tasks noop
  • Build project before running tests: ./build.ps1 -Tasks build
  • Always run tests in new pwsh session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Classes: source/Classes/{DependencyGroupNumber}.{ClassName}.ps1
  • Enums: source/Enum/{DependencyGroupNumber}.{EnumName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Follow instructions over existing code patterns
  • Follow PowerShell style and test guideline instructions strictly
  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys; remove any orphaned string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • DSC resources should always be created as class-based resources
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
  • source/Public/Resume-SqlDscDatabase.ps1
  • source/Public/Suspend-SqlDscDatabase.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • source/en-US/SqlServerDsc.strings.psd1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
  • CHANGELOG.md
{**/*.ps1,**/*.psm1,**/*.psd1}

⚙️ CodeRabbit configuration file

{**/*.ps1,**/*.psm1,**/*.psd1}: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

File naming

  • Class files: ###.ClassName.ps1 format (e.g. 001.SqlReason.ps1, 004.StartupParameters.ps1)

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description...

Files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • source/Public/Resume-SqlDscDatabase.ps1
  • source/Public/Suspend-SqlDscDatabase.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • source/en-US/SqlServerDsc.strings.psd1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
source/**/*.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-localization.instructions.md)

source/**/*.ps1: Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages in PowerShell scripts
Use localized string keys from $script:localizedData, not hardcoded strings, in diagnostic messages
Reference localized strings using the syntax: Write-Verbose -Message ($script:localizedData.KeyName -f $value1)

Localize all strings using string keys; remove any orphaned string keys

Files:

  • source/Public/Resume-SqlDscDatabase.ps1
  • source/Public/Suspend-SqlDscDatabase.ps1

⚙️ CodeRabbit configuration file

source/**/*.ps1: # Localization Guidelines

Requirements

  • Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages
  • Use localized string keys, not hardcoded strings
  • Assume $script:localizedData is available

String Files

  • Commands/functions: source/en-US/{MyModuleName}.strings.psd1
  • Class resources: source/en-US/{ResourceClassName}.strings.psd1

Key Naming Patterns

  • Format: Verb_FunctionName_Action (underscore separators), e.g. Get_Database_ConnectingToDatabase

String Format

ConvertFrom-StringData @'
    KeyName = Message with {0} placeholder. (PREFIX0001)
'@

String IDs

  • Format: (PREFIX####)
  • PREFIX: First letter of each word in class or function name (SqlSetup → SS, Get-SqlDscDatabase → GSDD)
  • Number: Sequential from 0001

Usage

Write-Verbose -Message ($script:localizedData.KeyName -f $value1)

Files:

  • source/Public/Resume-SqlDscDatabase.ps1
  • source/Public/Suspend-SqlDscDatabase.ps1
source/Public/*.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)

Public commands should be located in source/Public/{CommandName}.ps1

Files:

  • source/Public/Resume-SqlDscDatabase.ps1
  • source/Public/Suspend-SqlDscDatabase.ps1
**/tests/Integration/**/*.ps1

📄 CodeRabbit inference engine (.github/instructions/SqlServerDsc-guidelines.instructions.md)

Integration tests: use Connect-SqlDscDatabaseEngine for SQL Server DB session with correct CI credentials, and always follow with Disconnect-SqlDscDatabaseEngine

Files:

  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
tests/Integration/Commands/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md)

Location for Commands integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Integration tests for commands should be located in tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Files:

  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
tests/Integration/**/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md)

tests/Integration/**/*.Integration.Tests.ps1: Integration tests must not use mocking - use real environment only
Integration tests must cover all scenarios and code paths
Use Get-ComputerName for computer names in CI environments
Avoid ExpectedMessage parameter for Should -Throw assertions in integration tests
Call commands with -Force parameter where applicable to avoid prompting
Use -ErrorAction 'Stop' on commands so failures surface immediately
Integration tests must include the required setup block with BeforeDiscovery that imports DscResource.Test module and BeforeAll that imports the module being tested

Files:

  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).
  • Use -ErrorAction 'Stop' on commands so failures surface immediately

Required Setup Block

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
    try
    {
        if (-not (Get-Module -Name 'DscResource.Test'))
        {
            # Assumes dependencies have 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' 3>&1 4>&1 5>&1 6>&1 > $null
            }

            # If the dependencies have 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 noop" first.'
    }
}

BeforeAll {
    $script:moduleName = '{MyModuleName}'

    Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
source/en-US/*.strings.psd1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-localization.instructions.md)

source/en-US/*.strings.psd1: Store command/function localized strings in source/en-US/{MyModuleName}.strings.psd1 files
Store class resource localized strings in source/en-US/{ResourceClassName}.strings.psd1 files
Use Key Naming Pattern format: Verb_FunctionName_Action with underscore separators (e.g., Get_Database_ConnectingToDatabase)
Format localized strings using ConvertFrom-StringData with placeholder syntax: KeyName = Message with {0} placeholder. (PREFIX0001)
Prefix string IDs with an acronym derived from the first letter of each word in the class or function name (e.g., SqlSetup → SS, Get-SqlDscDatabase → GSDD), followed by sequential numbers starting from 0001

Files:

  • source/en-US/SqlServerDsc.strings.psd1
**/*.psd1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)

Don't use NestedModules for shared commands without RootModule in module manifest

Files:

  • source/en-US/SqlServerDsc.strings.psd1
CHANGELOG.md

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-changelog.instructions.md)

CHANGELOG.md: Always update the Unreleased section in CHANGELOG.md
Use Keep a Changelog format in CHANGELOG.md
Describe notable changes briefly in CHANGELOG.md, ≤2 items per change type
Reference issues using format issue #<issue_number> in CHANGELOG.md
No empty lines between list items in same section of CHANGELOG.md
Skip adding entry if same change already exists in Unreleased section of CHANGELOG.md
No duplicate sections or items in Unreleased section of CHANGELOG.md

Always update CHANGELOG.md Unreleased section

Files:

  • CHANGELOG.md

⚙️ CodeRabbit configuration file

CHANGELOG.md: # Changelog Guidelines

  • Always update the Unreleased section in CHANGELOG.md
  • Use Keep a Changelog format
  • Describe notable changes briefly, ≤2 items per change type
  • Reference issues using format issue #<issue_number>
  • No empty lines between list items in same section
  • Skip adding entry if same change already exists in Unreleased section
  • No duplicate sections or items in Unreleased section

Files:

  • CHANGELOG.md
**/*.md

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-markdown.instructions.md)

**/*.md: Wrap lines at word boundaries when over 80 characters (except tables/code blocks)
Use 2 spaces for indentation in Markdown files
Use '1.' for all items in ordered lists (1/1/1 numbering style)
Disable MD013 rule by adding a comment for tables/code blocks exceeding 80 characters
Empty lines required before/after code blocks and headings (except before line 1)
Escape backslashes in file paths only (not in code blocks)
Code blocks must specify language identifiers
Format parameters using bold in Markdown documentation
Format values and literals using inline code in Markdown documentation
Format resource/module/product names using italic in Markdown documentation
Format commands/files/paths using inline code in Markdown documentation

Files:

  • CHANGELOG.md

⚙️ CodeRabbit configuration file

**/*.md: # Markdown Style Guidelines

  • Wrap lines at word boundaries when over 80 characters (except tables/code blocks)
  • Use 2 spaces for indentation
  • Use '1.' for all items in ordered lists (1/1/1 numbering style)
  • Disable MD013 rule by adding a comment for tables/code blocks exceeding 80 characters
  • Empty lines required before/after code blocks and headings (except before line 1)
  • Escape backslashes in file paths only (not in code blocks)
  • Code blocks must specify language identifiers

Text Formatting

  • Parameters: bold
  • Values/literals: inline code
  • Resource/module/product names: italic
  • Commands/files/paths: inline code

Files:

  • CHANGELOG.md
🧠 Learnings (40)
📓 Common learnings
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.402Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests: use `Connect-SqlDscDatabaseEngine` for SQL Server DB session with correct CI credentials, and always follow with `Disconnect-SqlDscDatabaseEngine`
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.401Z
Learning: Applies to **/*.ps1 : Format public commands as `{Verb}-SqlDsc{Noun}` following PowerShell naming conventions
📚 Learning: 2025-11-27T17:58:02.402Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.402Z
Learning: Applies to **/tests/**/*.tests.ps1 : When unit tests test classes or commands containing SMO types like `[Microsoft.SqlServer.Management.Smo.*]`, ensure they are properly stubbed in SMO.cs

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.402Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.402Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests: use `Connect-SqlDscDatabaseEngine` for SQL Server DB session with correct CI credentials, and always follow with `Disconnect-SqlDscDatabaseEngine`

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • source/Public/Resume-SqlDscDatabase.ps1
  • source/Public/Suspend-SqlDscDatabase.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
  • CHANGELOG.md
📚 Learning: 2025-11-27T17:58:02.402Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.402Z
Learning: Applies to **/tests/**/*.tests.ps1 : Add `$env:SqlServerDscCI = $true` in `BeforeAll` block and remove in `AfterAll` block of unit tests

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.402Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.402Z
Learning: Applies to **/tests/**/*.tests.ps1 : In unit tests: use SMO stub types from SMO.cs, never mock SMO types

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
📚 Learning: 2025-11-27T17:58:02.402Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.402Z
Learning: After changing SMO stub types in SMO.cs, run tests in a new PowerShell session for changes to take effect

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
📚 Learning: 2025-11-27T17:59:27.192Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.192Z
Learning: Applies to tests/Unit/Public/*.[Tt]ests.ps1 : Public commands: `tests/Unit/Public/{Name}.Tests.ps1`

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:13:30.079Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2136
File: source/Public/Remove-SqlDscLogin.ps1:104-108
Timestamp: 2025-08-17T10:13:30.079Z
Learning: In SqlServerDsc unit tests, SMO object stubs (like Login objects) should have properly mocked Parent properties with correct Server stub types and valid InstanceName values, rather than handling null Parent scenarios in production code.

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T18:00:20.925Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-11-27T18:00:20.925Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : All public commands require parameter set validation tests

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.192Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.192Z
Learning: Applies to tests/Unit/Private/*.[Tt]ests.ps1 : Private functions: `tests/Unit/Private/{Name}.Tests.ps1`

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
📚 Learning: 2025-11-27T18:00:20.925Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-11-27T18:00:20.925Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Use the exact setup block with BeforeDiscovery, BeforeAll, and AfterAll blocks including DscResource.Test module import and PSDefaultParameterValues configuration

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T18:00:20.925Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-11-27T18:00:20.925Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Parameter set validation tests should use Get-Command with Where-Object filtering and Should assertions to verify ParameterSetName and ParameterListAsString

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
📚 Learning: 2025-11-27T17:58:31.900Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-11-27T17:58:31.900Z
Learning: Applies to tests/Integration/**/*.Integration.Tests.ps1 : Call commands with `-Force` parameter where applicable to avoid prompting

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2136
File: tests/Unit/Public/Remove-SqlDscLogin.Tests.ps1:36-39
Timestamp: 2025-08-17T10:15:48.194Z
Learning: Public command unit tests guideline: Never use InModuleScope unless accessing localized strings from $script:localizedData. PSDefaultParameterValues for InModuleScope should be kept in public command tests to support localized string retrieval when necessary.

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
📚 Learning: 2025-11-27T18:00:20.925Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-11-27T18:00:20.925Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Parameter property tests should verify mandatory parameter attributes using Get-Command Parameters and Should -BeTrue assertions

Applied to files:

  • tests/Unit/Public/Suspend-SqlDscDatabase.Tests.ps1
  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.401Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.401Z
Learning: Applies to **/resources/**/*.ps1 : Add `InstanceName`, `ServerName`, and `Credential` to `$this.ExcludeDscProperties` in Database Engine resources

Applied to files:

  • source/Public/Suspend-SqlDscDatabase.ps1
📚 Learning: 2025-11-27T17:58:31.900Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-11-27T17:58:31.900Z
Learning: Applies to tests/Integration/**/*.Integration.Tests.ps1 : Integration tests must include the required setup block with BeforeDiscovery that imports DscResource.Test module and BeforeAll that imports the module being tested

Applied to files:

  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.192Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.192Z
Learning: Applies to **/*.[Tt]ests.ps1 : Cover all scenarios and code paths

Applied to files:

  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.192Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.192Z
Learning: Applies to **/*.[Tt]ests.ps1 : All public commands, private functions and classes must have unit tests

Applied to files:

  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.192Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.192Z
Learning: Applies to **/*.[Tt]ests.ps1 : All public commands and class-based resources must have integration tests

Applied to files:

  • tests/Unit/Public/Resume-SqlDscDatabase.Tests.ps1
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T18:00:35.054Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T18:00:35.054Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Integration tests for commands should be located in `tests/Integration/Commands/{CommandName}.Integration.Tests.ps1`

Applied to files:

  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:31.900Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-11-27T17:58:31.900Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Location for Commands integration tests: `tests/Integration/Commands/{CommandName}.Integration.Tests.ps1`

Applied to files:

  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:31.900Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-11-27T17:58:31.900Z
Learning: Applies to tests/Integration/Resources/*.Integration.Tests.ps1 : Location for Resources integration tests: `tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1`

Applied to files:

  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T18:56:46.724Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 1622
File: tests/Integration/DSC_SqlDatabase.Integration.Tests.ps1:1-30
Timestamp: 2025-11-27T18:56:46.724Z
Learning: Integration tests for MOF-based DSC resources (located in source/DSCResources/**) should use the Initialize-TestEnvironment pattern with -ResourceType 'Mof', not the BeforeDiscovery/BeforeAll pattern. The BeforeDiscovery/BeforeAll pattern is for class-based resources only.

Applied to files:

  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:31.900Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-11-27T17:58:31.900Z
Learning: Applies to tests/Integration/**/*.Integration.Tests.ps1 : Avoid `ExpectedMessage` parameter for `Should -Throw` assertions in integration tests

Applied to files:

  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.192Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.192Z
Learning: Applies to **/*.[Tt]ests.ps1 : Mocking in `BeforeAll` (`BeforeEach` only when required)

Applied to files:

  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-10-04T21:33:23.022Z
Learnt from: dan-hughes
Repo: dsccommunity/UpdateServicesDsc PR: 85
File: source/en-US/UpdateServicesDsc.strings.psd1:1-2
Timestamp: 2025-10-04T21:33:23.022Z
Learning: In UpdateServicesDsc (and similar DSC modules), the module-level localization file (source/en-US/<ModuleName>.strings.psd1) can be empty when DSC resources have their own localization files in source/DSCResources/<ResourceName>/en-US/DSC_<ResourceName>.strings.psd1. Automated tests verify localization completeness for resources. Don't flag empty module-level localization files as issues when resources have separate localization.

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-11-27T17:59:01.498Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-11-27T17:59:01.498Z
Learning: Applies to source/DSCResources/**/*.psm1 : Use localized strings for all messages including Write-Verbose, Write-Error, and other messaging commands

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-11-27T17:59:01.498Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-11-27T17:59:01.498Z
Learning: Applies to source/DSCResources/**/en-US/DSC_*.strings.psd1 : Name localized strings file as `DSC_<ResourceName>.strings.psd1` in the `en-US` folder

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-11-27T17:59:01.498Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-11-27T17:59:01.498Z
Learning: Applies to source/DSCResources/**/en-US/DSC_*.strings.psd1 : In `.strings.psd1` files, use underscores as word separators in localized string key names for multi-word keys

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-11-27T17:58:42.320Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-11-27T17:58:42.320Z
Learning: Applies to source/**/*.ps1 : Use localized string keys from $script:localizedData, not hardcoded strings, in diagnostic messages

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-11-27T17:58:42.320Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-11-27T17:58:42.320Z
Learning: Applies to source/en-US/*.strings.psd1 : Prefix string IDs with an acronym derived from the first letter of each word in the class or function name (e.g., SqlSetup → SS, Get-SqlDscDatabase → GSDD), followed by sequential numbers starting from 0001

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-08-17T10:48:15.384Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-11-27T17:59:01.498Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-11-27T17:59:01.498Z
Learning: Applies to source/DSCResources/**/*.psm1 : Import localized strings using `Get-LocalizedData` at the module top level

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-11-27T17:58:42.320Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-11-27T17:58:42.320Z
Learning: Applies to source/en-US/*.strings.psd1 : Store class resource localized strings in source/en-US/{ResourceClassName}.strings.psd1 files

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-11-27T17:58:42.320Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-11-27T17:58:42.320Z
Learning: Applies to source/en-US/*.strings.psd1 : Use Key Naming Pattern format: Verb_FunctionName_Action with underscore separators (e.g., Get_Database_ConnectingToDatabase)

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-11-27T17:58:02.401Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.401Z
Learning: Applies to **/*.ps1 : Format public commands as `{Verb}-SqlDsc{Noun}` following PowerShell naming conventions

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
  • CHANGELOG.md
📚 Learning: 2025-11-27T18:00:11.915Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-11-27T18:00:11.915Z
Learning: Applies to **/*.{ps1,psm1,psd1} : `$PSCmdlet.ShouldProcess` must use required pattern: localized messages for description, confirmation, and caption

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-11-27T17:58:31.900Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-11-27T17:58:31.900Z
Learning: Applies to tests/Integration/**/*.Integration.Tests.ps1 : Integration tests must cover all scenarios and code paths

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.401Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.401Z
Learning: Applies to **/resources/**/*.ps1 : Database Engine resources must inherit from `SqlResourceBase`

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 30, 2025

Codecov Report

❌ Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94%. Comparing base (9bf5f46) to head (46a050a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
source/Public/Resume-SqlDscDatabase.ps1 96% 1 Missing ⚠️
source/Public/Suspend-SqlDscDatabase.ps1 96% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff          @@
##           main   #2355   +/-   ##
====================================
  Coverage    94%     94%           
====================================
  Files       164     166    +2     
  Lines      9709    9765   +56     
====================================
+ Hits       9152    9206   +54     
- Misses      557     559    +2     
Flag Coverage Δ
unit 94% <96%> (+<1%) ⬆️
Files with missing lines Coverage Δ
source/Public/Resume-SqlDscDatabase.ps1 96% <96%> (ø)
source/Public/Suspend-SqlDscDatabase.ps1 96% <96%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johlju reviewed 10 of 10 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @johlju)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1 (1)

154-163: Good integration test for pipeline chaining.

Line 160 slightly exceeds the 120-character guideline (~140 chars). Consider breaking into separate statements for readability, though the current form clearly demonstrates the intended pipeline usage.

         # Bring online using pipeline
-            $resultDb = $script:serverObject | Get-SqlDscDatabase -Name $script:testDatabaseName | Resume-SqlDscDatabase -Force -PassThru -ErrorAction 'Stop'
+            $databaseObject = $script:serverObject | Get-SqlDscDatabase -Name $script:testDatabaseName
+            $resultDb = $databaseObject | Resume-SqlDscDatabase -Force -PassThru -ErrorAction 'Stop'
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ceaab0 and daeb33b.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1 (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • CHANGELOG.md
  • tests/Integration/Commands/Suspend-SqlDscDatabase.Integration.Tests.ps1
🧰 Additional context used
📓 Path-based instructions (9)
**/*.ps1

📄 CodeRabbit inference engine (.github/instructions/SqlServerDsc-guidelines.instructions.md)

**/*.ps1: Format public commands as {Verb}-SqlDsc{Noun} following PowerShell naming conventions
Format private functions as {Verb}-{Noun} following PowerShell naming conventions

Files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
**/tests/Integration/**/*.ps1

📄 CodeRabbit inference engine (.github/instructions/SqlServerDsc-guidelines.instructions.md)

Integration tests: use Connect-SqlDscDatabaseEngine for SQL Server DB session with correct CI credentials, and always follow with Disconnect-SqlDscDatabaseEngine

Files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
tests/Integration/Commands/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md)

Location for Commands integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Integration tests for commands should be located in tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
tests/Integration/**/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md)

tests/Integration/**/*.Integration.Tests.ps1: Integration tests must not use mocking - use real environment only
Integration tests must cover all scenarios and code paths
Use Get-ComputerName for computer names in CI environments
Avoid ExpectedMessage parameter for Should -Throw assertions in integration tests
Call commands with -Force parameter where applicable to avoid prompting
Use -ErrorAction 'Stop' on commands so failures surface immediately
Integration tests must include the required setup block with BeforeDiscovery that imports DscResource.Test module and BeforeAll that imports the module being tested

Files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
**/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)

**/*.[Tt]ests.ps1: All public commands, private functions and classes must have unit tests
All public commands and class-based resources must have integration tests
Use Pester v5 syntax only
Test code only inside Describe blocks
Assertions only in It blocks
Never test verbose messages, debug messages or parameter binding behavior
Pass all mandatory parameters to avoid prompts
Inside It blocks, assign unused return objects to $null (unless part of pipeline)
Tested entity must be called from within the It blocks
Keep results and assertions in same It block
Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
Avoid unnecessary remove/recreate cycles
One Describe block per file matching the tested entity name
Context descriptions start with 'When'
It descriptions start with 'Should', must not contain 'when'
Mock variables prefix: 'mock'
Public commands: Never use InModuleScope (unless retrieving localized strings or creating an object using an internal class)
Private functions/class resources: Always use InModuleScope
Each class method = separate Context block
Each scenario = separate Context block
Use nested Context blocks for complex scenarios
Mocking in BeforeAll (BeforeEach only when required)
Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage
Spacing between blocks, arrange, act, and assert for readability
PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
Use -BeTrue/-BeFalse never -Be $true/-Be $false
Never use Assert-MockCalled, use Should -Invoke instead
No Should -Not -Throw - invoke commands directly
Never add an empty -MockWith block
Omit -MockWith when returning $null
Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, InModuleScope:ModuleName
Omit -ModuleName parameter on Pester commands
Never use Mock inside InModuleScope-block
Never use param() inside -MockWith scriptblock...

Files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core Requirements

  • All public commands, private functions and classes must have unit tests
  • All public commands and class-based resources must have integration tests
  • Use Pester v5 syntax only
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test verbose messages, debug messages or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Requirements

  • Inside It blocks, assign unused return objects to $null (unless part of pipeline)
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cycles

Naming

  • One Describe block per file matching the tested entity name
  • Context descriptions start with 'When'
  • It descriptions start with 'Should', must not contain 'when'
  • Mock variables prefix: 'mock'

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings or creating an object using an internal class)
  • Private functions/class resources: Always use InModuleScope
  • Each class method = separate Context block
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage
  • Spacing between blocks, arrange, act, and assert for readability

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • Use -BeTrue/-BeFalse never -Be $true/-Be $false
  • Never use Assert-MockCalled, use Should -Invoke instead
  • No Should -Not -Throw - invoke commands directly
  • Never add an empty -MockWith block
  • Omit -MockWith when returning $null
  • Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, `...

Files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
**/*.{ps1,psm1,psd1}

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)

**/*.{ps1,psm1,psd1}: Use descriptive names with 3+ characters and no abbreviations for functions, variables, and identifiers
Functions: Use PascalCase with Verb-Noun format using approved verbs
Parameters: Use PascalCase
Variables: Use camelCase
Keywords: Use lower-case
Classes: Use PascalCase
Include scope for script/global/environment variables: $script:, $global:, $env:
Use 4 spaces for indentation (no tabs)
Use one space around operators: $a = 1 + 2
Use one space between type and variable: [String] $name
Use one space between keyword and parenthesis: if ($condition)
No spaces on empty lines
Try to limit lines to 120 characters
Newline before opening brace (except variable assignments)
One newline after opening brace
Two newlines after closing brace (one if followed by another brace or continuation)
Use single quotes unless variable expansion is needed: 'text' vs "text $variable"
Single-line arrays: @('one', 'two', 'three'); multi-line: each element on separate line with proper indentation
Do not use the unary comma operator (,) in return statements to force an array
Empty hashtables: @{}; each property on separate line with proper indentation; use PascalCase for properties
Single-line comments: # Comment (capitalized, on own line); multi-line: <# Comment #> format with opening/closing brackets on own line
Do not include commented-out code
Always add comment-based help to all functions and scripts with SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, and EXAMPLE sections
Comment-based help indentation: keywords 4 spaces, text 8 spaces
Include examples in comment-based help for all parameter sets and combinations
INPUTS section in comment-based help: list each pipeline-accepted type (one per line) with 1-line description, repeat keyword for each input type
OUTPUTS section in comment-based help: list each return type (one per line) with 1-line description, repeat keyword for each output type; must match both [OutputType()] and actual ret...

Files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow Requirements

  • Run PowerShell script files from repository root
  • Setup build and test environment (once per pwsh session): ./build.ps1 -Tasks noop
  • Build project before running tests: ./build.ps1 -Tasks build
  • Always run tests in new pwsh session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Classes: source/Classes/{DependencyGroupNumber}.{ClassName}.ps1
  • Enums: source/Enum/{DependencyGroupNumber}.{EnumName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Follow instructions over existing code patterns
  • Follow PowerShell style and test guideline instructions strictly
  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys; remove any orphaned string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • DSC resources should always be created as class-based resources
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
{**/*.ps1,**/*.psm1,**/*.psd1}

⚙️ CodeRabbit configuration file

{**/*.ps1,**/*.psm1,**/*.psd1}: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

File naming

  • Class files: ###.ClassName.ps1 format (e.g. 001.SqlReason.ps1, 004.StartupParameters.ps1)

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description...

Files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).
  • Use -ErrorAction 'Stop' on commands so failures surface immediately

Required Setup Block

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
    try
    {
        if (-not (Get-Module -Name 'DscResource.Test'))
        {
            # Assumes dependencies have 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' 3>&1 4>&1 5>&1 6>&1 > $null
            }

            # If the dependencies have 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 noop" first.'
    }
}

BeforeAll {
    $script:moduleName = '{MyModuleName}'

    Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
🧠 Learnings (14)
📓 Common learnings
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests: use `Connect-SqlDscDatabaseEngine` for SQL Server DB session with correct CI credentials, and always follow with `Disconnect-SqlDscDatabaseEngine`
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/*.ps1 : Format public commands as `{Verb}-SqlDsc{Noun}` following PowerShell naming conventions
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/**/*.tests.ps1 : When unit tests test classes or commands containing SMO types like `[Microsoft.SqlServer.Management.Smo.*]`, ensure they are properly stubbed in SMO.cs
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/**/*.tests.ps1 : Add `$env:SqlServerDscCI = $true` in `BeforeAll` block and remove in `AfterAll` block of unit tests
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: After changing SMO stub types in SMO.cs, run tests in a new PowerShell session for changes to take effect
Learnt from: dan-hughes
Repo: dsccommunity/UpdateServicesDsc PR: 85
File: source/en-US/UpdateServicesDsc.strings.psd1:1-2
Timestamp: 2025-10-04T21:33:23.022Z
Learning: In UpdateServicesDsc (and similar DSC modules), the module-level localization file (source/en-US/<ModuleName>.strings.psd1) can be empty when DSC resources have their own localization files in source/DSCResources/<ResourceName>/en-US/DSC_<ResourceName>.strings.psd1. Automated tests verify localization completeness for resources. Don't flag empty module-level localization files as issues when resources have separate localization.
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/resources/**/*.ps1 : Add `InstanceName`, `ServerName`, and `Credential` to `$this.ExcludeDscProperties` in Database Engine resources
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests: use `Connect-SqlDscDatabaseEngine` for SQL Server DB session with correct CI credentials, and always follow with `Disconnect-SqlDscDatabaseEngine`

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : All public commands and class-based resources must have integration tests

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/**/*.tests.ps1 : Add `$env:SqlServerDscCI = $true` in `BeforeAll` block and remove in `AfterAll` block of unit tests

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:31.910Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-11-27T17:58:31.910Z
Learning: Applies to tests/Integration/Resources/*.Integration.Tests.ps1 : Location for Resources integration tests: `tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1`

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T18:00:35.078Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T18:00:35.078Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Integration tests for commands should be located in `tests/Integration/Commands/{CommandName}.Integration.Tests.ps1`

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:31.910Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-11-27T17:58:31.910Z
Learning: Applies to tests/Integration/**/*.Integration.Tests.ps1 : Integration tests must include the required setup block with BeforeDiscovery that imports DscResource.Test module and BeforeAll that imports the module being tested

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:31.910Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-11-27T17:58:31.910Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Location for Commands integration tests: `tests/Integration/Commands/{CommandName}.Integration.Tests.ps1`

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:31.910Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-11-27T17:58:31.910Z
Learning: Applies to tests/Integration/**/*.Integration.Tests.ps1 : Call commands with `-Force` parameter where applicable to avoid prompting

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:31.910Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-11-27T17:58:31.910Z
Learning: Applies to tests/Integration/**/*.Integration.Tests.ps1 : Integration tests must cover all scenarios and code paths

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/**/*.tests.ps1 : When unit tests test classes or commands containing SMO types like `[Microsoft.SqlServer.Management.Smo.*]`, ensure they are properly stubbed in SMO.cs

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T18:56:46.759Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 1622
File: tests/Integration/DSC_SqlDatabase.Integration.Tests.ps1:1-30
Timestamp: 2025-11-27T18:56:46.759Z
Learning: Integration tests for MOF-based DSC resources (located in source/DSCResources/**) should use the Initialize-TestEnvironment pattern with -ResourceType 'Mof', not the BeforeDiscovery/BeforeAll pattern. The BeforeDiscovery/BeforeAll pattern is for class-based resources only.

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-11-27T18:00:20.934Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-11-27T18:00:20.934Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Use the exact setup block with BeforeDiscovery, BeforeAll, and AfterAll blocks including DscResource.Test module import and PSDefaultParameterValues configuration

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:13:30.079Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2136
File: source/Public/Remove-SqlDscLogin.ps1:104-108
Timestamp: 2025-08-17T10:13:30.079Z
Learning: In SqlServerDsc unit tests, SMO object stubs (like Login objects) should have properly mocked Parent properties with correct Server stub types and valid InstanceName values, rather than handling null Parent scenarios in production code.

Applied to files:

  • tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (5)
tests/Integration/Commands/Resume-SqlDscDatabase.Integration.Tests.ps1 (5)

1-30: LGTM!

The setup blocks follow the required integration test pattern correctly: BeforeDiscovery handles the DscResource.Test module dependency, and BeforeAll imports the module under test with appropriate flags.


32-53: LGTM!

The test setup follows guidelines: uses Get-ComputerName for portability, Connect-SqlDscDatabaseEngine for DB session, -Force -ErrorAction 'Stop' on commands, and random database name suffixes for test isolation.


55-76: LGTM!

Cleanup is well-implemented: properly brings offline databases online before removal, uses Disconnect-SqlDscDatabaseEngine to close the session per guidelines, and handles edge cases gracefully with appropriate error actions.


78-112: LGTM!

Good coverage of the ServerObject parameter set with tests for the happy path, idempotency behavior, and error handling for non-existent databases. Naming conventions are correct and Should -Throw avoids -ExpectedMessage per guidelines.


114-152: LGTM!

The DatabaseObject parameter set and pipeline input scenarios are well-tested, covering both direct parameter usage and pipeline input variants for ServerObject and DatabaseObject.

johlju and others added 3 commits December 2, 2025 18:37
@johlju johlju merged commit 79c0cc0 into dsccommunity:main Dec 3, 2025
30 of 31 checks passed
@johlju johlju deleted the fix/suspend-resume-database branch December 3, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suspend-SqlDscDatabase: New command proposal Resume-SqlDscDatabase: New command proposal

1 participant