2022-04-12 13:55:35 +00:00
|
|
|
using Elsa.Extensions;
|
2023-03-24 21:25:48 +00:00
|
|
|
using Elsa.Features.Services;
|
Add a more generic UIHandler to customize how inputAttributes can be handle by UI (#4688)
* add a more generic UIHandler to customize how inputAttributes can be handle by the ui
* Add IPropertyUIHandlerResolver and update PropertyUIHandlerResolver
Introduced a new interface, IPropertyUIHandlerResolver, to resolve UI options for a property. Refactored PropertyUIHandlerResolver to implement this interface and removed the unnecessary partial class structure. Also, cleaned up some unnecessary usings in various files for better code organization.
* Refactor variable name and description in InputDescriptor
The 'uISpecifications' variable in the InputDescriptor model is renamed to 'uiSpecifications' for better readability. Additionally, the associated comment was revised to explain that the dictionary is used by the UI.
* "Refactor codebase for improved organization and cleaner architecture"
The codebase has been significantly refactored, moving several classes to more appropriate namespaces for improved organization and cleaner architecture. This includes shifting UI hint handlers, activities, and memory-related components, amongst others. The changes should improve code readability and maintainability, but as this is a broad refactoring effort, thorough regression testing is advised.
* Add CheckList UIHint with associated handler and provider
This update introduces a new UIHint called CheckList to the Elsa.Workflows.Core. This includes the necessary handler and provider classes. The handler is registered in the WorkflowsFeature.cs, and the CheckList UIHint key has been added to the InputUIHints.cs. Various associated files have been created in both the Elsa.Api.Client and Elsa.Workflows.Core project to support this new UIHint.
---------
Co-authored-by: Jérémie DEVILLARD <jdevillard@users.noreply.github.com>
Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2023-12-26 17:56:29 +00:00
|
|
|
using Elsa.Workflows.Activities;
|
|
|
|
|
using Elsa.Workflows.Contracts;
|
|
|
|
|
using Elsa.Workflows.Services;
|
2023-09-14 14:30:18 +00:00
|
|
|
using FluentStorage;
|
2023-04-13 20:23:07 +00:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2022-04-12 13:55:35 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Testing.Shared;
|
|
|
|
|
|
2023-04-17 13:58:07 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// A builder that can be used to configure an <see cref="IServiceProvider"/> for testing purposes.
|
|
|
|
|
/// </summary>
|
2022-04-18 13:48:21 +00:00
|
|
|
public class TestApplicationBuilder
|
2022-04-12 13:55:35 +00:00
|
|
|
{
|
2022-04-12 15:08:31 +00:00
|
|
|
private readonly ITestOutputHelper _testOutputHelper;
|
|
|
|
|
private readonly ServiceCollection _services;
|
2023-03-24 21:25:48 +00:00
|
|
|
private Action<IModule> _configureElsa;
|
2022-04-12 15:08:31 +00:00
|
|
|
|
2023-04-17 13:58:07 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="TestApplicationBuilder"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="testOutputHelper">The test output helper.</param>
|
2022-04-18 13:48:21 +00:00
|
|
|
public TestApplicationBuilder(ITestOutputHelper testOutputHelper)
|
2022-04-12 13:55:35 +00:00
|
|
|
{
|
2022-04-12 15:08:31 +00:00
|
|
|
_testOutputHelper = testOutputHelper;
|
|
|
|
|
_services = new ServiceCollection();
|
2022-04-12 13:55:35 +00:00
|
|
|
|
2022-04-12 15:08:31 +00:00
|
|
|
_services
|
|
|
|
|
.AddSingleton(testOutputHelper)
|
2023-04-13 20:23:07 +00:00
|
|
|
.AddSingleton<IConfiguration, ConfigurationManager>()
|
2022-04-12 13:55:35 +00:00
|
|
|
.AddLogging(logging => logging.AddProvider(new XunitLoggerProvider(testOutputHelper)).SetMinimumLevel(LogLevel.Debug));
|
2023-09-14 14:30:18 +00:00
|
|
|
|
2023-03-24 21:25:48 +00:00
|
|
|
_configureElsa += elsa => elsa
|
2023-04-18 19:28:23 +00:00
|
|
|
.AddActivitiesFrom<WriteLine>()
|
|
|
|
|
.UseScheduling()
|
2023-11-09 12:35:02 +00:00
|
|
|
.UseCSharp()
|
2023-04-18 19:28:23 +00:00
|
|
|
.UseJavaScript()
|
|
|
|
|
.UseLiquid()
|
2023-05-28 09:54:12 +00:00
|
|
|
.UseDsl()
|
2023-07-14 17:19:41 +00:00
|
|
|
.UseWorkflowManagement()
|
2023-03-24 21:25:48 +00:00
|
|
|
.UseWorkflows(workflows => workflows
|
|
|
|
|
.WithStandardOutStreamProvider(_ => new StandardOutStreamProvider(new XunitConsoleTextWriter(_testOutputHelper)))
|
|
|
|
|
);
|
2022-04-12 15:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-17 13:58:07 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Builds the <see cref="IServiceProvider"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The <see cref="IServiceProvider"/>.</returns>
|
2023-03-24 21:25:48 +00:00
|
|
|
public IServiceProvider Build()
|
|
|
|
|
{
|
|
|
|
|
_services.AddElsa(_configureElsa);
|
|
|
|
|
return _services.BuildServiceProvider();
|
|
|
|
|
}
|
2022-04-12 13:55:35 +00:00
|
|
|
|
2023-04-17 13:58:07 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Configures Elsa.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="configure">The configuration delegate.</param>
|
|
|
|
|
/// <returns>The <see cref="TestApplicationBuilder"/>.</returns>
|
2023-03-24 21:25:48 +00:00
|
|
|
public TestApplicationBuilder ConfigureElsa(Action<IModule> configure)
|
|
|
|
|
{
|
|
|
|
|
_configureElsa += configure;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2023-09-14 14:30:18 +00:00
|
|
|
|
2023-04-17 13:58:07 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Configures the service provider.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="configure">The configuration delegate.</param>
|
|
|
|
|
/// <returns>The <see cref="TestApplicationBuilder"/>.</returns>
|
2023-03-24 21:25:48 +00:00
|
|
|
public TestApplicationBuilder ConfigureServices(Action<IServiceCollection> configure)
|
2022-04-12 15:08:31 +00:00
|
|
|
{
|
|
|
|
|
configure(_services);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2022-04-12 13:55:35 +00:00
|
|
|
|
2023-04-17 13:58:07 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Configures the service provider to use a <see cref="CapturingTextWriter"/> to capture standard output.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="capturingTextWriter">The capturing text writer.</param>
|
|
|
|
|
/// <returns>The <see cref="TestApplicationBuilder"/>.</returns>
|
2022-04-18 13:48:21 +00:00
|
|
|
public TestApplicationBuilder WithCapturingTextWriter(CapturingTextWriter capturingTextWriter)
|
2022-04-12 15:08:31 +00:00
|
|
|
{
|
|
|
|
|
var combinedTextWriter = new CombinedTextWriter(capturingTextWriter, new XunitConsoleTextWriter(_testOutputHelper));
|
2023-03-24 21:25:48 +00:00
|
|
|
var provider = new StandardOutStreamProvider(combinedTextWriter);
|
|
|
|
|
|
|
|
|
|
ConfigureElsa(elsa => elsa.UseWorkflows(workflows => workflows.WithStandardOutStreamProvider(_ => provider)));
|
2022-04-12 15:08:31 +00:00
|
|
|
return this;
|
2022-04-12 13:55:35 +00:00
|
|
|
}
|
2023-09-14 08:50:02 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds a workflow to the service provider.
|
|
|
|
|
/// </summary>
|
2023-09-14 14:30:18 +00:00
|
|
|
public TestApplicationBuilder AddWorkflow<T>() where T : IWorkflow
|
2023-09-14 08:50:02 +00:00
|
|
|
{
|
|
|
|
|
return ConfigureElsa(elsa => elsa.AddWorkflow<T>());
|
|
|
|
|
}
|
2023-09-14 14:30:18 +00:00
|
|
|
|
2023-09-22 16:45:18 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Adds activities from the assembly containing the specified type.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public TestApplicationBuilder AddActivitiesFrom<T>()
|
|
|
|
|
{
|
|
|
|
|
return ConfigureElsa(elsa => elsa.AddActivitiesFrom<T>());
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-14 14:30:18 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Add workflows from the specified relative directory.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="directory">The path segments of the directory.</param>
|
|
|
|
|
public TestApplicationBuilder WithWorkflowsFromDirectory(params string[] directory)
|
|
|
|
|
{
|
|
|
|
|
var assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
|
|
|
|
var assemblyDirectory = Path.GetDirectoryName(assemblyLocation)!;
|
|
|
|
|
var workflowsDirectory = directory.Prepend(assemblyDirectory).ToArray();
|
|
|
|
|
_configureElsa += elsa => elsa.UseFluentStorageProvider(storage => storage.BlobStorage = sp => StorageFactory.Blobs.DirectoryFiles(Path.Combine(workflowsDirectory)));
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2022-04-12 13:55:35 +00:00
|
|
|
}
|