@@ -163,40 +163,49 @@ public void StartDependencyInstallationIfNeeded_InstallsSnapshotInForeground_Whe
163163        [ Fact ] 
164164        public  void  StartDependencyInstallationIfNeeded_InvokesBackgroundMaintainer_WhenAcceptableDependenciesAlreadyInstalled ( ) 
165165        { 
166-             _mockInstalledDependenciesLocator . Setup ( _  =>   _ . GetPathWithAcceptableDependencyVersionsInstalled ( ) ) 
167-                  . Returns ( "AlreadyInstalled" ) ; 
168-             _mockStorage . Setup ( _  =>   _ . GetDependencies ( ) ) . Returns ( GetAnyNonEmptyDependencyManifestEntries ( ) ) ; 
166+             try 
167+             { 
168+                  Environment . SetEnvironmentVariable ( "MDEnableAutomaticUpgrades" ,   "true" ) ; 
169169
170-             var  firstPowerShellRunspace  =  PowerShell . Create ( ) ; 
171-             Func < PowerShell >  powerShellFactory  =  PowerShell . Create ; 
170+                 _mockInstalledDependenciesLocator . Setup ( _ =>  _ . GetPathWithAcceptableDependencyVersionsInstalled ( ) ) 
171+                     . Returns ( "AlreadyInstalled" ) ; 
172+                 _mockStorage . Setup ( _ =>  _ . GetDependencies ( ) ) . Returns ( GetAnyNonEmptyDependencyManifestEntries ( ) ) ; 
172173
173-             _mockStorage . Setup ( _ =>  _ . SnapshotExists ( "AlreadyInstalled" ) ) . Returns ( true ) ; 
174+                 var  firstPowerShellRunspace  =  PowerShell . Create ( ) ; 
175+                 Func < PowerShell >  powerShellFactory  =  PowerShell . Create ; 
174176
175-             _mockBackgroundDependencySnapshotMaintainer . Setup ( 
176-                 _ =>  _ . InstallAndPurgeSnapshots ( It . IsAny < Func < PowerShell > > ( ) ,  It . IsAny < ILogger > ( ) ) ) 
177-                 . Returns ( "NewSnapshot" ) ; 
177+                 _mockStorage . Setup ( _ =>  _ . SnapshotExists ( "AlreadyInstalled" ) ) . Returns ( true ) ; 
178178
179-             using  ( var  dependencyManager  =  CreateDependencyManagerWithMocks ( ) ) 
180-             { 
181-                 dependencyManager . Initialize ( _mockLogger . Object ) ; 
182-                 dependencyManager . StartDependencyInstallationIfNeeded ( firstPowerShellRunspace ,  powerShellFactory ,  _mockLogger . Object ) ; 
183-                 var  hadToWait  =  dependencyManager . WaitForDependenciesAvailability ( ( )  =>  _mockLogger . Object ) ; 
179+                 _mockBackgroundDependencySnapshotMaintainer . Setup ( 
180+                     _ =>  _ . InstallAndPurgeSnapshots ( It . IsAny < Func < PowerShell > > ( ) ,  It . IsAny < ILogger > ( ) ) ) 
181+                     . Returns ( "NewSnapshot" ) ; 
184182
185-                 Assert . False ( hadToWait ) ; 
186-                 Assert . Equal ( "NewSnapshot" ,  dependencyManager . WaitForBackgroundDependencyInstallationTaskCompletion ( ) ) ; 
183+                 using  ( var  dependencyManager  =  CreateDependencyManagerWithMocks ( ) ) 
184+                 { 
185+                     dependencyManager . Initialize ( _mockLogger . Object ) ; 
186+                     dependencyManager . StartDependencyInstallationIfNeeded ( firstPowerShellRunspace ,  powerShellFactory ,  _mockLogger . Object ) ; 
187+                     var  hadToWait  =  dependencyManager . WaitForDependenciesAvailability ( ( )  =>  _mockLogger . Object ) ; 
187188
188-                 _mockBackgroundDependencySnapshotMaintainer . Verify ( 
189-                     _ =>  _ . InstallAndPurgeSnapshots ( powerShellFactory ,  _mockLogger . Object ) , 
189+                     Assert . False ( hadToWait ) ; 
190+                     Assert . Equal ( "NewSnapshot" ,  dependencyManager . WaitForBackgroundDependencyInstallationTaskCompletion ( ) ) ; 
191+ 
192+                     _mockBackgroundDependencySnapshotMaintainer . Verify ( 
193+                         _ =>  _ . InstallAndPurgeSnapshots ( powerShellFactory ,  _mockLogger . Object ) , 
194+                         Times . Once ) ; 
195+                 } 
196+ 
197+                 _mockLogger . Verify ( 
198+                     _ =>  _ . Log ( 
199+                         false , 
200+                         LogLevel . Trace , 
201+                         It . Is < string > ( message =>  message . Contains ( PowerShellWorkerStrings . AcceptableFunctionAppDependenciesAlreadyInstalled ) ) , 
202+                         It . IsAny < Exception > ( ) ) , 
190203                    Times . Once ) ; 
191204            } 
192- 
193-             _mockLogger . Verify ( 
194-                 _ =>  _ . Log ( 
195-                     false , 
196-                     LogLevel . Trace , 
197-                     It . Is < string > ( message =>  message . Contains ( PowerShellWorkerStrings . AcceptableFunctionAppDependenciesAlreadyInstalled ) ) , 
198-                     It . IsAny < Exception > ( ) ) , 
199-                 Times . Once ) ; 
205+             finally 
206+             { 
207+                 Environment . SetEnvironmentVariable ( "MDEnableAutomaticUpgrades" ,  null ) ; 
208+             } 
200209        } 
201210
202211        [ Fact ] 
0 commit comments