@@ -203,4 +203,60 @@ public async Task RunCommand_CompletesSuccessfully()
203
203
var exitCode = await pendingRun . WaitAsync ( CliTestConstants . DefaultTimeout ) ;
204
204
Assert . Equal ( ExitCodeConstants . Success , exitCode ) ;
205
205
}
206
+
207
+ [ Fact ]
208
+ public async Task RunCommand_WithNoResources_CompletesSuccessfully ( )
209
+ {
210
+ var getResourceStatesAsyncCalled = new TaskCompletionSource ( ) ;
211
+ var backchannelFactory = ( IServiceProvider sp ) => {
212
+ var backchannel = new TestAppHostBackchannel ( ) ;
213
+ backchannel . GetResourceStatesAsyncCalled = getResourceStatesAsyncCalled ;
214
+
215
+ // Return empty resources using an empty enumerable
216
+ backchannel . GetResourceStatesAsyncCallback = _ => EmptyAsyncEnumerable < RpcResourceState > . Instance ;
217
+
218
+ return backchannel ;
219
+ } ;
220
+
221
+ var runnerFactory = ( IServiceProvider sp ) => {
222
+ var runner = new TestDotNetCliRunner ( ) ;
223
+ runner . CheckHttpCertificateAsyncCallback = ( options , ct ) => 0 ;
224
+ runner . BuildAsyncCallback = ( projectFile , options , ct ) => 0 ;
225
+ runner . GetAppHostInformationAsyncCallback = ( projectFile , options , ct ) => ( 0 , true , VersionHelper . GetDefaultTemplateVersion ( ) ) ;
226
+
227
+ runner . RunAsyncCallback = async ( projectFile , watch , noBuild , args , env , backchannelCompletionSource , options , ct ) =>
228
+ {
229
+ var backchannel = sp . GetRequiredService < IAppHostBackchannel > ( ) ;
230
+ backchannelCompletionSource ! . SetResult ( backchannel ) ;
231
+ await Task . Delay ( Timeout . InfiniteTimeSpan , ct ) ;
232
+ return 0 ;
233
+ } ;
234
+
235
+ return runner ;
236
+ } ;
237
+
238
+ var projectLocatorFactory = ( IServiceProvider sp ) => new TestProjectLocator ( ) ;
239
+
240
+ var services = CliTestHelper . CreateServiceCollection ( outputHelper , options =>
241
+ {
242
+ options . ProjectLocatorFactory = projectLocatorFactory ;
243
+ options . AppHostBackchannelFactory = backchannelFactory ;
244
+ options . DotNetCliRunnerFactory = runnerFactory ;
245
+ } ) ;
246
+
247
+ var provider = services . BuildServiceProvider ( ) ;
248
+ var command = provider . GetRequiredService < RootCommand > ( ) ;
249
+ var result = command . Parse ( "run" ) ;
250
+
251
+ using var cts = new CancellationTokenSource ( ) ;
252
+ var pendingRun = result . InvokeAsync ( cts . Token ) ;
253
+
254
+ await getResourceStatesAsyncCalled . Task . WaitAsync ( CliTestConstants . DefaultTimeout ) ;
255
+
256
+ // Simulate CTRL-C.
257
+ cts . Cancel ( ) ;
258
+
259
+ var exitCode = await pendingRun . WaitAsync ( CliTestConstants . DefaultTimeout ) ;
260
+ Assert . Equal ( ExitCodeConstants . Success , exitCode ) ;
261
+ }
206
262
}
0 commit comments