Add project files.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using Hangfire.Annotations;
|
||||
|
||||
namespace Elsa.Workflows.ComponentTests.Fixtures;
|
||||
|
||||
[UsedImplicitly]
|
||||
public class App : IAsyncLifetime
|
||||
{
|
||||
public App()
|
||||
{
|
||||
Infrastructure = new();
|
||||
Cluster = new(Infrastructure);
|
||||
WorkflowServer = Cluster.Pod1;
|
||||
}
|
||||
|
||||
public Infrastructure Infrastructure { get; set; }
|
||||
public Cluster Cluster { get; set; }
|
||||
public WorkflowServer WorkflowServer { get; set; }
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
await Infrastructure.InitializeAsync();
|
||||
}
|
||||
|
||||
public async Task DisposeAsync()
|
||||
{
|
||||
await Cluster.DisposeAsync();
|
||||
await Infrastructure.DisposeAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Elsa.Workflows.ComponentTests.Fixtures;
|
||||
|
||||
[CollectionDefinition(nameof(AppCollection))]
|
||||
public class AppCollection : ICollectionFixture<App>
|
||||
{
|
||||
// This class has no code, and is never created. Its purpose is simply
|
||||
// to be the place to apply [CollectionDefinition] and all the
|
||||
// ICollectionFixture<> interfaces.
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Hangfire.Annotations;
|
||||
|
||||
namespace Elsa.Workflows.ComponentTests.Fixtures;
|
||||
|
||||
[UsedImplicitly]
|
||||
public class Cluster(Infrastructure infrastructure) : IAsyncDisposable
|
||||
{
|
||||
public WorkflowServer Pod3 { get; set; } = new(infrastructure, "http://localhost:5003");
|
||||
public WorkflowServer Pod2 { get; set; } = new(infrastructure, "http://localhost:5002");
|
||||
public WorkflowServer Pod1 { get; set; } = new(infrastructure, "http://localhost:5001");
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await Pod3.DisposeAsync();
|
||||
await Pod2.DisposeAsync();
|
||||
await Pod1.DisposeAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Testcontainers.PostgreSql;
|
||||
using Testcontainers.RabbitMq;
|
||||
|
||||
namespace Elsa.Workflows.ComponentTests.Fixtures;
|
||||
|
||||
public class Infrastructure : IAsyncLifetime
|
||||
{
|
||||
public readonly PostgreSqlContainer DbContainer = new PostgreSqlBuilder()
|
||||
.WithImage("postgres:latest")
|
||||
.WithDatabase("elsa")
|
||||
.WithUsername("postgres")
|
||||
.WithPassword("postgres")
|
||||
.Build();
|
||||
|
||||
public readonly RabbitMqContainer RabbitMqContainer = new RabbitMqBuilder()
|
||||
.WithImage("rabbitmq:4-management")
|
||||
.Build();
|
||||
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
return Task.WhenAll(
|
||||
DbContainer.StartAsync(),
|
||||
RabbitMqContainer.StartAsync());
|
||||
}
|
||||
|
||||
public Task DisposeAsync()
|
||||
{
|
||||
return Task.WhenAll(
|
||||
DbContainer.StopAsync(),
|
||||
RabbitMqContainer.StopAsync());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
using System.Reflection;
|
||||
using Elsa.Alterations.Extensions;
|
||||
using Elsa.Caching;
|
||||
using Elsa.EntityFrameworkCore.Extensions;
|
||||
using Elsa.EntityFrameworkCore.Modules.Alterations;
|
||||
using Elsa.EntityFrameworkCore.Modules.Identity;
|
||||
using Elsa.EntityFrameworkCore.Modules.Management;
|
||||
using Elsa.EntityFrameworkCore.Modules.Runtime;
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Identity.Providers;
|
||||
using Elsa.MassTransit.Extensions;
|
||||
using Elsa.Testing.Shared.Handlers;
|
||||
using Elsa.Testing.Shared.Services;
|
||||
using Elsa.Workflows.ComponentTests.Consumers;
|
||||
using Elsa.Workflows.ComponentTests.Decorators;
|
||||
using Elsa.Workflows.ComponentTests.Materializers;
|
||||
using Elsa.Workflows.ComponentTests.WorkflowProviders;
|
||||
using Elsa.Workflows.Management;
|
||||
using Elsa.Workflows.Runtime.Distributed.Extensions;
|
||||
using FluentStorage;
|
||||
using Hangfire.Annotations;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Refit;
|
||||
using static Elsa.Api.Client.RefitSettingsHelper;
|
||||
|
||||
namespace Elsa.Workflows.ComponentTests.Fixtures;
|
||||
|
||||
[UsedImplicitly]
|
||||
public class WorkflowServer(Infrastructure infrastructure, string url) : WebApplicationFactory<Program>
|
||||
{
|
||||
public TClient CreateApiClient<TClient>()
|
||||
{
|
||||
var client = CreateClient();
|
||||
client.BaseAddress = new(client.BaseAddress!, "/elsa/api");
|
||||
client.Timeout = TimeSpan.FromMinutes(1);
|
||||
return RestService.For<TClient>(client, CreateRefitSettings(Services));
|
||||
}
|
||||
|
||||
public HttpClient CreateHttpWorkflowClient()
|
||||
{
|
||||
var client = CreateClient();
|
||||
client.BaseAddress = new(client.BaseAddress!, "/workflows/");
|
||||
client.Timeout = TimeSpan.FromMinutes(1);
|
||||
return client;
|
||||
}
|
||||
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
var dbConnectionString = infrastructure.DbContainer.GetConnectionString();
|
||||
var rabbitMqConnectionString = infrastructure.RabbitMqContainer.GetConnectionString();
|
||||
|
||||
builder.UseUrls(url);
|
||||
|
||||
if (Program.ConfigureForTest == null)
|
||||
{
|
||||
Program.ConfigureForTest = elsa =>
|
||||
{
|
||||
elsa.AddWorkflowsFrom<WorkflowServer>();
|
||||
elsa.AddActivitiesFrom<WorkflowServer>();
|
||||
elsa.UseDefaultAuthentication(defaultAuthentication => defaultAuthentication.UseAdminApiKey());
|
||||
elsa.UseFluentStorageProvider(sp =>
|
||||
{
|
||||
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
|
||||
var assemblyDirectory = Path.GetDirectoryName(assemblyLocation)!;
|
||||
var workflowsDirectorySegments = new[]
|
||||
{
|
||||
assemblyDirectory, "Scenarios"
|
||||
};
|
||||
var workflowsDirectory = Path.Join(workflowsDirectorySegments);
|
||||
return StorageFactory.Blobs.DirectoryFiles(workflowsDirectory);
|
||||
});
|
||||
elsa.UseMassTransit(massTransit =>
|
||||
{
|
||||
//massTransit.UseRabbitMq(rabbitMqConnectionString);
|
||||
massTransit.Services.AddSingleton<WorkflowDefinitionEvents>();
|
||||
massTransit.AddConsumer<WorkflowDefinitionEventConsumer>("elsa-test-workflow-definition-updates", true);
|
||||
});
|
||||
elsa.UseIdentity(identity => identity.UseEntityFrameworkCore(ef => ef.UsePostgreSql(dbConnectionString)));
|
||||
elsa.UseWorkflowManagement(management =>
|
||||
{
|
||||
management.UseEntityFrameworkCore(ef => ef.UsePostgreSql(dbConnectionString));
|
||||
management.UseMassTransitDispatcher();
|
||||
management.UseCache();
|
||||
});
|
||||
elsa.UseWorkflowRuntime(runtime =>
|
||||
{
|
||||
runtime.UseEntityFrameworkCore(ef => ef.UsePostgreSql(dbConnectionString));
|
||||
runtime.UseCache();
|
||||
runtime.UseMassTransitDispatcher();
|
||||
runtime.UseDistributedRuntime();
|
||||
});
|
||||
elsa.UseDistributedCache(distributedCaching =>
|
||||
{
|
||||
distributedCaching.UseMassTransit();
|
||||
});
|
||||
elsa.UseJavaScript(options =>
|
||||
{
|
||||
options.AllowClrAccess = true;
|
||||
options.ConfigureEngine(engine =>
|
||||
{
|
||||
engine.SetValue("getStaticValue", () => StaticValueHolder.Value);
|
||||
});
|
||||
});
|
||||
elsa.UseAlterations(alterations =>
|
||||
{
|
||||
alterations.UseEntityFrameworkCore(ef => ef.UsePostgreSql(dbConnectionString));
|
||||
});
|
||||
elsa.UseHttp(http =>
|
||||
{
|
||||
http.UseCache();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
builder.ConfigureTestServices(services =>
|
||||
{
|
||||
services
|
||||
.AddSingleton<SignalManager>()
|
||||
.AddScoped<WorkflowEvents>()
|
||||
.AddScoped<WorkflowDefinitionEvents>()
|
||||
.AddSingleton<TriggerChangeTokenSignalEvents>()
|
||||
.AddScoped<IWorkflowMaterializer, TestWorkflowMaterializer>()
|
||||
.AddNotificationHandlersFrom<WorkflowServer>()
|
||||
.AddWorkflowDefinitionProvider<TestWorkflowProvider>()
|
||||
.AddNotificationHandlersFrom<WorkflowEventHandlers>()
|
||||
.Decorate<IChangeTokenSignaler, EventPublishingChangeTokenSignaler>()
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
protected override void ConfigureClient(HttpClient client)
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new("ApiKey", AdminApiKeyProvider.DefaultApiKey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user