@@ -99,6 +99,46 @@ Describe 'Invoke-ReportServerSetupAction' -Tag 'Private' {
9999 }
100100 }
101101
102+ Context ' When user is not elevated' {
103+ BeforeAll {
104+ # Mock Assert-ElevatedUser to throw the same error it would in a real scenario
105+ Mock - CommandName Assert-ElevatedUser - MockWith {
106+ $PSCmdlet.ThrowTerminatingError (
107+ [System.Management.Automation.ErrorRecord ]::new(
108+ ' This command must run in an elevated PowerShell session. (DRC0043)' ,
109+ ' UserNotElevated' ,
110+ [System.Management.Automation.ErrorCategory ]::InvalidOperation,
111+ ' Command parameters'
112+ )
113+ )
114+ }
115+
116+ # Create a valid executable file for the test
117+ New-Item - Path " $TestDrive /ssrs.exe" - ItemType File - Force | Out-Null
118+
119+ InModuleScope - ScriptBlock {
120+ $script :mockDefaultParameters = @ {
121+ Install = $true
122+ AcceptLicensingTerms = $true
123+ MediaPath = " $TestDrive /ssrs.exe"
124+ Force = $true
125+ }
126+ }
127+ }
128+
129+ It ' Should throw a terminating error and not continue execution' {
130+ InModuleScope - ScriptBlock {
131+ # This test verifies the fix for issue #2070 where Assert-ElevatedUser
132+ # would throw an error but the function would continue executing
133+ { Invoke-ReportServerSetupAction @mockDefaultParameters } |
134+ Should - Throw - ExpectedMessage ' *This command must run in an elevated PowerShell session*'
135+ }
136+
137+ # Ensure Assert-ElevatedUser was called
138+ Should - Invoke - CommandName Assert-ElevatedUser - Exactly - Times 1 - Scope It
139+ }
140+ }
141+
102142 Context ' When passing no existent path to parameter MediaPath' {
103143 BeforeAll {
104144 Mock - CommandName Assert-ElevatedUser
0 commit comments