-
Notifications
You must be signed in to change notification settings - Fork 45
Fix formatting #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix formatting #114
Conversation
WalkthroughFormatting and style were standardized across the repo (spacing, quoting, negation style). MSFT_xRDGatewayConfiguration and MSFT_xRDServer added/relocated ValidateCustomModeParameters and tightened/changed some Get/Set/Test signatures and validations. Tests and examples were updated for naming/formatting and some mock property names. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Admin
participant DSC as DSC Engine
participant xRDGW as xRDGatewayConfiguration
participant RDS as RD Cmdlets
Admin->>DSC: Invoke Set-TargetResource(params)
DSC->>xRDGW: Set-TargetResource(params)
xRDGW->>xRDGW: ValidateCustomModeParameters(GatewayMode, ExternalFqdn, LogonMethod, ...)
alt GatewayMode == 'Custom'
xRDGW->>RDS: Set-RdDeploymentGatewayConfiguration(GatewayMode, ExternalFqdn, LogonMethod, UseCachedCredentials, BypassLocal, -Force)
RDS-->>xRDGW: Result / Error
else GatewayMode != 'Custom'
xRDGW-->>Admin: Emit warning for ignored Custom-only params
xRDGW->>RDS: Set-RdDeploymentGatewayConfiguration(GatewayMode, -Force)
RDS-->>xRDGW: Result / Error
end
xRDGW-->>DSC: Return status
DSC-->>Admin: Completed / Errored
sequenceDiagram
autonumber
actor Admin
participant DSC as DSC Engine
participant xRDSrv as xRDServer
participant RDS as RD Cmdlets
Admin->>DSC: Invoke Set-TargetResource(Role, GatewayExternalFqdn, ...)
DSC->>xRDSrv: Set-TargetResource(...)
xRDSrv->>xRDSrv: ValidateCustomModeParameters(Role, GatewayExternalFqdn)
alt Role == 'RDS-Gateway' and missing GatewayExternalFqdn
xRDSrv-->>DSC: Throw validation error
else Role != 'RDS-Gateway' or FQDN present
xRDSrv-->>Admin: Possibly warn and ignore non-applicable params
xRDSrv->>RDS: Add-RDServer(Role, ...)
RDS-->>xRDSrv: Result / Error
end
xRDSrv-->>DSC: Return status
DSC-->>Admin: Completed / Errored
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Pre-merge checks✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
tests/Unit/MSFT_xRDSessionDeployment.tests.ps1 (1)
75-190
: Restore hyphenatedShould
operators.The formatter stripped the
-
from everyShould -Be*
assertion (e.g., Lines 75, 85, 151, 189). Pester’s dynamic parameters require the hyphen; without it the call becomesShould BeLike
/Should Be
, which raises “A positional parameter cannot be found that accepts argument…” at runtime and the tests fail. Please revert these to the hyphenated form throughout the file.- $serviceWarning | Should BeLike "Failed to start RDMS service. Error: Cannot find any service with service name 'RDMS'*" + $serviceWarning | Should -BeLike "Failed to start RDMS service. Error: Cannot find any service with service name 'RDMS'*"tests/Unit/MSFT_xRDSessionCollection.tests.ps1 (1)
135-147
: ReplaceAssert-MockCalled
withShould -Invoke
.The test uses
Assert-MockCalled
, which violates the guideline. All assertions should useShould -Invoke
instead.As per coding guidelines.
Apply this pattern throughout the file (lines 135, 143, 247, 262, 280, 303, 304, 317):
- Assert-MockCalled -CommandName Get-RDSessionCollection -Times 1 -Scope It -ParameterFilter { + Should -Invoke -CommandName Get-RDSessionCollection -Times 1 -Scope It -ParameterFilter { $CollectionName -eq $testCollection[0].Name -and $ConnectionBroker -eq $testConnectionBroker }tests/Unit/MSFT_xRDGatewayConfiguration.tests.ps1 (1)
191-228
: ReplaceAssert-MockCalled
withShould -Invoke
.The test uses
Assert-MockCalled
, which violates the test guidelines. All mock assertions should useShould -Invoke
instead.As per coding guidelines.
Apply this pattern throughout the file (lines 191, 204, 208, 222, 262, 280, 405, 418, 422, 436):
- Assert-MockCalled -CommandName Add-RDServer -Times 0 -Scope It + Should -Invoke -CommandName Add-RDServer -Times 0 -Scope Itsource/DSCResources/MSFT_xRDGatewayConfiguration/MSFT_xRDGatewayConfiguration.psm1 (1)
8-72
: LGTM! Well-structured validation logic.The
ValidateCustomModeParameters
helper function correctly:
- Validates GatewayMode and related parameters
- Ensures all required parameters are present for 'Custom' mode
- Warns about unused parameters for 'DoNotUse' and 'Automatic' modes
- Improves code maintainability by centralizing validation logic
This is good modularization that follows DSC Community guidelines.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (39)
.vscode/analyzersettings.psd1
(1 hunks)CHANGELOG.md
(1 hunks)source/DSCResources/MSFT_xRDCertificateConfiguration/MSFT_xRDCertificateConfiguration.psm1
(3 hunks)source/DSCResources/MSFT_xRDConnectionBrokerHAMode/MSFT_xRDConnectionBrokerHAMode.psm1
(1 hunks)source/DSCResources/MSFT_xRDConnectionBrokerHAMode/MSFT_xRDConnectionBrokerHAMode.schema.mof
(0 hunks)source/DSCResources/MSFT_xRDGatewayConfiguration/MSFT_xRDGatewayConfiguration.psm1
(8 hunks)source/DSCResources/MSFT_xRDLicenseConfiguration/MSFT_xRDLicenseConfiguration.psm1
(6 hunks)source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
(11 hunks)source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.schema.mof
(0 hunks)source/DSCResources/MSFT_xRDServer/MSFT_xRDServer.psm1
(7 hunks)source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1
(5 hunks)source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.schema.mof
(0 hunks)source/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1
(9 hunks)source/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.schema.mof
(0 hunks)source/DSCResources/MSFT_xRDSessionDeployment/MSFT_xRDSessionDeployment.psm1
(6 hunks)source/DSCResources/MSFT_xRDSessionDeployment/MSFT_xRDSessionDeployment.schema.mof
(0 hunks)source/Examples/Resources/xRDConnectionBrokerHAMode/1-ConfigureHaMode.ps1
(1 hunks)source/Examples/Resources/xRDGatewayConfiguration/1-CreateGatewayConfiguration.ps1
(1 hunks)source/Examples/Resources/xRDLicenseConfiguration/1-CreateLicenseServer.ps1
(1 hunks)source/Examples/Resources/xRDRemoteApp/1-CreateRemoteApp.ps1
(1 hunks)source/Examples/Resources/xRDServer/1-JoinRDSHost.ps1
(1 hunks)source/Examples/Resources/xRDSessionCollection/1-CreateSessionCollection.ps1
(1 hunks)source/Examples/Resources/xRDSessionCollection/1-xRDSessionCollection_Full.ps1
(1 hunks)source/Examples/Resources/xRDSessionCollectionConfiguration/1-ConfigureSessionCollection.ps1
(1 hunks)source/Examples/Resources/xRDSessionDeployment/1-CreateSessionDeployment.ps1
(1 hunks)source/Examples/Resources/xRDSessionDeployment/1-xRDSessionDeployment_Full.ps1
(1 hunks)source/Modules/xRemoteDesktopSessionHostCommon.psd1
(1 hunks)source/Modules/xRemoteDesktopSessionHostCommon.psm1
(1 hunks)source/en-US/about_xRemoteDesktopSessionHost.help.txt
(0 hunks)source/xRemoteDesktopSessionHost.psd1
(2 hunks)tests/Unit/MSFT_xRDCertificateConfiguration.tests.ps1
(8 hunks)tests/Unit/MSFT_xRDGatewayConfiguration.tests.ps1
(17 hunks)tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
(3 hunks)tests/Unit/MSFT_xRDRemoteApp.tests.ps1
(7 hunks)tests/Unit/MSFT_xRDServer.tests.ps1
(6 hunks)tests/Unit/MSFT_xRDSessionCollection.tests.ps1
(17 hunks)tests/Unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1
(7 hunks)tests/Unit/MSFT_xRDSessionDeployment.tests.ps1
(13 hunks)tests/Unit/xRemoteDesktopSessionHost.tests.ps1
(1 hunks)
💤 Files with no reviewable changes (6)
- source/DSCResources/MSFT_xRDSessionDeployment/MSFT_xRDSessionDeployment.schema.mof
- source/en-US/about_xRemoteDesktopSessionHost.help.txt
- source/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.schema.mof
- source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.schema.mof
- source/DSCResources/MSFT_xRDConnectionBrokerHAMode/MSFT_xRDConnectionBrokerHAMode.schema.mof
- source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.schema.mof
🧰 Additional context used
📓 Path-based instructions (8)
**
⚙️ CodeRabbit configuration file
**
: # DSC Community GuidelinesTerminology
- 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
- 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:
source/Examples/Resources/xRDRemoteApp/1-CreateRemoteApp.ps1
source/Examples/Resources/xRDServer/1-JoinRDSHost.ps1
source/Examples/Resources/xRDConnectionBrokerHAMode/1-ConfigureHaMode.ps1
tests/Unit/MSFT_xRDSessionCollection.tests.ps1
tests/Unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1
source/Examples/Resources/xRDGatewayConfiguration/1-CreateGatewayConfiguration.ps1
source/Modules/xRemoteDesktopSessionHostCommon.psm1
source/Examples/Resources/xRDSessionCollectionConfiguration/1-ConfigureSessionCollection.ps1
source/DSCResources/MSFT_xRDLicenseConfiguration/MSFT_xRDLicenseConfiguration.psm1
tests/Unit/xRemoteDesktopSessionHost.tests.ps1
source/xRemoteDesktopSessionHost.psd1
source/Modules/xRemoteDesktopSessionHostCommon.psd1
source/Examples/Resources/xRDSessionCollection/1-CreateSessionCollection.ps1
tests/Unit/MSFT_xRDServer.tests.ps1
source/DSCResources/MSFT_xRDCertificateConfiguration/MSFT_xRDCertificateConfiguration.psm1
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
source/Examples/Resources/xRDSessionCollection/1-xRDSessionCollection_Full.ps1
source/Examples/Resources/xRDSessionDeployment/1-xRDSessionDeployment_Full.ps1
source/Examples/Resources/xRDLicenseConfiguration/1-CreateLicenseServer.ps1
CHANGELOG.md
tests/Unit/MSFT_xRDSessionDeployment.tests.ps1
source/DSCResources/MSFT_xRDConnectionBrokerHAMode/MSFT_xRDConnectionBrokerHAMode.psm1
tests/Unit/MSFT_xRDGatewayConfiguration.tests.ps1
tests/Unit/MSFT_xRDCertificateConfiguration.tests.ps1
tests/Unit/MSFT_xRDRemoteApp.tests.ps1
source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1
source/Examples/Resources/xRDSessionDeployment/1-CreateSessionDeployment.ps1
source/DSCResources/MSFT_xRDServer/MSFT_xRDServer.psm1
source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
source/DSCResources/MSFT_xRDSessionDeployment/MSFT_xRDSessionDeployment.psm1
source/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1
source/DSCResources/MSFT_xRDGatewayConfiguration/MSFT_xRDGatewayConfiguration.psm1
{**/*.ps1,**/*.psm1,**/*.psd1}
⚙️ CodeRabbit configuration file
{**/*.ps1,**/*.psm1,**/*.psd1}
: # PowerShell GuidelinesNaming
- 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 arrayHashtables
- 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:
source/Examples/Resources/xRDRemoteApp/1-CreateRemoteApp.ps1
source/Examples/Resources/xRDServer/1-JoinRDSHost.ps1
source/Examples/Resources/xRDConnectionBrokerHAMode/1-ConfigureHaMode.ps1
tests/Unit/MSFT_xRDSessionCollection.tests.ps1
tests/Unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1
source/Examples/Resources/xRDGatewayConfiguration/1-CreateGatewayConfiguration.ps1
source/Modules/xRemoteDesktopSessionHostCommon.psm1
source/Examples/Resources/xRDSessionCollectionConfiguration/1-ConfigureSessionCollection.ps1
source/DSCResources/MSFT_xRDLicenseConfiguration/MSFT_xRDLicenseConfiguration.psm1
tests/Unit/xRemoteDesktopSessionHost.tests.ps1
source/xRemoteDesktopSessionHost.psd1
source/Modules/xRemoteDesktopSessionHostCommon.psd1
source/Examples/Resources/xRDSessionCollection/1-CreateSessionCollection.ps1
tests/Unit/MSFT_xRDServer.tests.ps1
source/DSCResources/MSFT_xRDCertificateConfiguration/MSFT_xRDCertificateConfiguration.psm1
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
source/Examples/Resources/xRDSessionCollection/1-xRDSessionCollection_Full.ps1
source/Examples/Resources/xRDSessionDeployment/1-xRDSessionDeployment_Full.ps1
source/Examples/Resources/xRDLicenseConfiguration/1-CreateLicenseServer.ps1
tests/Unit/MSFT_xRDSessionDeployment.tests.ps1
source/DSCResources/MSFT_xRDConnectionBrokerHAMode/MSFT_xRDConnectionBrokerHAMode.psm1
tests/Unit/MSFT_xRDGatewayConfiguration.tests.ps1
tests/Unit/MSFT_xRDCertificateConfiguration.tests.ps1
tests/Unit/MSFT_xRDRemoteApp.tests.ps1
source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1
source/Examples/Resources/xRDSessionDeployment/1-CreateSessionDeployment.ps1
source/DSCResources/MSFT_xRDServer/MSFT_xRDServer.psm1
source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
source/DSCResources/MSFT_xRDSessionDeployment/MSFT_xRDSessionDeployment.psm1
source/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1
source/DSCResources/MSFT_xRDGatewayConfiguration/MSFT_xRDGatewayConfiguration.psm1
source/**/*.ps1
⚙️ CodeRabbit configuration file
source/**/*.ps1
: # Localization GuidelinesRequirements
- 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 availableString 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/Examples/Resources/xRDRemoteApp/1-CreateRemoteApp.ps1
source/Examples/Resources/xRDServer/1-JoinRDSHost.ps1
source/Examples/Resources/xRDConnectionBrokerHAMode/1-ConfigureHaMode.ps1
source/Examples/Resources/xRDGatewayConfiguration/1-CreateGatewayConfiguration.ps1
source/Examples/Resources/xRDSessionCollectionConfiguration/1-ConfigureSessionCollection.ps1
source/Examples/Resources/xRDSessionCollection/1-CreateSessionCollection.ps1
source/Examples/Resources/xRDSessionCollection/1-xRDSessionCollection_Full.ps1
source/Examples/Resources/xRDSessionDeployment/1-xRDSessionDeployment_Full.ps1
source/Examples/Resources/xRDLicenseConfiguration/1-CreateLicenseServer.ps1
source/Examples/Resources/xRDSessionDeployment/1-CreateSessionDeployment.ps1
tests/[Uu]nit/**/*.[Tt]ests.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/MSFT_xRDSessionCollection.tests.ps1
tests/Unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1
tests/Unit/xRemoteDesktopSessionHost.tests.ps1
tests/Unit/MSFT_xRDServer.tests.ps1
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
tests/Unit/MSFT_xRDSessionDeployment.tests.ps1
tests/Unit/MSFT_xRDGatewayConfiguration.tests.ps1
tests/Unit/MSFT_xRDCertificateConfiguration.tests.ps1
tests/Unit/MSFT_xRDRemoteApp.tests.ps1
**/*.[Tt]ests.ps1
⚙️ CodeRabbit configuration file
**/*.[Tt]ests.ps1
: # Tests GuidelinesCore 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
orAfterEach
- Avoid unnecessary remove/recreate cycles
Naming
- One
Describe
block per file matching the tested entity nameContext
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)- 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 usageSyntax Rules
- PascalCase:
Describe
,Context
,It
,Should
,BeforeAll
,BeforeEach
,AfterAll
,AfterEach
- Use
-BeTrue
/-BeFalse
never-Be $true
/-Be $false
- Never use
Assert-MockCalled
, useShould -Invoke
instead- No
Should -Not -Throw
- invoke commands directly- Never add an empty
-MockWith
block- Omit
-MockWith
when returning$null
- Set
$PSDefaultParameterValues
forMock:ModuleName
,Should:ModuleName
,InModuleScope:ModuleName
- Omit
-ModuleName
parameter on Pester commands- Never use
Mock
inside `InModuleSc...
Files:
tests/Unit/MSFT_xRDSessionCollection.tests.ps1
tests/Unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1
tests/Unit/xRemoteDesktopSessionHost.tests.ps1
tests/Unit/MSFT_xRDServer.tests.ps1
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
tests/Unit/MSFT_xRDSessionDeployment.tests.ps1
tests/Unit/MSFT_xRDGatewayConfiguration.tests.ps1
tests/Unit/MSFT_xRDCertificateConfiguration.tests.ps1
tests/Unit/MSFT_xRDRemoteApp.tests.ps1
source/DSCResources/**/*.psm1
⚙️ CodeRabbit configuration file
source/DSCResources/**/*.psm1
: # MOF-based Desired State Configuration (DSC) Resources GuidelinesRequired Functions
- Every DSC resource must define:
Get-TargetResource
,Set-TargetResource
,Test-TargetResource
- Export using
*-TargetResource
patternFunction Return Types
Get-TargetResource
: Must return hashtable with all resource propertiesTest-TargetResource
: Must return boolean ($true/$false)Set-TargetResource
: Must not return anything (void)Parameter Guidelines
Get-TargetResource
: Only include parameters needed to retrieve actual current state valuesGet-TargetResource
: Remove non-mandatory parameters that are never usedSet-TargetResource
andTest-TargetResource
: Must have identical parametersSet-TargetResource
andTest-TargetResource
: Unused mandatory parameters: Add "Not used in <function_name>" to help commentRequired Elements
- Each function must include
Write-Verbose
at least once
Get-TargetResource
: Use verbose message starting with "Getting the current state of..."Set-TargetResource
: Use verbose message starting with "Setting the desired state of..."Test-TargetResource
: Use verbose message starting with "Determining the current state of..."- Use localized strings for all messages (Write-Verbose, Write-Error, etc.)
- Import localized strings using
Get-LocalizedData
at module topError Handling
- Do not use
throw
for terminating errors- Use
try/catch
blocks to handle exceptions- Throw localized exceptions using the appropriate
New-*Exception
cmdlet:
New‑InvalidDataException
New-ArgumentException
New-InvalidOperationException
- [
New-ObjectNotFoundException
](https:/...
Files:
source/DSCResources/MSFT_xRDLicenseConfiguration/MSFT_xRDLicenseConfiguration.psm1
source/DSCResources/MSFT_xRDCertificateConfiguration/MSFT_xRDCertificateConfiguration.psm1
source/DSCResources/MSFT_xRDConnectionBrokerHAMode/MSFT_xRDConnectionBrokerHAMode.psm1
source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1
source/DSCResources/MSFT_xRDServer/MSFT_xRDServer.psm1
source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
source/DSCResources/MSFT_xRDSessionDeployment/MSFT_xRDSessionDeployment.psm1
source/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1
source/DSCResources/MSFT_xRDGatewayConfiguration/MSFT_xRDGatewayConfiguration.psm1
**/*.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
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
🧠 Learnings (19)
📚 Learning: 2025-09-16T16:34:44.689Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-09-16T16:34:44.689Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Include the exact Pester setup block before Describe: SuppressMessage attribute with param (); BeforeDiscovery to ensure DscResource.Test is available (fallback to build.ps1 -Tasks 'noop') and Import-Module; BeforeAll to set $script:moduleName, import the module, and set PSDefaultParameterValues for InModuleScope/Mock/Should; AfterAll to remove those defaults and unload the tested module
Applied to files:
tests/Unit/MSFT_xRDSessionCollection.tests.ps1
tests/Unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1
tests/Unit/MSFT_xRDServer.tests.ps1
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
tests/Unit/MSFT_xRDSessionDeployment.tests.ps1
📚 Learning: 2025-08-09T19:29:36.323Z
Learnt from: johlju
PR: dsccommunity/DscResource.Test#167
File: source/Private/Test-FileContainsClassResource.ps1:44-56
Timestamp: 2025-08-09T19:29:36.323Z
Learning: In the DscResource.Test repository, DSC resource attributes are consistently written as `[DscResource(...)]` rather than using variations like `[DscResourceAttribute()]` or fully qualified names like `[Microsoft.PowerShell.DesiredStateConfiguration.DscResource()]`. The Test-FileContainsClassResource function should focus on detecting the standard `[DscResource(...)]` pattern that is actually used in the codebase.
Applied to files:
tests/Unit/MSFT_xRDSessionCollection.tests.ps1
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
tests/Unit/MSFT_xRDRemoteApp.tests.ps1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Set-TargetResource and Test-TargetResource must have identical parameters
Applied to files:
tests/Unit/MSFT_xRDSessionCollection.tests.ps1
source/DSCResources/MSFT_xRDLicenseConfiguration/MSFT_xRDLicenseConfiguration.psm1
tests/Unit/MSFT_xRDServer.tests.ps1
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
tests/Unit/MSFT_xRDGatewayConfiguration.tests.ps1
tests/Unit/MSFT_xRDCertificateConfiguration.tests.ps1
tests/Unit/MSFT_xRDRemoteApp.tests.ps1
source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1
source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Set-TargetResource must not return anything (void)
Applied to files:
tests/Unit/MSFT_xRDSessionCollection.tests.ps1
source/DSCResources/MSFT_xRDLicenseConfiguration/MSFT_xRDLicenseConfiguration.psm1
tests/Unit/MSFT_xRDServer.tests.ps1
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
tests/Unit/MSFT_xRDGatewayConfiguration.tests.ps1
tests/Unit/MSFT_xRDCertificateConfiguration.tests.ps1
tests/Unit/MSFT_xRDRemoteApp.tests.ps1
source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1
source/DSCResources/MSFT_xRDServer/MSFT_xRDServer.psm1
source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Set-TargetResource: Write-Verbose message should start with "Setting the desired state of..."
Applied to files:
tests/Unit/MSFT_xRDSessionCollection.tests.ps1
tests/Unit/MSFT_xRDServer.tests.ps1
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
tests/Unit/MSFT_xRDGatewayConfiguration.tests.ps1
tests/Unit/MSFT_xRDRemoteApp.tests.ps1
source/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Test-TargetResource must return a boolean ($true/$false)
Applied to files:
tests/Unit/MSFT_xRDSessionCollection.tests.ps1
tests/Unit/MSFT_xRDServer.tests.ps1
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
tests/Unit/MSFT_xRDRemoteApp.tests.ps1
source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1
source/DSCResources/MSFT_xRDServer/MSFT_xRDServer.psm1
source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
source/DSCResources/MSFT_xRDGatewayConfiguration/MSFT_xRDGatewayConfiguration.psm1
📚 Learning: 2025-09-23T10:20:59.832Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-09-23T10:20:59.832Z
Learning: Resource class constructor must be: MyResourceName() : base () { } (no $PSScriptRoot parameter)
Applied to files:
tests/Unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1
📚 Learning: 2025-09-12T13:21:31.054Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Each scenario gets a separate Context block
Applied to files:
tests/Unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1
📚 Learning: 2025-09-12T13:21:31.054Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Use nested Context blocks for complex scenarios
Applied to files:
tests/Unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Get-TargetResource must return a hashtable containing all resource properties
Applied to files:
source/DSCResources/MSFT_xRDLicenseConfiguration/MSFT_xRDLicenseConfiguration.psm1
tests/Unit/MSFT_xRDRemoteApp.tests.ps1
source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1
source/DSCResources/MSFT_xRDServer/MSFT_xRDServer.psm1
source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Export resource functions using the *-TargetResource naming pattern
Applied to files:
source/DSCResources/MSFT_xRDLicenseConfiguration/MSFT_xRDLicenseConfiguration.psm1
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
tests/Unit/MSFT_xRDRemoteApp.tests.ps1
source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1
source/DSCResources/MSFT_xRDServer/MSFT_xRDServer.psm1
source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Every MOF DSC resource module must define the functions: Get-TargetResource, Set-TargetResource, and Test-TargetResource
Applied to files:
source/DSCResources/MSFT_xRDLicenseConfiguration/MSFT_xRDLicenseConfiguration.psm1
tests/Unit/MSFT_xRDServer.tests.ps1
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1
source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1
source/DSCResources/MSFT_xRDServer/MSFT_xRDServer.psm1
source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
📚 Learning: 2025-10-04T21:33:23.022Z
Learnt from: dan-hughes
PR: dsccommunity/UpdateServicesDsc#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:
tests/Unit/MSFT_xRDServer.tests.ps1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Each of Get-/Set-/Test-TargetResource must include at least one Write-Verbose call
Applied to files:
tests/Unit/MSFT_xRDServer.tests.ps1
source/DSCResources/MSFT_xRDServer/MSFT_xRDServer.psm1
source/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Import localized strings at the top of the module using Get-LocalizedData
Applied to files:
source/DSCResources/MSFT_xRDCertificateConfiguration/MSFT_xRDCertificateConfiguration.psm1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Get-TargetResource: remove non-mandatory parameters that are never used
Applied to files:
tests/Unit/MSFT_xRDRemoteApp.tests.ps1
source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Test-TargetResource: Write-Verbose message should start with "Determining the current state of..."
Applied to files:
source/DSCResources/MSFT_xRDServer/MSFT_xRDServer.psm1
source/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Get-TargetResource parameters: include only those needed to retrieve actual current state values
Applied to files:
source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
📚 Learning: 2025-09-16T16:34:27.319Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-16T16:34:27.319Z
Learning: Applies to **/*.{ps1,psm1} : Use Write-Verbose for high-level execution flow and user-actionable information
Applied to files:
source/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1
⏰ 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). (1)
- GitHub Check: dsccommunity.xRemoteDesktopSessionHost (Build Package Module)
🔇 Additional comments (44)
source/Examples/Resources/xRDRemoteApp/1-CreateRemoteApp.ps1 (2)
6-6
: Verify lowercase DSC keywords align with project conventions.The
Configuration
andNode
keywords have been changed to lowercase (configuration
,node
). While the PR states this follows DSC Community format guidelines, these constructs are typically PascalCase in standard DSC conventions. Please confirm this casing is intentional and consistent with your project's style standards.Also applies to: 11-11
14-24
: LGTM!Property alignment changes improve readability without altering functionality.
source/Examples/Resources/xRDServer/1-JoinRDSHost.ps1 (2)
6-6
: Verify lowercase DSC keywords align with project conventions.Same concern as in the previous file:
Configuration
andNode
changed to lowercase. Confirm this is consistent with DSC Community guidelines for this project.Also applies to: 10-10
14-15
: LGTM!Property alignment improves consistency.
source/Examples/Resources/xRDSessionCollectionConfiguration/1-ConfigureSessionCollection.ps1 (2)
6-6
: Verify lowercase DSC keywords align with project conventions.Consistent with other example files, but please confirm the lowercase
configuration
andnode
keywords match your DSC Community style standards.Also applies to: 10-10
13-33
: LGTM!Property alignment enhances readability without functional changes.
source/Examples/Resources/xRDLicenseConfiguration/1-CreateLicenseServer.ps1 (1)
6-6
: LGTM with verification.Formatting changes are consistent with the broader PR. Ensure the lowercase DSC keywords match project standards.
Also applies to: 11-11, 15-16
source/Examples/Resources/xRDSessionDeployment/1-CreateSessionDeployment.ps1 (1)
6-6
: LGTM with verification.All formatting changes are consistent with the PR's objectives. Confirm DSC keyword casing aligns with your style guidelines.
Also applies to: 10-10, 13-13, 15-15
source/Examples/Resources/xRDSessionCollection/1-xRDSessionCollection_Full.ps1 (1)
29-30
: LGTM!Property alignment is consistent with formatting improvements throughout the PR.
tests/Unit/MSFT_xRDSessionCollectionConfiguration.tests.ps1 (3)
1-2
: LGTM!Variable alignment improves readability.
Also applies to: 32-32
55-55
: LGTM!Mock structure formatting is clear and consistent.
Also applies to: 72-72
74-79
: LGTM!Pester syntax updates correctly apply:
- PascalCase for
It
andShould
commands- Single-quote standardization in test descriptions
- Context naming consistency
All changes are formatting-only with no functional impact.
Also applies to: 82-94, 96-136, 147-153, 155-166, 168-244, 280-332
tests/Unit/xRemoteDesktopSessionHost.tests.ps1 (3)
25-25
: LGTM!Single-quote usage in Describe block aligns with PowerShell guidelines.
27-27
: LGTM!
New-Object
casing is now consistent with PowerShell conventions.Also applies to: 33-33, 39-39, 45-45
28-30
: LGTM!Pester syntax updated correctly:
- PascalCase
It
andShould
commands- Proper formatting per Pester v5 guidelines
Also applies to: 34-36, 40-42, 46-48
tests/Unit/MSFT_xRDSessionCollection.tests.ps1 (1)
1-426
: LGTM: Formatting improvements are consistent.The formatting changes (single-quote usage, alignment, spacing) align with the DSC Community Style Guidelines and improve consistency.
source/DSCResources/MSFT_xRDCertificateConfiguration/MSFT_xRDCertificateConfiguration.psm1 (2)
2-5
: LGTM: Negation style improvement.The change from
!(Test-...)
to-not (Test-...)
improves readability and aligns with PowerShell best practices.
73-79
: LGTM: Hashtable alignment improvement.The alignment changes improve code readability while maintaining identical behavior.
source/DSCResources/MSFT_xRDConnectionBrokerHAMode/MSFT_xRDConnectionBrokerHAMode.psm1 (1)
2-5
: LGTM: Consistent negation style.The negation style change is consistent with other resources in the PR and aligns with PowerShell best practices.
source/Examples/Resources/xRDSessionCollection/1-CreateSessionCollection.ps1 (1)
6-19
: LGTM: Keyword casing and alignment improvements.The keyword casing changes (
configuration
,node
) and property alignment align with the PowerShell style guidelines for consistent formatting.As per coding guidelines.
source/Examples/Resources/xRDGatewayConfiguration/1-CreateGatewayConfiguration.ps1 (1)
6-22
: LGTM: Consistent formatting with other examples.The keyword casing and alignment changes are consistent with other example files in the PR and follow the PowerShell style guidelines.
tests/Unit/MSFT_xRDGatewayConfiguration.tests.ps1 (1)
1-454
: LGTM: Formatting improvements are consistent.The formatting changes (single-quote usage, hashtable alignment, property naming consistency) align with the DSC Community Style Guidelines.
source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1 (3)
2-5
: LGTM: Consistent negation style.The negation style change is consistent with other resources in the PR.
29-62
: LGTM: Formatting improvements enhance consistency.The changes to verbose messages (single quotes), Where-Object syntax, and hashtable formatting improve code consistency without altering behavior.
115-137
: LGTM: String formatting improvement.The change to use string interpolation with
-f
operator is cleaner and aligns with PowerShell best practices.source/DSCResources/MSFT_xRDSessionDeployment/MSFT_xRDSessionDeployment.psm1 (2)
2-6
: LGTM: Consistent OS requirement check.The negation style change is consistent with other resources in the PR and improves readability.
26-94
: LGTM: Comprehensive formatting improvements.The changes to verbose messages, hashtable formatting, SuppressMessageAttribute syntax, and role literals all align with the PowerShell style guidelines and improve consistency.
source/DSCResources/MSFT_xRDSessionCollectionConfiguration/MSFT_xRDSessionCollectionConfiguration.psm1 (4)
10-13
: LGTM! Improved OS requirement check style.The change from
if (!(Test-...))
toif (-not (Test-...))
with single-quoted throw message improves readability and aligns with PowerShell best practices.
26-27
: LGTM! Improved parameter attribute formatting.The added spacing in ValidateLength attributes (e.g.,
[ValidateLength(1, 256)]
) improves readability.Also applies to: 136-137, 299-300
79-125
: LGTM! Improved formatting and consistency.The changes enhance readability through:
- Single-quoted verbose messages
- Aligned hashtable keys
- Explicit Add calls for UserProfileDisk properties on Windows Server 2016+
The UserProfileDisk configuration block is well-structured and correctly conditional on OS version.
246-254
: LGTM! Improved hashtable alignment.The aligned key-value pairs in the splat hashtable improve code readability.
source/DSCResources/MSFT_xRDServer/MSFT_xRDServer.psm1 (2)
2-5
: LGTM! Consistent style improvements.The changes improve consistency:
-not
style for OS requirement checks- Single-quoted strings in ValidateSet attributes
- Single-quoted throw messages
Also applies to: 80-80, 161-161, 243-243
178-178
: LGTM! Proper validation integration.The call to
ValidateCustomModeParameters
correctly validates parameters before proceeding with Add-RDServer operations.source/DSCResources/MSFT_xRDGatewayConfiguration/MSFT_xRDGatewayConfiguration.psm1 (2)
13-13
: LGTM! Consistent ValidateSet formatting.The single-quoted strings in ValidateSet attributes align with PowerShell style guidelines and improve consistency across the codebase.
Also applies to: 98-100, 175-175, 184-184, 299-299, 304-304
255-265
: LGTM! Clear parameter handling for Custom mode.The explicit splat hashtable with Force and ErrorAction parameters provides clear, maintainable configuration for Custom mode gateway settings.
tests/Unit/MSFT_xRDServer.tests.ps1 (2)
1-2
: LGTM! Consistent variable formatting.The standardized spacing around assignments improves readability.
Also applies to: 32-32
41-44
: LGTM! Improved hashtable readability.The formatted Roles arrays with consistent indentation enhance code clarity.
Also applies to: 79-83, 101-104
tests/Unit/MSFT_xRDRemoteApp.tests.ps1 (1)
1-2
: LGTM! Formatting improvements.The standardized spacing and alignment improve test readability.
Also applies to: 34-34, 39-42
tests/Unit/MSFT_xRDLicenseConfiguration.tests.ps1 (2)
1-2
: LGTM! Consistent formatting.The standardized variable assignments improve readability.
Also applies to: 32-32
52-68
: LGTM! Improved mock data formatting.The single-quoted strings and aligned hashtable keys enhance test clarity.
source/DSCResources/MSFT_xRDLicenseConfiguration/MSFT_xRDLicenseConfiguration.psm1 (2)
2-5
: LGTM! Consistent style improvements.The changes align with PowerShell best practices:
-not
style for OS checks- Single-quoted strings in ValidateSet attributes
- Single-quoted verbose and throw messages
Also applies to: 26-26, 75-75, 118-118
46-50
: LGTM! Improved hashtable formatting.The unquoted keys and consistent alignment improve readability while maintaining functionality.
source/DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1 (2)
10-13
: LGTM! Comprehensive formatting improvements.The changes enhance consistency:
-not
style for OS requirement check- Spacing in ValidateLength attributes
- Single-quoted strings in ValidateSet attributes
- Single-quoted throw message
These align with DSC Community Style Guidelines.
Also applies to: 26-26, 35-35, 42-42, 104-104, 113-113, 120-120, 170-170, 179-179, 186-186
68-92
: LGTM! Improved hashtable formatting.The aligned key-value pairs and consistent spacing enhance readability while maintaining the same return structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tests/Unit/MSFT_xRDSessionDeployment.tests.ps1 (2)
1-27
: Replace deprecated test setup with required Pester v5 setup blocks.The test file uses the deprecated
Invoke-TestSetup
/Invoke-TestCleanup
pattern instead of the required Pester v5 setup blocks specified in the coding guidelines. The guidelines mandate usingBeforeDiscovery
,BeforeAll
, andAfterAll
blocks with specific structure.Replace lines 1-27 with the required setup pattern:
-$script:DSCModuleName = 'xRemoteDesktopSessionHost' -$script:DSCResourceName = 'MSFT_xRDSessionDeployment' - -function Invoke-TestSetup -{ - try - { - Import-Module -Name DscResource.Test -Force - } - catch [System.IO.FileNotFoundException] - { - throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' - } - - $script:testEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DscResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType 'Unit' -} - -function Invoke-TestCleanup -{ - Restore-TestEnvironment -TestEnvironment $script:testEnvironment -} - -Invoke-TestSetup +[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 = 'xRemoteDesktopSessionHost' + + 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:ModuleName') + $PSDefaultParameterValues.Remove('Should:ModuleName') + + # Unload the module being tested so that it doesn't impact any other tests. + Get-Module -Name $script:moduleName -All | Remove-Module -Force +}Based on learnings.
70-70
: Replace deprecatedAssert-MockCalled
withShould -Invoke
.The test file uses the deprecated Pester v4
Assert-MockCalled
cmdlet. Per coding guidelines, useShould -Invoke
instead.Example conversion for line 70:
- Assert-MockCalled -CommandName Get-Service -Times 1 + Should -Invoke -CommandName Get-Service -Times 1 -ExactlyApply similar changes to all
Assert-MockCalled
calls throughout the file (lines 70, 120, 140, 154, 171, 176, 189).As per coding guidelines.
Also applies to: 120-120, 140-140, 154-157, 171-176, 189-189
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/Unit/MSFT_xRDSessionDeployment.tests.ps1
(16 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**
⚙️ CodeRabbit configuration file
**
: # DSC Community GuidelinesTerminology
- 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
- 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/MSFT_xRDSessionDeployment.tests.ps1
tests/[Uu]nit/**/*.[Tt]ests.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/MSFT_xRDSessionDeployment.tests.ps1
{**/*.ps1,**/*.psm1,**/*.psd1}
⚙️ CodeRabbit configuration file
{**/*.ps1,**/*.psm1,**/*.psd1}
: # PowerShell GuidelinesNaming
- 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 arrayHashtables
- 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/MSFT_xRDSessionDeployment.tests.ps1
**/*.[Tt]ests.ps1
⚙️ CodeRabbit configuration file
**/*.[Tt]ests.ps1
: # Tests GuidelinesCore 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
orAfterEach
- Avoid unnecessary remove/recreate cycles
Naming
- One
Describe
block per file matching the tested entity nameContext
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)- 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 usageSyntax Rules
- PascalCase:
Describe
,Context
,It
,Should
,BeforeAll
,BeforeEach
,AfterAll
,AfterEach
- Use
-BeTrue
/-BeFalse
never-Be $true
/-Be $false
- Never use
Assert-MockCalled
, useShould -Invoke
instead- No
Should -Not -Throw
- invoke commands directly- Never add an empty
-MockWith
block- Omit
-MockWith
when returning$null
- Set
$PSDefaultParameterValues
forMock:ModuleName
,Should:ModuleName
,InModuleScope:ModuleName
- Omit
-ModuleName
parameter on Pester commands- Never use
Mock
inside `InModuleSc...
Files:
tests/Unit/MSFT_xRDSessionDeployment.tests.ps1
🧠 Learnings (2)
📚 Learning: 2025-09-16T16:34:44.689Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-09-16T16:34:44.689Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Include the exact Pester setup block before Describe: SuppressMessage attribute with param (); BeforeDiscovery to ensure DscResource.Test is available (fallback to build.ps1 -Tasks 'noop') and Import-Module; BeforeAll to set $script:moduleName, import the module, and set PSDefaultParameterValues for InModuleScope/Mock/Should; AfterAll to remove those defaults and unload the tested module
Applied to files:
tests/Unit/MSFT_xRDSessionDeployment.tests.ps1
📚 Learning: 2025-09-12T13:21:31.054Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-12T13:21:31.054Z
Learning: Applies to **/*.[Tt]ests.ps1 : Avoid try/catch/finally for cleanup; use AfterAll or AfterEach
Applied to files:
tests/Unit/MSFT_xRDSessionDeployment.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). (1)
- GitHub Check: dsccommunity.xRemoteDesktopSessionHost (Build Package Module)
🔇 Additional comments (2)
tests/Unit/MSFT_xRDSessionDeployment.tests.ps1 (2)
63-64
: LGTM: String literal formatting.The conversion from double quotes to single quotes for string literals is correct and follows the PowerShell style guideline to "use single quotes unless variable expansion is needed."
Also applies to: 75-76, 124-125, 129-130
398-405
: LGTM: Exception handling pattern.The catch/finally pattern correctly ensures that exceptions are propagated while cleanup is always performed. This is an acceptable approach for test teardown.
@johlju, can you have a quick look at this, please. I want to create one or two other PRs for fixing some bugs. Thanks! |
Pull Request (PR) description
The formatting in most source files was not according to the guidelines. Fixed formatting with the VSCode
Format Document
feature.This Pull Request (PR) fixes the following issues
Task list
Entry should say what was changed and how that affects users (if applicable), and
reference the issue being resolved (if applicable).
help.
This change is