* Seperate YesSql and added InMemory, MongoDb * Error fixed, if DatabaseInitializer is run through several times * icon.png was not packed * Added AddWorkflowProvider to AddElsaPersistenceMongoDb * Wrong primary keys were used for MongoDb * Refactorig MongoDb * Register IMongoCollection<WorkflowDefinition> and IMongoCollection<WorkflowInstance> with DI * Wrong Parameter Type in Constructor (MongoDbWorkflowInstanceRepository) * Add workflowDefinition.WorkflowDefinitionId = _idGenerator.Generate(); to Initialize * Removed duplicated code * Correct wrong Commit Co-authored-by: Rafael Carnucci <rafael.carnucci@icn.de> Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
60 lines
2.5 KiB
C#
60 lines
2.5 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Elsa.Builders;
|
|
using Elsa.Persistence.InMemory;
|
|
using Elsa.Services;
|
|
using Elsa.Testing.Shared.Helpers;
|
|
using Elsa.Triggers;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Elsa.Testing.Shared.Unit
|
|
{
|
|
public abstract class WorkflowsUnitTestBase : IAsyncLifetime, IDisposable
|
|
{
|
|
private readonly TemporaryFolder _tempFolder;
|
|
|
|
protected WorkflowsUnitTestBase(ITestOutputHelper testOutputHelper, Action<IServiceCollection>? configureServices = default)
|
|
{
|
|
_tempFolder = new TemporaryFolder();
|
|
TestOutputHelper = testOutputHelper;
|
|
|
|
var services = new ServiceCollection()
|
|
.AddElsa()
|
|
.AddElsaPersistenceInMemory()
|
|
.AddConsoleActivities(Console.In, new XunitConsoleForwarder(testOutputHelper));
|
|
|
|
configureServices?.Invoke(services);
|
|
ServiceProvider = services.BuildServiceProvider();
|
|
ServiceScope = ServiceProvider.CreateScope();
|
|
WorkflowRunner = ServiceScope.ServiceProvider.GetRequiredService<IWorkflowRunner>();
|
|
WorkflowBlueprintMaterializer = ServiceScope.ServiceProvider.GetRequiredService<IWorkflowBlueprintMaterializer>();
|
|
WorkflowBuilder = ServiceScope.ServiceProvider.GetRequiredService<IWorkflowBuilder>();
|
|
WorkflowRegistry = ServiceScope.ServiceProvider.GetRequiredService<IWorkflowRegistry>();
|
|
WorkflowSelector = ServiceScope.ServiceProvider.GetRequiredService<IWorkflowSelector>();
|
|
}
|
|
|
|
protected ITestOutputHelper TestOutputHelper { get; }
|
|
protected ServiceProvider ServiceProvider { get; }
|
|
protected IServiceScope ServiceScope { get; }
|
|
protected IWorkflowRunner WorkflowRunner { get; }
|
|
protected IWorkflowBlueprintMaterializer WorkflowBlueprintMaterializer { get; }
|
|
protected IWorkflowBuilder WorkflowBuilder { get; }
|
|
protected IWorkflowRegistry WorkflowRegistry { get; }
|
|
protected IWorkflowSelector WorkflowSelector { get; }
|
|
public virtual void Dispose() => _tempFolder.Dispose();
|
|
|
|
public virtual async Task InitializeAsync()
|
|
{
|
|
var startupRunner = ServiceProvider.GetRequiredService<IStartupRunner>();
|
|
await startupRunner.StartupAsync();
|
|
}
|
|
|
|
public virtual async Task DisposeAsync()
|
|
{
|
|
await ServiceProvider.DisposeAsync();
|
|
Dispose();
|
|
}
|
|
}
|
|
} |