using System;
using System.Threading.Tasks;
using Elsa.Testing.Extensions;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Hosting;
using Xunit;
namespace Sample;
///
/// Sample integration test showing how to properly shutdown Elsa background tasks.
///
/// The startup class of your application.
public class IntegrationTestBase : IAsyncDisposable where TStartup : class
{
protected readonly WebApplicationFactory Factory;
public IntegrationTestBase()
{
Factory = new WebApplicationFactory();
// ... other initialization code
}
public async ValueTask DisposeAsync()
{
// Explicitly stop Elsa background tasks before disposing the factory
await Factory.ShutdownElsaAsync();
// Then stop the server and host
if (Factory.Server?.Host != null)
{
await Factory.Server.Host.StopAsync();
}
Factory.Dispose();
GC.SuppressFinalize(this);
}
}
///
/// Example test class inheriting from the base integration test class.
///
public class ExampleIntegrationTest : IntegrationTestBase
{
[Fact]
public async Task SampleTest()
{
// Test logic here
await Task.CompletedTask;
}
}
///
/// Sample startup class for demonstration purposes.
///
public class TestStartup
{
// This is just a placeholder class for the example
}