* 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>
108 lines
3.2 KiB
C#
108 lines
3.2 KiB
C#
using Elsa.Expressions.Models;
|
|
using Elsa.Extensions;
|
|
using Elsa.Workflows.Memory;
|
|
|
|
namespace Elsa.Workflows.Core.UnitTests;
|
|
|
|
public class ExpressionExecutionContextExtensionsTests
|
|
{
|
|
[Fact]
|
|
public void GetVariable_ReturnsVariable_WhenVariableExists()
|
|
{
|
|
// Arrange
|
|
var variable = new Variable("test", 5);
|
|
var memoryRegister = new MemoryRegister(new Dictionary<string, MemoryBlock>
|
|
{
|
|
{ variable.Id, new MemoryBlock(variable.Value, new VariableBlockMetadata(variable, typeof(object), true)) }
|
|
});
|
|
|
|
var context = new ExpressionExecutionContext(null!, memoryRegister);
|
|
|
|
// Act
|
|
var result = context.GetVariable<int>("test");
|
|
|
|
// Assert
|
|
Assert.Equal(5, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetVariable_ReturnsNull_WhenVariableDoesNotExist()
|
|
{
|
|
// Arrange
|
|
var memoryRegister = new MemoryRegister(new Dictionary<string, MemoryBlock>());
|
|
var context = new ExpressionExecutionContext(null!, memoryRegister);
|
|
|
|
// Act
|
|
var result = context.GetVariable<string>("nonexistent");
|
|
|
|
// Assert
|
|
Assert.Null(result);
|
|
}
|
|
|
|
[Fact]
|
|
public void CreateVariable_ThrowsException_WhenVariableExists()
|
|
{
|
|
// Arrange
|
|
var variable = new Variable("test", 5);
|
|
var memoryRegister = new MemoryRegister(new Dictionary<string, MemoryBlock>
|
|
{
|
|
{ variable.Id, new MemoryBlock(variable.Value, new VariableBlockMetadata(variable, typeof(object), true)) }
|
|
});
|
|
|
|
var context = new ExpressionExecutionContext(null!, memoryRegister);
|
|
|
|
// Act & Assert
|
|
Assert.Throws<Exception>(() => context.CreateVariable("test", 10));
|
|
}
|
|
|
|
[Fact]
|
|
public void CreateVariable_CreatesVariable_WhenVariableDoesNotExist()
|
|
{
|
|
// Arrange
|
|
var memoryRegister = new MemoryRegister(new Dictionary<string, MemoryBlock>());
|
|
var context = new ExpressionExecutionContext(null!, memoryRegister);
|
|
|
|
// Act
|
|
context.CreateVariable("newVariable", 10);
|
|
|
|
// Assert
|
|
var variable = context.GetVariable<int>("newVariable");
|
|
Assert.Equal(10, variable);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetVariable_CreatesVariable_WhenVariableDoesNotExist()
|
|
{
|
|
// Arrange
|
|
var memoryRegister = new MemoryRegister(new Dictionary<string, MemoryBlock>());
|
|
var context = new ExpressionExecutionContext(null!, memoryRegister);
|
|
|
|
// Act
|
|
context.CreateVariable("newVariable", 10);
|
|
|
|
// Assert
|
|
var variable = context.GetVariable<int>("newVariable");
|
|
Assert.Equal(10, variable);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetVariable_SetsValue_WhenVariableExists()
|
|
{
|
|
// Arrange
|
|
var variable = new Variable("test", 5);
|
|
var memoryRegister = new MemoryRegister(new Dictionary<string, MemoryBlock>
|
|
{
|
|
{ variable.Id, new MemoryBlock(variable.Value, new VariableBlockMetadata(variable, typeof(object), true)) }
|
|
});
|
|
|
|
var context = new ExpressionExecutionContext(null!, memoryRegister);
|
|
|
|
// Act
|
|
context.SetVariable("test", 10);
|
|
|
|
// Assert
|
|
var updatedVariable = context.GetVariable<int>("test");
|
|
Assert.Equal(10, updatedVariable);
|
|
}
|
|
}
|