@@ -732,33 +732,45 @@ NovaModuleTools would update from 1.2.3 to prerelease 1.3.0-preview1.
732732Prerelease updates may be less stable than released versions.
733733Continue with the prerelease update?
734734"@
735+ $prompt.Choice.Keys | Should - Be @ (' Y' , ' N' )
736+ $prompt.Default | Should - Be ' N'
735737 }
736738 }
737739
738- It ' Confirm-NovaPrereleaseModuleUpdate delegates the generated prompt to ShouldContinue and returns the decision' {
739- InModuleScope $script :moduleName {
740- $calls = [System.Collections.Generic.List [object ]]::new()
741- $cmdlet = [pscustomobject ]@ {
742- Calls = $calls
743- ShouldContinueResult = $false
740+ It ' Confirm-NovaPrereleaseModuleUpdate uses a choice prompt that defaults prerelease updates to No' - ForEach @ (
741+ @ {ChoiceIndex = 1 ; Expected = $false }
742+ @ {ChoiceIndex = 0 ; Expected = $true }
743+ ) {
744+ InModuleScope $script :moduleName - Parameters @ {TestCase = $_ } {
745+ param ($TestCase )
746+
747+ $hostUi = [pscustomobject ]@ {
748+ State = [ordered ]@ {
749+ ChoiceCalls = 0
750+ ChoiceLabels = @ ()
751+ DefaultChoiceIndex = $null
752+ }
744753 }
745- $cmdlet | Add-Member - MemberType ScriptMethod - Name ShouldContinue - Value {
746- param ($Message , $Caption )
754+ $hostUi | Add-Member - MemberType ScriptMethod - Name PromptForChoice - Value {
755+ param ($Caption , $ Message, $Choices , $DefaultChoiceIndex )
747756
748- $this.Calls.Add ([pscustomobject ]@ {
749- Message = $Message
750- Caption = $Caption
751- }) | Out-Null
752- return $this.ShouldContinueResult
757+ $this.State.ChoiceCalls += 1
758+ $this.State.ChoiceLabels = @ ($Choices | ForEach-Object Label)
759+ $this.State.DefaultChoiceIndex = $DefaultChoiceIndex
760+ return $TestCase.ChoiceIndex
761+ }
762+ $cmdlet = [pscustomobject ]@ {
763+ Host = [pscustomobject ]@ {
764+ UI = $hostUi
765+ }
753766 }
754767
755768 $result = Confirm-NovaPrereleaseModuleUpdate - Cmdlet $cmdlet - CurrentVersion ' 1.2.3' - TargetVersion ' 2.0.0-preview2'
756769
757- $result | Should - BeFalse
758- $calls.Count | Should - Be 1
759- $calls [0 ].Caption | Should - Be ' Confirm prerelease NovaModuleTools update'
760- $calls [0 ].Message | Should -Match ' 1.2.3'
761- $calls [0 ].Message | Should -Match ' 2.0.0-preview2'
770+ $result | Should - Be $TestCase.Expected
771+ $hostUi.State.ChoiceCalls | Should - Be 1
772+ $hostUi.State.ChoiceLabels | Should - Be @ (' &Y' , ' &N' )
773+ $hostUi.State.DefaultChoiceIndex | Should - Be 1
762774 }
763775 }
764776
0 commit comments