Skip to content

Convert RDConnectionBrokerHAMode to class-based#155

Open
dan-hughes wants to merge 7 commits into
dsccommunity:mainfrom
dan-hughes:class/cbhamode
Open

Convert RDConnectionBrokerHAMode to class-based#155
dan-hughes wants to merge 7 commits into
dsccommunity:mainfrom
dan-hughes:class/cbhamode

Conversation

@dan-hughes
Copy link
Copy Markdown
Contributor

@dan-hughes dan-hughes commented May 15, 2026

Pull Request (PR) description

Convert RDConnectionBrokerHAMode to a class-based resource.

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 added/updated in README.md.
  • Resource parameter descriptions added/updated in README.md, schema.mof and comment-based
    help.
  • Comment-based help added/updated.
  • Localization strings added/updated in all localization files as appropriate.
  • Examples appropriately added/updated.
  • Unit tests added/updated. See DSC Community Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Community Testing Guidelines.
  • New/changed code adheres to DSC Community Style Guidelines.

This change is Reviewable

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 70955dc6-5b44-40c8-afe8-a4c87338446d

📥 Commits

Reviewing files that changed from the base of the PR and between 65cbcce and 8393541.

📒 Files selected for processing (1)
  • Resolve-Dependency.psd1
✅ Files skipped from review due to trivial changes (1)
  • Resolve-Dependency.psd1

Walkthrough

Converts RDConnectionBrokerHAMode from a legacy function/MOF DSC resource to a class-based ResourceBase DSC class, removes the old module and MOF schema, adds class implementation and comprehensive Pester tests, updates localization, and adjusts the module manifest and dependency config.

Changes

RDConnectionBrokerHAMode Class-Based Conversion

Layer / File(s) Summary
Class resource declaration and lifecycle delegation
source/Classes/020.RDConnectionBrokerHAMode.ps1
Introduces RDConnectionBrokerHAMode class inheriting from ResourceBase with DSC properties (key ClientAccessName, database connection fields, ConnectionBroker, read-only ActiveManagementServer and Reasons) and public Get(), Set(), Test() delegating to base.
State inspection and enforcement
source/Classes/020.RDConnectionBrokerHAMode.ps1
Implements GetCurrentState() calling Get-RDConnectionBrokerHighAvailability (defaults ConnectionBroker to FQDN), Modify() applying state via Set-RDConnectionBrokerHighAvailability with immutability guard when ActiveManagementServer is set, and AssertProperties() validating OS requirement and importing RemoteDesktop module.
Test suite bootstrap and infrastructure
tests/Unit/Classes/RDConnectionBrokerHAMode.Tests.ps1
Adds Pester harness, dependency check/load for DscResource.Test, imports module-under-test and stubs, and teardown cleanup.
Constructor and public method behavioral tests
tests/Unit/Classes/RDConnectionBrokerHAMode.Tests.ps1
Validates constructor, Get() behavior for desired/non-desired states, Set() conditional Modify() calls, and Test() correctness across property mismatch scenarios.
Hidden state management method tests
tests/Unit/Classes/RDConnectionBrokerHAMode.Tests.ps1
Tests GetCurrentState() absent/present flows, Modify() apply vs throw on existing ActiveManagementServer, and AssertProperties() OS requirement handling and module import.
Module manifest and localization setup
source/en-US/RDConnectionBrokerHAMode.strings.psd1, source/RemoteDesktopServicesDsc.psd1
Adds new localization strings RDSHA0001/RDSHA0002 and sets AliasesToExport = @() in module manifest.
Documentation and legacy resource removal
source/DSCResources/DSC_RDConnectionBrokerHAMode/..., CHANGELOG.md
Removes legacy DSC_RDConnectionBrokerHAMode.psm1 and MOF schema, deletes old localized strings and README description, and updates CHANGELOG to note class-based conversion.
Resolve-Dependency configuration
Resolve-Dependency.psd1
Comments out UseModuleFast setting.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ResourceBase
  participant RDConnectionBrokerHAMode
  participant Get-RDConnectionBrokerHighAvailability
  participant Set-RDConnectionBrokerHighAvailability
  participant Get-ComputerName

  Caller->>ResourceBase: Invoke Get/Set/Test
  ResourceBase->>RDConnectionBrokerHAMode: Delegate to Get/Set/Test
  RDConnectionBrokerHAMode->>Get-RDConnectionBrokerHighAvailability: GetCurrentState query
  RDConnectionBrokerHAMode->>Get-ComputerName: Default ConnectionBroker to FQDN (if empty)
  alt Applying changes
    RDConnectionBrokerHAMode->>Set-RDConnectionBrokerHighAvailability: Modify applies desired state
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: converting RDConnectionBrokerHAMode to a class-based resource, which aligns with the primary objective of the PR.
Description check ✅ Passed The description explains the PR purpose (converting to class-based resource) and references the linked issue #144, demonstrating relevance to the changeset.
Linked Issues check ✅ Passed The PR successfully converts RDConnectionBrokerHAMode from script-based to class-based DSC resource as required by issue #144, with unit tests added and CHANGELOG updated.
Out of Scope Changes check ✅ Passed All changes are directly related to the class-based conversion objective: new class implementation, removal of old script-based code, updated tests, localization strings, and manifest entries.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98%. Comparing base (b52372c) to head (65cbcce).

Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #155   +/-   ##
===================================
  Coverage    97%    98%           
===================================
  Files        10     10           
  Lines       536    528    -8     
===================================
- Hits        524    518    -6     
+ Misses       12     10    -2     
Files with missing lines Coverage Δ
source/Classes/020.RDConnectionBrokerHAMode.ps1 100% <100%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dan-hughes
Copy link
Copy Markdown
Contributor Author

@coderabbitai rate limit

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Review rate limit: 1/1 review remaining, available now.

@dan-hughes
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@dan-hughes
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 5

🧹 Nitpick comments (1)
tests/Unit/Classes/RDConnectionBrokerHAMode.Tests.ps1 (1)

27-50: ⚡ Quick win

Consider using $script:moduleName to match the required template.

The code uses $script:dscModuleName throughout the setup and teardown blocks, but the required template specifies $script:moduleName. While functionally equivalent, matching the template improves consistency across the codebase.

♻️ Proposed fix to align with template
 BeforeAll {
-    $script:dscModuleName = 'RemoteDesktopServicesDsc'
+    $script:moduleName = 'RemoteDesktopServicesDsc'
 
-    Import-Module -Name $script:dscModuleName -ErrorAction Stop
+    Import-Module -Name $script:moduleName -ErrorAction Stop
 
     # Load stub cmdlets and classes.
     Import-Module (Join-Path -Path $PSScriptRoot -ChildPath '..\Stubs\RemoteDesktop.stubs.psm1')
 
-    $PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:dscModuleName
-    $PSDefaultParameterValues['Mock:ModuleName'] = $script:dscModuleName
-    $PSDefaultParameterValues['Should:ModuleName'] = $script:dscModuleName
+    $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 stub module
     Remove-Module -Name RemoteDesktop.stubs -Force
 
     # Unload the module being tested so that it doesn't impact any other tests.
-    Get-Module -Name $script:dscModuleName -All | Remove-Module -Force
+    Get-Module -Name $script:moduleName -All | Remove-Module -Force
 }

As per coding guidelines, test files should use the exact setup block template specified under "Test Setup Requirements".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Unit/Classes/RDConnectionBrokerHAMode.Tests.ps1` around lines 27 - 50,
Rename the test setup variable to match the required template by changing the
declaration and all references of $script:dscModuleName to $script:moduleName in
the BeforeAll and AfterAll blocks (the declaration line, the Import-Module call,
the PSDefaultParameterValues assignments 'InModuleScope:ModuleName' and
'Mock:ModuleName' usages, the Remove-Module -Name RemoteDesktop.stubs -Force
call remains unchanged, and the Get-Module | Remove-Module call should use
$script:moduleName); ensure every occurrence inside BeforeAll and AfterAll
(including Get-Module -Name $script:dscModuleName -All | Remove-Module -Force)
is updated so the file matches the standard template.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CHANGELOG.md`:
- Line 15: Update the changelog entry "Converted to class-based resource [Issue
`#144`](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144)" to
use the required lowercase issue-link label by replacing "[Issue `#144`]" with
"[issue `#144`]" so it matches the repository changelog rule and the required
format referenced in the guidelines.

In `@source/Classes/020.RDConnectionBrokerHAMode.ps1`:
- Line 157: In the AssertProperties function change the stream redirection on
the Import-RemoteDesktopModule call so only the Verbose stream is suppressed;
replace the incorrect "4>&1 > $null" redirection with "4> $null" (i.e., update
the Import-RemoteDesktopModule invocation inside AssertProperties to use 4>
$null instead of 4>&1 > $null).
- Line 38: The DSC resource attribute on the class is missing an explicit
RunAsCredential setting; update the class attribute `[DscResource()]` to include
`RunAsCredential = 'Optional'` so it becomes `[DscResource(RunAsCredential =
'Optional')]`, ensuring the class-based resource explicitly declares
RunAsCredential as required by guidelines.

In `@tests/Unit/Classes/RDConnectionBrokerHAMode.Tests.ps1`:
- Around line 1-3: The SuppressMessageAttribute usage is missing the required
Justification parameter: update the attribute on the test setup block
(System.Diagnostics.CodeAnalysis.SuppressMessageAttribute) to include the
Justification parameter set to a short explanatory string (e.g.
Justification='ScriptAnalyzer doesn't understand Pester syntax'), matching the
exact template required by the Test Setup Requirements so the attribute becomes
something like SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments',
'', Justification='...') or using the named parameter Justification='<reason>'.
- Around line 5-25: In the BeforeDiscovery setup block update the two inline
comments that incorrectly say "dependencies has" to the grammatically correct
"dependencies have": change the comment above the noop invocation ("# Assumes
dependencies have been resolved, so if this module is not available, run 'noop'
task.") and the comment before Import-Module ("# If the dependencies have not
been resolved, this will throw an error.") so they match the required test setup
template; locate these comments near the Get-Module checks and the calls to "&
\"$PSScriptRoot/../../../build.ps1\" -Tasks 'noop'" and "Import-Module -Name
'DscResource.Test' -Force -ErrorAction 'Stop'".

---

Nitpick comments:
In `@tests/Unit/Classes/RDConnectionBrokerHAMode.Tests.ps1`:
- Around line 27-50: Rename the test setup variable to match the required
template by changing the declaration and all references of $script:dscModuleName
to $script:moduleName in the BeforeAll and AfterAll blocks (the declaration
line, the Import-Module call, the PSDefaultParameterValues assignments
'InModuleScope:ModuleName' and 'Mock:ModuleName' usages, the Remove-Module -Name
RemoteDesktop.stubs -Force call remains unchanged, and the Get-Module |
Remove-Module call should use $script:moduleName); ensure every occurrence
inside BeforeAll and AfterAll (including Get-Module -Name $script:dscModuleName
-All | Remove-Module -Force) is updated so the file matches the standard
template.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: af7bbaf0-fbd7-4fbe-a376-b7e40b78ddd2

📥 Commits

Reviewing files that changed from the base of the PR and between b52372c and 65cbcce.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • source/Classes/020.RDConnectionBrokerHAMode.ps1
  • source/DSCResources/DSC_RDConnectionBrokerHAMode/DSC_RDConnectionBrokerHAMode.psm1
  • source/DSCResources/DSC_RDConnectionBrokerHAMode/DSC_RDConnectionBrokerHAMode.schema.mof
  • source/DSCResources/DSC_RDConnectionBrokerHAMode/README.md
  • source/DSCResources/DSC_RDConnectionBrokerHAMode/en-US/DSC_RDConnectionBrokerHAMode.strings.psd1
  • source/RemoteDesktopServicesDsc.psd1
  • source/en-US/RDConnectionBrokerHAMode.strings.psd1
  • tests/Unit/Classes/RDConnectionBrokerHAMode.Tests.ps1
  • tests/Unit/DSC_RDConnectionBrokerHAMode.Tests.ps1
💤 Files with no reviewable changes (5)
  • source/DSCResources/DSC_RDConnectionBrokerHAMode/DSC_RDConnectionBrokerHAMode.schema.mof
  • source/DSCResources/DSC_RDConnectionBrokerHAMode/README.md
  • source/DSCResources/DSC_RDConnectionBrokerHAMode/en-US/DSC_RDConnectionBrokerHAMode.strings.psd1
  • tests/Unit/DSC_RDConnectionBrokerHAMode.Tests.ps1
  • source/DSCResources/DSC_RDConnectionBrokerHAMode/DSC_RDConnectionBrokerHAMode.psm1

Comment thread CHANGELOG.md
- WebAccessServer is now NOT a required parameter, mirroring the use
of the underlying cmdlet.
- `RDConnectionBrokerHAMode`
- Converted to class-based resource [Issue #144](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use the required issue-link label format in changelog entries.

Please use lowercase issue in the link label to match the repository changelog rule.

Proposed fix
-  - Converted to class-based resource [Issue `#144`](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144).
+  - Converted to class-based resource [issue `#144`](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144).

As per coding guidelines, "Reference issues using format issue #<issue_number>".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Converted to class-based resource [Issue #144](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144).
- Converted to class-based resource [issue `#144`](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CHANGELOG.md` at line 15, Update the changelog entry "Converted to
class-based resource [Issue
`#144`](https://github.com/dsccommunity/RemoteDesktopServicesDsc/issues/144)" to
use the required lowercase issue-link label by replacing "[Issue `#144`]" with
"[issue `#144`]" so it matches the repository changelog rule and the required
format referenced in the guidelines.

Returns the reason a property is not in desired state.
#>

[DscResource()]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In PowerShell DSC class resources, what is the default behavior when [DscResource()]omitsRunAsCredential, and how does RunAsCredential = 'Optional' affect PsDscRunAsCredential support?

💡 Result:

In PowerShell class-based DSC resources, the [DscResource()] attribute's RunAsCredential property defines how the resource interacts with the automatic PsDscRunAsCredential property [1]. Default Behavior When RunAsCredential is omitted from the [DscResource()] attribute, the default behavior is Optional [1]. This means that a user may optionally use the PsDscRunAsCredential property with the DSC resource [1]. This default behavior is functionally equivalent to explicitly setting RunAsCredential = 'Optional' or RunAsCredential = 'Default' [1]. Effect of 'Optional' Setting RunAsCredential = 'Optional' explicitly enables support for the PsDscRunAsCredential property [1]. When this is set (or defaulted), the DSC engine allows the user to provide a PSCredential object via the PsDscRunAsCredential parameter in the configuration [2][1]. If provided, the DSC engine attempts to execute the resource's methods under the context of the specified user account [2]. Important Context While these settings are defined in the [DscResource()] attribute, they are primarily relevant for DSC v1.1 and earlier [1]. In DSC v2.0 and later, the RunAsCredential property in the [DscResource()] attribute has no functional effect on the execution of the resource [1]. Additionally, the PsDscRunAsCredential property itself is only supported in DSC v1.1 and earlier [1].

Citations:


🏁 Script executed:

# Check the file and examine line 38
if [ -f "source/Classes/020.RDConnectionBrokerHAMode.ps1" ]; then
    echo "=== File exists ==="
    sed -n '35,42p' source/Classes/020.RDConnectionBrokerHAMode.ps1
else
    echo "File not found"
fi

Repository: dsccommunity/RemoteDesktopServicesDsc

Length of output: 284


🏁 Script executed:

# Search for all DSC resources and their attribute declarations
echo "=== All DSC resources in Classes directory ==="
find source/Classes -name "*.ps1" -type f -exec grep -l "class.*ResourceBase" {} \;

echo ""
echo "=== Their DscResource attributes ==="
find source/Classes -name "*.ps1" -type f -exec grep -B2 "class.*ResourceBase" {} + | grep -E "\[DscResource|class"

Repository: dsccommunity/RemoteDesktopServicesDsc

Length of output: 558


Add RunAsCredential to the DSC resource attribute.

The coding guidelines require explicit declaration as [DscResource(RunAsCredential = 'Optional')] for class-based resources.

Proposed fix
-[DscResource()]
+[DscResource(RunAsCredential = 'Optional')]
 class RDConnectionBrokerHAMode : ResourceBase
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[DscResource()]
[DscResource(RunAsCredential = 'Optional')]
class RDConnectionBrokerHAMode : ResourceBase
🧰 Tools
🪛 PSScriptAnalyzer (1.25.0)

[info] 38-159: No examples found for resource 'RDConnectionBrokerHAMode'

(PSDSCDscExamplesPresent)


[info] 38-159: No tests found for resource 'RDConnectionBrokerHAMode'

(PSDSCDscTestsPresent)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@source/Classes/020.RDConnectionBrokerHAMode.ps1` at line 38, The DSC resource
attribute on the class is missing an explicit RunAsCredential setting; update
the class attribute `[DscResource()]` to include `RunAsCredential = 'Optional'`
so it becomes `[DscResource(RunAsCredential = 'Optional')]`, ensuring the
class-based resource explicitly declares RunAsCredential as required by
guidelines.

}

# Module Import in verbose mode outputs lots of data, so redirecting to null.
Import-RemoteDesktopModule 4>&1 > $null
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In PowerShell, how is 4>&1 > $null evaluated, and what is the correct redirection syntax to suppress only stream 4 (verbose)?

💡 Result:

In PowerShell, the syntax 4>&1 > $null is evaluated as a two-step redirection process [1][2]. First, 4>&1 redirects the Verbose stream (stream 4) into the Success stream (stream 1) [1][2]. Second, the > $null operator redirects the resulting Success stream (which now contains the original Success output plus the redirected Verbose output) to the $null automatic variable, effectively discarding both [1][2]. To suppress only the Verbose stream (stream 4) without affecting the Success stream, you should redirect stream 4 directly to $null [1][2]. The correct syntax is: 4> $null This directs only the Verbose output to the $null device, leaving the Success stream (stream 1) to be displayed in the console or handled by other redirections as intended [1][2].

Citations:


🏁 Script executed:

cat -n source/Classes/020.RDConnectionBrokerHAMode.ps1 | sed -n '150,165p'

Repository: dsccommunity/RemoteDesktopServicesDsc

Length of output: 499


Fix stream redirection order in AssertProperties.

Line 157 uses 4>&1 > $null, which redirects both the Verbose stream (4) and Success stream (1) to $null. To suppress only the Verbose output as intended, use 4> $null.

Proposed fix
-        Import-RemoteDesktopModule 4>&1 > $null
+        Import-RemoteDesktopModule 4> $null
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Import-RemoteDesktopModule 4>&1 > $null
Import-RemoteDesktopModule 4> $null
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@source/Classes/020.RDConnectionBrokerHAMode.ps1` at line 157, In the
AssertProperties function change the stream redirection on the
Import-RemoteDesktopModule call so only the Verbose stream is suppressed;
replace the incorrect "4>&1 > $null" redirection with "4> $null" (i.e., update
the Import-RemoteDesktopModule invocation inside AssertProperties to use 4>
$null instead of 4>&1 > $null).

Comment on lines +1 to +3
# Suppressing this rule because Script Analyzer does not understand Pester's syntax.
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')]
param ()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add missing Justification parameter to match required template.

The SuppressMessageAttribute is missing the Justification parameter. As per coding guidelines, the test setup block must exactly match the required template.

📋 Proposed fix to match template
 # Suppressing this rule because Script Analyzer does not understand Pester's syntax.
-[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')]
+[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
 param ()

As per coding guidelines, test files must use the exact setup block template specified under "Test Setup Requirements".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Unit/Classes/RDConnectionBrokerHAMode.Tests.ps1` around lines 1 - 3,
The SuppressMessageAttribute usage is missing the required Justification
parameter: update the attribute on the test setup block
(System.Diagnostics.CodeAnalysis.SuppressMessageAttribute) to include the
Justification parameter set to a short explanatory string (e.g.
Justification='ScriptAnalyzer doesn't understand Pester syntax'), matching the
exact template required by the Test Setup Requirements so the attribute becomes
something like SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments',
'', Justification='...') or using the named parameter Justification='<reason>'.

Comment on lines +5 to +25
BeforeDiscovery {
try
{
if (-not (Get-Module -Name 'DscResource.Test'))
{
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
}

# If the dependencies has not been resolved, this will throw an error.
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
}
}
catch [System.IO.FileNotFoundException]
{
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Fix grammatical errors in comments to match required template.

The comments contain grammatical errors that deviate from the required template. "dependencies has" should be "dependencies have" in both occurrences (lines 10 and 17).

📋 Proposed fix to match template
-            # Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
+            # 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 has not been resolved, this will throw an error.
+            # If the dependencies have not been resolved, this will throw an error.
             Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'

As per coding guidelines, test files must use the exact setup block template specified under "Test Setup Requirements".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Unit/Classes/RDConnectionBrokerHAMode.Tests.ps1` around lines 5 - 25,
In the BeforeDiscovery setup block update the two inline comments that
incorrectly say "dependencies has" to the grammatically correct "dependencies
have": change the comment above the noop invocation ("# Assumes dependencies
have been resolved, so if this module is not available, run 'noop' task.") and
the comment before Import-Module ("# If the dependencies have not been resolved,
this will throw an error.") so they match the required test setup template;
locate these comments near the Get-Module checks and the calls to "&
\"$PSScriptRoot/../../../build.ps1\" -Tasks 'noop'" and "Import-Module -Name
'DscResource.Test' -Force -ErrorAction 'Stop'".

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.

RDConnectionBrokerHAMode - Convert to Class-Based

1 participant