public async Task Function_Can_Handle_Failed_Initialization() { // Arrange void Configure(IServiceCollection services) { services.AddLogging((builder) => builder.AddXUnit(this)); } using var server = new LambdaTestServer(Configure); using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2)); await server.StartAsync(cts.Token); var context = await server.EnqueueAsync(@"{""Values"": null}"); _ = Task.Run(async() => { await context.Response.WaitToReadAsync(cts.Token); if (!cts.IsCancellationRequested) { cts.Cancel(); } }); using var httpClient = server.CreateClient(); // Act await Assert.ThrowsAsync <InvalidOperationException>( () => FunctionRunner.RunAsync <MyFailedInitializationHandler>(httpClient, cts.Token)); }
internal static async Task RunAsync( HttpClient?httpClient = null, CancellationToken cancellationToken = default) { await FunctionRunner.RunAsync <MyHandler>(httpClient, cancellationToken); }