diff --git a/src/Anexia.E5E.Tests/Integration/NonKeepAliveModeTests.cs b/src/Anexia.E5E.Tests/Integration/NonKeepAliveModeTests.cs new file mode 100644 index 0000000..aa19a66 --- /dev/null +++ b/src/Anexia.E5E.Tests/Integration/NonKeepAliveModeTests.cs @@ -0,0 +1,39 @@ +using System.Threading.Tasks; + +using Anexia.E5E.Functions; +using Anexia.E5E.Tests.Helpers; +using Anexia.E5E.Tests.TestHelpers; + +using Xunit; +using Xunit.Abstractions; + +namespace Anexia.E5E.Tests.Integration; + +public class NonKeepAliveModeTests : IntegrationTestBase +{ + public NonKeepAliveModeTests(ITestOutputHelper outputHelper) : base(outputHelper) + { + Host.ConfigureEndpoints(cfg => + { + cfg.RegisterEntrypoint(TestE5ERuntimeOptions.DefaultEntrypointName, + _ => Task.FromResult(E5EResponse.From("response"))); + }, new[] { TestE5ERuntimeOptions.DefaultEntrypointName, "+++", "0", "---" }); + } + + public override Task InitializeAsync() => Host.StartAsync(); + + + [Fact] + public async Task ShouldEndWithJsonResponse() + { + var (stdout, _) = await Host.WriteOnceAsync(builder => builder.WithData("request")); + Assert.EndsWith(@"{""result"":{""data"":""response"",""type"":""text""}}", stdout); + } + + [Fact] + public async Task ShouldNotWriteExecutionEndToStderr() + { + var (_, stderr) = await Host.WriteOnceAsync(builder => builder.WithData("request")); + Assert.Empty(stderr); + } +} diff --git a/src/Anexia.E5E.Tests/TestHelpers/IntegrationTestBase.cs b/src/Anexia.E5E.Tests/TestHelpers/IntegrationTestBase.cs index 7e46106..ee5224a 100644 --- a/src/Anexia.E5E.Tests/TestHelpers/IntegrationTestBase.cs +++ b/src/Anexia.E5E.Tests/TestHelpers/IntegrationTestBase.cs @@ -15,7 +15,7 @@ protected IntegrationTestBase(ITestOutputHelper outputHelper) : base(outputHelpe protected TestHostBuilder Host { get; } - public Task InitializeAsync() + public virtual Task InitializeAsync() { return Task.CompletedTask; } diff --git a/src/Anexia.E5E/Extensions/HostBuilderExtensions.cs b/src/Anexia.E5E/Extensions/HostBuilderExtensions.cs index c5dee56..7493f0e 100644 --- a/src/Anexia.E5E/Extensions/HostBuilderExtensions.cs +++ b/src/Anexia.E5E/Extensions/HostBuilderExtensions.cs @@ -71,10 +71,12 @@ public static IHostBuilder UseAnexiaE5E(this IHostBuilder hb, string[]? args, private sealed class E5EHostBuilderWrapper : IHostBuilder { private readonly IHostBuilder _inner; + private readonly E5ERuntimeOptions _options; public E5EHostBuilderWrapper(IHostBuilder inner, E5ERuntimeOptions runtimeOptions) { _inner = inner; + _options = runtimeOptions; _inner.ConfigureServices((_, services) => { services.AddHostedService(); @@ -110,6 +112,17 @@ public IHostBuilder ConfigureServices(Action