@@ -67,6 +67,83 @@ public static void Print()
6767 await App . AssertOutputLineStartsWith ( "Changed!" ) ;
6868 }
6969
70+ [ Theory ]
71+ [ CombinatorialData ]
72+ public async Task AutoRestartOnRudeEdit ( bool nonInteractive )
73+ {
74+ var testAsset = TestAssets . CopyTestAsset ( "WatchHotReloadApp" )
75+ . WithSource ( ) ;
76+
77+ if ( ! nonInteractive )
78+ {
79+ testAsset = testAsset
80+ . WithProjectChanges ( project =>
81+ {
82+ project . Root . Descendants ( )
83+ . First ( e => e . Name . LocalName == "PropertyGroup" )
84+ . Add ( XElement . Parse ( """
85+ <HotReloadAutoRestart>true</HotReloadAutoRestart>
86+ """ ) ) ;
87+ } ) ;
88+ }
89+
90+ var programPath = Path . Combine ( testAsset . Path , "Program.cs" ) ;
91+
92+ App . Start ( testAsset , nonInteractive ? [ "--non-interactive" ] : [ ] ) ;
93+
94+ await App . AssertWaitingForChanges ( ) ;
95+ App . Process . ClearOutput ( ) ;
96+
97+ // rude edit: adding virtual method
98+ UpdateSourceFile ( programPath , src => src . Replace ( "/* member placeholder */" , "public virtual void F() {}" ) ) ;
99+
100+ await App . AssertOutputLineStartsWith ( MessageDescriptor . WaitingForChanges , failure : _ => false ) ;
101+
102+ App . AssertOutputContains ( "⌚ Restart is needed to apply the changes" ) ;
103+ App . AssertOutputContains ( $ "❌ [auto-restart] { programPath } (33,11): error ENC0023: Adding an abstract method or overriding an inherited method requires restarting the application.") ;
104+ App . AssertOutputContains ( $ "[WatchHotReloadApp ({ ToolsetInfo . CurrentTargetFramework } )] Exited") ;
105+ App . AssertOutputContains ( $ "[WatchHotReloadApp ({ ToolsetInfo . CurrentTargetFramework } )] Launched") ;
106+ }
107+
108+ [ Theory ]
109+ [ CombinatorialData ]
110+ public async Task AutoRestartOnNoEffectEdit ( bool nonInteractive )
111+ {
112+ var testAsset = TestAssets . CopyTestAsset ( "WatchHotReloadApp" )
113+ . WithSource ( ) ;
114+
115+ if ( ! nonInteractive )
116+ {
117+ testAsset = testAsset
118+ . WithProjectChanges ( project =>
119+ {
120+ project . Root . Descendants ( )
121+ . First ( e => e . Name . LocalName == "PropertyGroup" )
122+ . Add ( XElement . Parse ( """
123+ <HotReloadAutoRestart>true</HotReloadAutoRestart>
124+ """ ) ) ;
125+ } ) ;
126+ }
127+
128+ var programPath = Path . Combine ( testAsset . Path , "Program.cs" ) ;
129+
130+ App . Start ( testAsset , nonInteractive ? [ "--non-interactive" ] : [ ] ) ;
131+
132+ await App . AssertWaitingForChanges ( ) ;
133+ App . Process . ClearOutput ( ) ;
134+
135+ // rude edit: adding virtual method
136+ UpdateSourceFile ( programPath , src => src . Replace ( "Started" , "<Updated>" ) ) ;
137+
138+ await App . AssertOutputLineStartsWith ( MessageDescriptor . WaitingForChanges , failure : _ => false ) ;
139+
140+ App . AssertOutputContains ( "⌚ Restart is needed to apply the changes" ) ;
141+ App . AssertOutputContains ( $ "⚠ [auto-restart] { programPath } (16,19): warning ENC0118: Changing 'top-level code' might not have any effect until the application is restarted.") ;
142+ App . AssertOutputContains ( $ "[WatchHotReloadApp ({ ToolsetInfo . CurrentTargetFramework } )] Exited") ;
143+ App . AssertOutputContains ( $ "[WatchHotReloadApp ({ ToolsetInfo . CurrentTargetFramework } )] Launched") ;
144+ App . AssertOutputContains ( "<Updated>" ) ;
145+ }
146+
70147 /// <summary>
71148 /// Unchanged project doesn't build. Wait for source change and rebuild.
72149 /// </summary>
@@ -682,7 +759,7 @@ public async Task Aspire()
682759
683760 await App . AssertOutputLineStartsWith ( " ❔ Do you want to restart these projects? Yes (y) / No (n) / Always (a) / Never (v)" ) ;
684761
685- App . AssertOutputContains ( "dotnet watch ⌚ Unable to apply hot reload, restart is needed to apply the changes." ) ;
762+ App . AssertOutputContains ( "dotnet watch ⌚ Restart is needed to apply the changes." ) ;
686763 App . AssertOutputContains ( "error ENC0020: Renaming record 'WeatherForecast' requires restarting the application." ) ;
687764 App . AssertOutputContains ( "dotnet watch ⌚ Affected projects:" ) ;
688765 App . AssertOutputContains ( "dotnet watch ⌚ WatchAspire.ApiService" ) ;
0 commit comments