@@ -556,4 +556,193 @@ public async Task PublishMode_CreateProvisioningContextAsync_ReturnsValidContext
556556 Assert . NotNull ( context . Principal ) ;
557557 Assert . Equal ( "westus2" , context . Location . Name ) ;
558558 }
559+
560+ [ Fact ]
561+ public async Task CreateProvisioningContextAsync_SubscriptionInputStartsDisabledWhenNotConfigured ( )
562+ {
563+ // Arrange
564+ var testInteractionService = new TestInteractionService ( ) ;
565+ var options = ProvisioningTestHelpers . CreateOptions ( subscriptionId : null , location : null , resourceGroup : null ) ;
566+ var environment = ProvisioningTestHelpers . CreateEnvironment ( ) ;
567+ var logger = ProvisioningTestHelpers . CreateLogger ( ) ;
568+ var armClientProvider = ProvisioningTestHelpers . CreateArmClientProvider ( ) ;
569+ var userPrincipalProvider = ProvisioningTestHelpers . CreateUserPrincipalProvider ( ) ;
570+ var tokenCredentialProvider = ProvisioningTestHelpers . CreateTokenCredentialProvider ( ) ;
571+ var deploymentStateManager = ProvisioningTestHelpers . CreateUserSecretsManager ( ) ;
572+
573+ var provider = new RunModeProvisioningContextProvider (
574+ testInteractionService ,
575+ options ,
576+ environment ,
577+ logger ,
578+ armClientProvider ,
579+ userPrincipalProvider ,
580+ tokenCredentialProvider ,
581+ deploymentStateManager ,
582+ new DistributedApplicationExecutionContext ( DistributedApplicationOperation . Run ) ) ;
583+
584+ // Act
585+ _ = provider . CreateProvisioningContextAsync ( CancellationToken . None ) ;
586+
587+ // Assert - Wait for the first interaction (message bar)
588+ var messageBarInteraction = await testInteractionService . Interactions . Reader . ReadAsync ( ) ;
589+ messageBarInteraction . CompletionTcs . SetResult ( InteractionResult . Ok ( true ) ) ;
590+
591+ // Wait for the inputs interaction
592+ var inputsInteraction = await testInteractionService . Interactions . Reader . ReadAsync ( ) ;
593+
594+ // Find the subscription input
595+ var subscriptionInput = inputsInteraction . Inputs [ BaseProvisioningContextProvider . SubscriptionIdName ] ;
596+
597+ // Assert that subscription ID input starts disabled when not configured
598+ Assert . True ( subscriptionInput . Disabled , "Subscription ID input should be disabled initially when not configured" ) ;
599+ Assert . NotNull ( subscriptionInput . DynamicLoading ) ;
600+ }
601+
602+ [ Fact ]
603+ public async Task CreateProvisioningContextAsync_SubscriptionInputDependsOnTenantWhenNotConfigured ( )
604+ {
605+ // Arrange
606+ var testInteractionService = new TestInteractionService ( ) ;
607+ var options = ProvisioningTestHelpers . CreateOptions ( subscriptionId : null , location : null , resourceGroup : null ) ;
608+ var environment = ProvisioningTestHelpers . CreateEnvironment ( ) ;
609+ var logger = ProvisioningTestHelpers . CreateLogger ( ) ;
610+ var armClientProvider = ProvisioningTestHelpers . CreateArmClientProvider ( ) ;
611+ var userPrincipalProvider = ProvisioningTestHelpers . CreateUserPrincipalProvider ( ) ;
612+ var tokenCredentialProvider = ProvisioningTestHelpers . CreateTokenCredentialProvider ( ) ;
613+ var deploymentStateManager = ProvisioningTestHelpers . CreateUserSecretsManager ( ) ;
614+
615+ var provider = new RunModeProvisioningContextProvider (
616+ testInteractionService ,
617+ options ,
618+ environment ,
619+ logger ,
620+ armClientProvider ,
621+ userPrincipalProvider ,
622+ tokenCredentialProvider ,
623+ deploymentStateManager ,
624+ new DistributedApplicationExecutionContext ( DistributedApplicationOperation . Run ) ) ;
625+
626+ // Act
627+ _ = provider . CreateProvisioningContextAsync ( CancellationToken . None ) ;
628+
629+ // Assert - Wait for the first interaction (message bar)
630+ var messageBarInteraction = await testInteractionService . Interactions . Reader . ReadAsync ( ) ;
631+ messageBarInteraction . CompletionTcs . SetResult ( InteractionResult . Ok ( true ) ) ;
632+
633+ // Wait for the inputs interaction
634+ var inputsInteraction = await testInteractionService . Interactions . Reader . ReadAsync ( ) ;
635+
636+ // Find the subscription input
637+ var subscriptionInput = inputsInteraction . Inputs [ BaseProvisioningContextProvider . SubscriptionIdName ] ;
638+
639+ // Assert that subscription ID has dynamic loading that depends on tenant
640+ Assert . NotNull ( subscriptionInput . DynamicLoading ) ;
641+ Assert . NotNull ( subscriptionInput . DynamicLoading . DependsOnInputs ) ;
642+ var dependsOnInputs = Assert . Single ( subscriptionInput . DynamicLoading . DependsOnInputs ) ;
643+ Assert . Equal ( BaseProvisioningContextProvider . TenantName , dependsOnInputs ) ;
644+ }
645+
646+ [ Fact ]
647+ public async Task CreateProvisioningContextAsync_SubscriptionInputBecomesEnabledAfterTenantSelection ( )
648+ {
649+ // Arrange
650+ var testInteractionService = new TestInteractionService ( ) ;
651+ var options = ProvisioningTestHelpers . CreateOptions ( subscriptionId : null , location : null , resourceGroup : null ) ;
652+ var environment = ProvisioningTestHelpers . CreateEnvironment ( ) ;
653+ var logger = ProvisioningTestHelpers . CreateLogger ( ) ;
654+ var armClientProvider = ProvisioningTestHelpers . CreateArmClientProvider ( ) ;
655+ var userPrincipalProvider = ProvisioningTestHelpers . CreateUserPrincipalProvider ( ) ;
656+ var tokenCredentialProvider = ProvisioningTestHelpers . CreateTokenCredentialProvider ( ) ;
657+ var deploymentStateManager = ProvisioningTestHelpers . CreateUserSecretsManager ( ) ;
658+
659+ var provider = new RunModeProvisioningContextProvider (
660+ testInteractionService ,
661+ options ,
662+ environment ,
663+ logger ,
664+ armClientProvider ,
665+ userPrincipalProvider ,
666+ tokenCredentialProvider ,
667+ deploymentStateManager ,
668+ new DistributedApplicationExecutionContext ( DistributedApplicationOperation . Run ) ) ;
669+
670+ // Act
671+ var createTask = provider . CreateProvisioningContextAsync ( CancellationToken . None ) ;
672+
673+ // Assert - Wait for the first interaction (message bar)
674+ var messageBarInteraction = await testInteractionService . Interactions . Reader . ReadAsync ( ) ;
675+ messageBarInteraction . CompletionTcs . SetResult ( InteractionResult . Ok ( true ) ) ;
676+
677+ // Wait for the inputs interaction
678+ var inputsInteraction = await testInteractionService . Interactions . Reader . ReadAsync ( ) ;
679+
680+ // Set tenant ID
681+ inputsInteraction . Inputs [ BaseProvisioningContextProvider . TenantName ] . Value = "87654321-4321-4321-4321-210987654321" ;
682+
683+ // Find the subscription input
684+ var subscriptionInput = inputsInteraction . Inputs [ BaseProvisioningContextProvider . SubscriptionIdName ] ;
685+
686+ // Assert subscription is initially disabled
687+ Assert . True ( subscriptionInput . Disabled ) ;
688+
689+ // Trigger dynamic loading callback for subscription based on tenant selection
690+ await subscriptionInput . DynamicLoading ! . LoadCallback ( new LoadInputContext
691+ {
692+ AllInputs = inputsInteraction . Inputs ,
693+ CancellationToken = CancellationToken . None ,
694+ Input = subscriptionInput ,
695+ Services = new ServiceCollection ( ) . BuildServiceProvider ( )
696+ } ) ;
697+
698+ // Assert that subscription input is now enabled after tenant selection
699+ Assert . False ( subscriptionInput . Disabled , "Subscription ID input should be enabled after tenant selection" ) ;
700+ Assert . NotNull ( subscriptionInput . Options ) ;
701+ Assert . NotEmpty ( subscriptionInput . Options ) ;
702+ }
703+
704+ [ Fact ]
705+ public async Task CreateProvisioningContextAsync_SubscriptionInputHasNoDynamicLoadingWhenConfigured ( )
706+ {
707+ // Arrange
708+ var testInteractionService = new TestInteractionService ( ) ;
709+ var subscriptionId = "12345678-1234-1234-1234-123456789012" ;
710+ var options = ProvisioningTestHelpers . CreateOptions ( subscriptionId , location : null , resourceGroup : null ) ;
711+ var environment = ProvisioningTestHelpers . CreateEnvironment ( ) ;
712+ var logger = ProvisioningTestHelpers . CreateLogger ( ) ;
713+ var armClientProvider = ProvisioningTestHelpers . CreateArmClientProvider ( ) ;
714+ var userPrincipalProvider = ProvisioningTestHelpers . CreateUserPrincipalProvider ( ) ;
715+ var tokenCredentialProvider = ProvisioningTestHelpers . CreateTokenCredentialProvider ( ) ;
716+ var deploymentStateManager = ProvisioningTestHelpers . CreateUserSecretsManager ( ) ;
717+
718+ var provider = new RunModeProvisioningContextProvider (
719+ testInteractionService ,
720+ options ,
721+ environment ,
722+ logger ,
723+ armClientProvider ,
724+ userPrincipalProvider ,
725+ tokenCredentialProvider ,
726+ deploymentStateManager ,
727+ new DistributedApplicationExecutionContext ( DistributedApplicationOperation . Run ) ) ;
728+
729+ // Act
730+ _ = provider . CreateProvisioningContextAsync ( CancellationToken . None ) ;
731+
732+ // Assert - Wait for the first interaction (message bar)
733+ var messageBarInteraction = await testInteractionService . Interactions . Reader . ReadAsync ( ) ;
734+ messageBarInteraction . CompletionTcs . SetResult ( InteractionResult . Ok ( true ) ) ;
735+
736+ // Wait for the inputs interaction
737+ var inputsInteraction = await testInteractionService . Interactions . Reader . ReadAsync ( ) ;
738+
739+ // Find the subscription input
740+ var subscriptionInput = inputsInteraction . Inputs [ BaseProvisioningContextProvider . SubscriptionIdName ] ;
741+
742+ // Assert that subscription ID has no dynamic loading when pre-configured
743+ Assert . Null ( subscriptionInput . DynamicLoading ) ;
744+ Assert . True ( subscriptionInput . Disabled , "Subscription ID input should remain disabled when pre-configured" ) ;
745+ Assert . Equal ( InputType . Text , subscriptionInput . InputType ) ;
746+ Assert . Equal ( subscriptionId , subscriptionInput . Value ) ;
747+ }
559748}
0 commit comments