elsa-core/test/unit/Elsa.Activities.UnitTests/Flow/FlowchartTestHelpers.cs

28 lines
837 B
C#
Raw Permalink Normal View History

Adds SetVariable activity unit tests (#6989) * Update doc/qa/test-guidelines.md Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com> * Improvements on maintainability of sendhttprequest unit tests * Improving tests and scheduled activity evaluation for activity context * Refactor and splitting unnecessary grouped tests * Improvements on SendHttp Unit tests * Improvements on tests * Update test/unit/Elsa.Activities.UnitTests/HTTP/SendHttpRequestTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Small suggestions from copilot * Update test/unit/Elsa.Activities.UnitTests/HTTP/SendHttpRequestTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * small copilot suggestion * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts - Added `IWorkflowExecutionContextSchedulerStrategy` and `IActivityExecutionContextSchedulerStrategy` interfaces. - Implemented `WorkflowExecutionContextSchedulerStrategy` and `ActivityExecutionContextSchedulerStrategy` for scheduling activities in workflows. - Refactored scheduling logic to utilize the new scheduler strategies. - Updated unit tests and test helpers to reflect refactoring, introducing fake implementations for testing purposes. - Adjusted background execution scheduling and improved extensibility for custom scheduler strategies. * Refactor `SendHttpRequestTests`: simplify scheduling assertions, use shared extensions, and standardize method naming. Streamline helper methods and remove unused test logic. * Refactor: Replace `ActivityTestHelper` with `ActivityTestFixture` in unit tests for streamlined activity testing - Introduced `ActivityTestFixture` with a fluent API for better test setup and execution of activities. - Added extension methods `ActivityTestFixtureExtensions` and `ActivityTestFixtureHttpExtensions` for configuring attributes and HTTP services. - Updated test guidelines and unit tests to use the new fixture and extensions. - Removed `ActivityTestHelper`. * Refactor: Move `ActivityTestFixture` and related extensions to shared project for reuse across test suites - Consolidated `ActivityTestFixture`, `ActivityTestFixtureExtensions`, and `ActivityTestFixtureHttpExtensions` into `Elsa.Testing.Shared`. - Updated namespaces and imports across unit tests to reflect new structure. - Enhanced `AssertActivityAttributes` and added fluent configuration APIs. - Adjusted `Directory.Packages.props` with new dependencies, including `NSubstitute` and `xunit.assert`. * Refactor `SetVariableTests`: inline `ActivityTestFixture` initialization to simplify test setup. * Refactor `ActivityTestFixture`: eliminate redundant field `_services`, add `UsedImplicitly` attributes, and improve service collection management * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for `ActivityExecutionContextExtensions`, detailing methods and parameters. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for scheduler strategies and their methods - Updated `IActivityExecutionContextSchedulerStrategy` and `IWorkflowExecutionContextSchedulerStrategy` interfaces with XML summaries for methods. - Added XML documentation to implementations (`ActivityExecutionContextSchedulerStrategy`, `WorkflowExecutionContextSchedulerStrategy`) and test fakes for clarity. * Refactor `WriteLineTests`: consolidate duplicate test logic, simplify setup with shared helper method, and enhance readability in assertions. * Refactor `WriteLineTests` and `SetVariableTests`: replace `WriteLineAsync` assertions with synchronous `WriteLine`, streamline exception recording in `SetVariableTests`, and remove unused imports. * Add integration and unit tests for `SetVariable` activity: ensure variable scoping, null handling, and value setting are covered. * Add new `SetVariableOfTTests` and update `SetVariableTests` for improved test coverage and type handling. * Add new unit and integration tests for activity input and expression evaluation - Introduced comprehensive test suites covering activity input evaluation, expression handling, and fault scenarios. - Added unit tests for `ExpressionDescriptorRegistry`, `ExpressionEvaluator`, and activity execution context extensions. - Added integration tests: `CustomInputEvaluatorTests`, `InputEvaluationErrorTests`, and `InputPropertyEvaluationTests`. - Enhanced code coverage for edge cases and async evaluation logic. * Remove unused `RunWorkflowAsync` extension method from `RunActivityExtensions`. * Rename `CustomInputEvaluatorTests` to `InputEvaluationTests` for consistency with naming conventions. * Remove unused `Elsa.Workflows.Activities` import from `RunActivityExtensions`. * Remove redundant comments from `InputEvaluationErrorTests` for clarity. * Refactor unit tests to streamline activity and expression evaluations - Refactored `ExecuteActivityAsync` and `ExecuteWriteLineAsync` into shared helpers for consistency and reuse across tests. - Replaced redundant mock setups with helper methods in `ExpressionDescriptorRegistryTests`. - Simplified test setup for expression and activity evaluation by removing unused imports and consolidating configuration logic. - Enhanced readability by reducing duplicate code and leveraging shared utility methods. * Refactor activity input evaluation tests - Extracted `CreateContextAsync` helper into `EvaluationTestHelpers` for reuse across evaluation test suites. - Replaced inline activity context setup with shared helper in `InputPropertyEvaluationTests`, `WrappedInputEvaluationTests`, and related test suites. - Simplified test method names for clarity and consistency. - Updated test annotations to enhance readability and align with naming conventions. * Remove redundant test cases and unused imports - Deleted duplicated and non-essential test cases across evaluation test suites. - Removed unused imports to improve code cleanliness and readability. - Streamlined variable initializations and method calls within test setups. * Remove redundant test case from `InputEvaluationErrorTests` - Deleted the `ContinuesEvaluationForMultipleInputs` test, as it overlaps with existing tests and does not provide additional coverage. * Remove redundant assertion from `InputPropertyEvaluationTests` - Deleted `Assert.True(context.GetHasEvaluatedProperties())`, as it is unnecessary for verifying test outcomes. * Remove redundant test cases from `WrappedInputEvaluationTests` - Deleted `UsesDefaultValueWhenInputIsNull` and `EvaluatesExpression` tests as they are either duplicated or unnecessary for current test coverage. * Add unit test projects for `Elsa.Workflows.Management` and `Elsa.Expressions` - Introduced new test projects to separate and organize unit tests for `Elsa.Workflows.Management` and `Elsa.Expressions`. - Updated `Elsa.sln` to include references to the newly added test projects. - Adjusted namespaces in affected test classes for consistency with the updated project structure. * Refactor `ExpressionEvaluatorTests` for clarity and consistency - Simplified test method names and annotations for improved readability. - Replaced duplicate mock setups with helper functions (`CreateContextAsync`, `CreateContextWithMockHandlerAsync`, and related methods). - Streamlined test setups by removing redundant code and consolidating context creation logic. - Updated test annotations to include descriptive `DisplayName` attributes. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove redundant comment from `ExpressionEvaluatorTests` for clarity * Remove redundant blank lines from unit test classes - Eliminated unnecessary blank lines across `ActivityExecutionContextExtensions` test suites to improve code readability and consistency. * Add unit tests for Flowchart activity - Introduced `FlowchartTests` to verify common Flowchart behavior, including start activity scheduling, execution without a start activity, and `UseTokenFlow` handling. - Added `FlowchartTestHelpers` to encapsulate shared test logic. - Updated project file to include the new `Flow` folder for organization. * Add integration tests for Flowchart activity execution strategies - Introduced `FlowchartCounterBasedTests` and `FlowchartTokenBasedTests` to verify different Flowchart execution strategies. - Added `FlowchartTestHelpers` for shared test logic, including helper methods for creating various flowchart configurations and connections. - Enhanced test coverage with scenarios for linear, parallel, and conditional flows, mixed merge modes, nested flowcharts, and token handling. - Updated project structure to include new test classes under the `Flow` folder. * Remove obsolete tag from `FlowJoin` activity description * Handle both string and enum values in `GetMergeMode` for backwards compatibility * Group flowchart integration tests into non-parallelizable test collection - Introduced `FlowchartTestCollection` to prevent parallel execution of flowchart tests due to shared `Flowchart.UseTokenFlow` flag. - Updated `FlowchartCounterBasedTests` and `FlowchartTokenBasedTests` to implement `IDisposable` and manage `UseTokenFlow` cleanup. * Remove unused `Flow` folder reference from test project file * Add `ParallelTests` for unit and integration testing with various scenarios (#6988) - Added unit tests for `Parallel` activity to ensure proper scheduling of child activities, including empty and mixed activity cases. - Added integration tests to validate execution flow and edge cases for `Parallel` activities (e.g., nested parallelism, fault handling). - Enhanced `ScheduleChildrenAsync` in `Parallel` to handle no activity scenario by completing immediately. * Fix null-check and memory declaration in `ActivityTestFixture` to prevent potential `NullReferenceException`. * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts (#6984) * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts - Added `IWorkflowExecutionContextSchedulerStrategy` and `IActivityExecutionContextSchedulerStrategy` interfaces. - Implemented `WorkflowExecutionContextSchedulerStrategy` and `ActivityExecutionContextSchedulerStrategy` for scheduling activities in workflows. - Refactored scheduling logic to utilize the new scheduler strategies. - Updated unit tests and test helpers to reflect refactoring, introducing fake implementations for testing purposes. - Adjusted background execution scheduling and improved extensibility for custom scheduler strategies. * Refactor `SendHttpRequestTests`: simplify scheduling assertions, use shared extensions, and standardize method naming. Streamline helper methods and remove unused test logic. * Refactor: Replace `ActivityTestHelper` with `ActivityTestFixture` in unit tests for streamlined activity testing - Introduced `ActivityTestFixture` with a fluent API for better test setup and execution of activities. - Added extension methods `ActivityTestFixtureExtensions` and `ActivityTestFixtureHttpExtensions` for configuring attributes and HTTP services. - Updated test guidelines and unit tests to use the new fixture and extensions. - Removed `ActivityTestHelper`. * Refactor: Move `ActivityTestFixture` and related extensions to shared project for reuse across test suites - Consolidated `ActivityTestFixture`, `ActivityTestFixtureExtensions`, and `ActivityTestFixtureHttpExtensions` into `Elsa.Testing.Shared`. - Updated namespaces and imports across unit tests to reflect new structure. - Enhanced `AssertActivityAttributes` and added fluent configuration APIs. - Adjusted `Directory.Packages.props` with new dependencies, including `NSubstitute` and `xunit.assert`. * Refactor `SetVariableTests`: inline `ActivityTestFixture` initialization to simplify test setup. * Refactor `ActivityTestFixture`: eliminate redundant field `_services`, add `UsedImplicitly` attributes, and improve service collection management * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for `ActivityExecutionContextExtensions`, detailing methods and parameters. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for scheduler strategies and their methods - Updated `IActivityExecutionContextSchedulerStrategy` and `IWorkflowExecutionContextSchedulerStrategy` interfaces with XML summaries for methods. - Added XML documentation to implementations (`ActivityExecutionContextSchedulerStrategy`, `WorkflowExecutionContextSchedulerStrategy`) and test fakes for clarity. * Refactor `WriteLineTests`: consolidate duplicate test logic, simplify setup with shared helper method, and enhance readability in assertions. * Refactor `WriteLineTests` and `SetVariableTests`: replace `WriteLineAsync` assertions with synchronous `WriteLine`, streamline exception recording in `SetVariableTests`, and remove unused imports. * Add `ParallelTests` for unit and integration testing with various scenarios (#6988) - Added unit tests for `Parallel` activity to ensure proper scheduling of child activities, including empty and mixed activity cases. - Added integration tests to validate execution flow and edge cases for `Parallel` activities (e.g., nested parallelism, fault handling). - Enhanced `ScheduleChildrenAsync` in `Parallel` to handle no activity scenario by completing immediately. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add new unit and integration tests for activity input and expression evaluation (#6990) * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts - Added `IWorkflowExecutionContextSchedulerStrategy` and `IActivityExecutionContextSchedulerStrategy` interfaces. - Implemented `WorkflowExecutionContextSchedulerStrategy` and `ActivityExecutionContextSchedulerStrategy` for scheduling activities in workflows. - Refactored scheduling logic to utilize the new scheduler strategies. - Updated unit tests and test helpers to reflect refactoring, introducing fake implementations for testing purposes. - Adjusted background execution scheduling and improved extensibility for custom scheduler strategies. * Refactor `SendHttpRequestTests`: simplify scheduling assertions, use shared extensions, and standardize method naming. Streamline helper methods and remove unused test logic. * Refactor: Replace `ActivityTestHelper` with `ActivityTestFixture` in unit tests for streamlined activity testing - Introduced `ActivityTestFixture` with a fluent API for better test setup and execution of activities. - Added extension methods `ActivityTestFixtureExtensions` and `ActivityTestFixtureHttpExtensions` for configuring attributes and HTTP services. - Updated test guidelines and unit tests to use the new fixture and extensions. - Removed `ActivityTestHelper`. * Refactor: Move `ActivityTestFixture` and related extensions to shared project for reuse across test suites - Consolidated `ActivityTestFixture`, `ActivityTestFixtureExtensions`, and `ActivityTestFixtureHttpExtensions` into `Elsa.Testing.Shared`. - Updated namespaces and imports across unit tests to reflect new structure. - Enhanced `AssertActivityAttributes` and added fluent configuration APIs. - Adjusted `Directory.Packages.props` with new dependencies, including `NSubstitute` and `xunit.assert`. * Refactor `SetVariableTests`: inline `ActivityTestFixture` initialization to simplify test setup. * Refactor `ActivityTestFixture`: eliminate redundant field `_services`, add `UsedImplicitly` attributes, and improve service collection management * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for `ActivityExecutionContextExtensions`, detailing methods and parameters. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for scheduler strategies and their methods - Updated `IActivityExecutionContextSchedulerStrategy` and `IWorkflowExecutionContextSchedulerStrategy` interfaces with XML summaries for methods. - Added XML documentation to implementations (`ActivityExecutionContextSchedulerStrategy`, `WorkflowExecutionContextSchedulerStrategy`) and test fakes for clarity. * Refactor `WriteLineTests`: consolidate duplicate test logic, simplify setup with shared helper method, and enhance readability in assertions. * Refactor `WriteLineTests` and `SetVariableTests`: replace `WriteLineAsync` assertions with synchronous `WriteLine`, streamline exception recording in `SetVariableTests`, and remove unused imports. * Add new unit and integration tests for activity input and expression evaluation - Introduced comprehensive test suites covering activity input evaluation, expression handling, and fault scenarios. - Added unit tests for `ExpressionDescriptorRegistry`, `ExpressionEvaluator`, and activity execution context extensions. - Added integration tests: `CustomInputEvaluatorTests`, `InputEvaluationErrorTests`, and `InputPropertyEvaluationTests`. - Enhanced code coverage for edge cases and async evaluation logic. * Remove unused `RunWorkflowAsync` extension method from `RunActivityExtensions`. * Rename `CustomInputEvaluatorTests` to `InputEvaluationTests` for consistency with naming conventions. * Remove unused `Elsa.Workflows.Activities` import from `RunActivityExtensions`. * Remove redundant comments from `InputEvaluationErrorTests` for clarity. * Refactor unit tests to streamline activity and expression evaluations - Refactored `ExecuteActivityAsync` and `ExecuteWriteLineAsync` into shared helpers for consistency and reuse across tests. - Replaced redundant mock setups with helper methods in `ExpressionDescriptorRegistryTests`. - Simplified test setup for expression and activity evaluation by removing unused imports and consolidating configuration logic. - Enhanced readability by reducing duplicate code and leveraging shared utility methods. * Refactor activity input evaluation tests - Extracted `CreateContextAsync` helper into `EvaluationTestHelpers` for reuse across evaluation test suites. - Replaced inline activity context setup with shared helper in `InputPropertyEvaluationTests`, `WrappedInputEvaluationTests`, and related test suites. - Simplified test method names for clarity and consistency. - Updated test annotations to enhance readability and align with naming conventions. * Remove redundant test cases and unused imports - Deleted duplicated and non-essential test cases across evaluation test suites. - Removed unused imports to improve code cleanliness and readability. - Streamlined variable initializations and method calls within test setups. * Remove redundant test case from `InputEvaluationErrorTests` - Deleted the `ContinuesEvaluationForMultipleInputs` test, as it overlaps with existing tests and does not provide additional coverage. * Remove redundant assertion from `InputPropertyEvaluationTests` - Deleted `Assert.True(context.GetHasEvaluatedProperties())`, as it is unnecessary for verifying test outcomes. * Remove redundant test cases from `WrappedInputEvaluationTests` - Deleted `UsesDefaultValueWhenInputIsNull` and `EvaluatesExpression` tests as they are either duplicated or unnecessary for current test coverage. * Add unit test projects for `Elsa.Workflows.Management` and `Elsa.Expressions` - Introduced new test projects to separate and organize unit tests for `Elsa.Workflows.Management` and `Elsa.Expressions`. - Updated `Elsa.sln` to include references to the newly added test projects. - Adjusted namespaces in affected test classes for consistency with the updated project structure. * Refactor `ExpressionEvaluatorTests` for clarity and consistency - Simplified test method names and annotations for improved readability. - Replaced duplicate mock setups with helper functions (`CreateContextAsync`, `CreateContextWithMockHandlerAsync`, and related methods). - Streamlined test setups by removing redundant code and consolidating context creation logic. - Updated test annotations to include descriptive `DisplayName` attributes. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove redundant comment from `ExpressionEvaluatorTests` for clarity * Remove redundant blank lines from unit test classes - Eliminated unnecessary blank lines across `ActivityExecutionContextExtensions` test suites to improve code readability and consistency. * Update src/modules/Elsa.Expressions/Services/ExpressionEvaluator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Expand `test-guidelines.md` with testing best practices, helper references, and example snippets - Added detailed guidance on test project organization, updated helper documentation, and streamlined example code for activity unit testing. - Introduced scheduler strategy information and integration test patterns for deterministic tests. - Clarified usage of shared infrastructure like `ActivityTestFixture` and `AsyncWorkflowRunner`. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix merge issue * Add missing `using Elsa.Expressions.Models` directive to `SetVariableTests` * Update `SetVariableTests` and `ActivityTestFixture` to fix exception type assertion and improve test utility execution handling. * Update `SetVariableTests` and `ActivityTestFixture` to handle null variables, fix exception type assertion, and simplify context usage. --------- Co-authored-by: lucas.hipolito <lukhipolito@yahoo.com.br> Co-authored-by: lukhipolito-nexxbiz <lucas.hipolito@nexxbiz.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-22 18:54:58 +00:00
using Elsa.Testing.Shared;
using Elsa.Workflows;
using Elsa.Workflows.Activities.Flowchart.Activities;
Configures Flowchart Execution via DI (#7141) * Introduce `FlowchartExecutionMode` to streamline flowchart execution logic. - Added `FlowchartExecutionMode` enum to represent execution modes (Default, TokenBased, CounterBased). - Updated flowchart-related integration and unit tests to use the new execution mode. - Removed the global `UseTokenFlow` flag in favor of execution-specific configuration via `RunWorkflowOptions`. - Refactored flowchart-related APIs and test helpers for improved flexibility and modularity. * Add support for configuring flowchart execution behavior via `FlowchartOptions` and DI. - Introduced extensions for `FlowchartFeature` to simplify configuration. - Added DI support for setting default execution modes. - Refactored flowchart execution logic to prioritize configuration. * Update default Flowchart execution settings to align with version 3.5.2 behavior - Changed `DefaultExecutionMode` to `CounterBased`. - Updated `UseTokenFlow` default to `false`. * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Models/FlowchartExecutionMode.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Extensions/FlowchartFeatureExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update test/integration/Elsa.Workflows.IntegrationTests/Scenarios/FlowchartNextActivity/Tests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Extensions/RunWorkflowOptionsExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor flowchart integration tests for improved formatting and consistency * Refactor workflow tests and related services to improve reusability and align with updated Flowchart execution behavior * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Options/FlowchartOptions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor flowchart execution logic to use `FlowchartExecutionMode` enum, replacing boolean checks for improved clarity and extensibility. * Refactor tests and workflow logic to replace boolean `useTokenFlow` with `FlowchartExecutionMode` enum for clarity and consistency. * Refactor flowchart execution logic to centralize mode-based behavior handling and simplify implementation. * Remove unnecessary whitespace in Flowchart.cs to improve code formatting * Remove unnecessary whitespace in FlowJoinTests.cs to improve code formatting * Update src/common/Elsa.Testing.Shared.Integration/WorkflowTestFixture.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-15 09:15:39 +00:00
using Elsa.Workflows.Activities.Flowchart.Models;
Adds SetVariable activity unit tests (#6989) * Update doc/qa/test-guidelines.md Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com> * Improvements on maintainability of sendhttprequest unit tests * Improving tests and scheduled activity evaluation for activity context * Refactor and splitting unnecessary grouped tests * Improvements on SendHttp Unit tests * Improvements on tests * Update test/unit/Elsa.Activities.UnitTests/HTTP/SendHttpRequestTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Small suggestions from copilot * Update test/unit/Elsa.Activities.UnitTests/HTTP/SendHttpRequestTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * small copilot suggestion * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts - Added `IWorkflowExecutionContextSchedulerStrategy` and `IActivityExecutionContextSchedulerStrategy` interfaces. - Implemented `WorkflowExecutionContextSchedulerStrategy` and `ActivityExecutionContextSchedulerStrategy` for scheduling activities in workflows. - Refactored scheduling logic to utilize the new scheduler strategies. - Updated unit tests and test helpers to reflect refactoring, introducing fake implementations for testing purposes. - Adjusted background execution scheduling and improved extensibility for custom scheduler strategies. * Refactor `SendHttpRequestTests`: simplify scheduling assertions, use shared extensions, and standardize method naming. Streamline helper methods and remove unused test logic. * Refactor: Replace `ActivityTestHelper` with `ActivityTestFixture` in unit tests for streamlined activity testing - Introduced `ActivityTestFixture` with a fluent API for better test setup and execution of activities. - Added extension methods `ActivityTestFixtureExtensions` and `ActivityTestFixtureHttpExtensions` for configuring attributes and HTTP services. - Updated test guidelines and unit tests to use the new fixture and extensions. - Removed `ActivityTestHelper`. * Refactor: Move `ActivityTestFixture` and related extensions to shared project for reuse across test suites - Consolidated `ActivityTestFixture`, `ActivityTestFixtureExtensions`, and `ActivityTestFixtureHttpExtensions` into `Elsa.Testing.Shared`. - Updated namespaces and imports across unit tests to reflect new structure. - Enhanced `AssertActivityAttributes` and added fluent configuration APIs. - Adjusted `Directory.Packages.props` with new dependencies, including `NSubstitute` and `xunit.assert`. * Refactor `SetVariableTests`: inline `ActivityTestFixture` initialization to simplify test setup. * Refactor `ActivityTestFixture`: eliminate redundant field `_services`, add `UsedImplicitly` attributes, and improve service collection management * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for `ActivityExecutionContextExtensions`, detailing methods and parameters. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for scheduler strategies and their methods - Updated `IActivityExecutionContextSchedulerStrategy` and `IWorkflowExecutionContextSchedulerStrategy` interfaces with XML summaries for methods. - Added XML documentation to implementations (`ActivityExecutionContextSchedulerStrategy`, `WorkflowExecutionContextSchedulerStrategy`) and test fakes for clarity. * Refactor `WriteLineTests`: consolidate duplicate test logic, simplify setup with shared helper method, and enhance readability in assertions. * Refactor `WriteLineTests` and `SetVariableTests`: replace `WriteLineAsync` assertions with synchronous `WriteLine`, streamline exception recording in `SetVariableTests`, and remove unused imports. * Add integration and unit tests for `SetVariable` activity: ensure variable scoping, null handling, and value setting are covered. * Add new `SetVariableOfTTests` and update `SetVariableTests` for improved test coverage and type handling. * Add new unit and integration tests for activity input and expression evaluation - Introduced comprehensive test suites covering activity input evaluation, expression handling, and fault scenarios. - Added unit tests for `ExpressionDescriptorRegistry`, `ExpressionEvaluator`, and activity execution context extensions. - Added integration tests: `CustomInputEvaluatorTests`, `InputEvaluationErrorTests`, and `InputPropertyEvaluationTests`. - Enhanced code coverage for edge cases and async evaluation logic. * Remove unused `RunWorkflowAsync` extension method from `RunActivityExtensions`. * Rename `CustomInputEvaluatorTests` to `InputEvaluationTests` for consistency with naming conventions. * Remove unused `Elsa.Workflows.Activities` import from `RunActivityExtensions`. * Remove redundant comments from `InputEvaluationErrorTests` for clarity. * Refactor unit tests to streamline activity and expression evaluations - Refactored `ExecuteActivityAsync` and `ExecuteWriteLineAsync` into shared helpers for consistency and reuse across tests. - Replaced redundant mock setups with helper methods in `ExpressionDescriptorRegistryTests`. - Simplified test setup for expression and activity evaluation by removing unused imports and consolidating configuration logic. - Enhanced readability by reducing duplicate code and leveraging shared utility methods. * Refactor activity input evaluation tests - Extracted `CreateContextAsync` helper into `EvaluationTestHelpers` for reuse across evaluation test suites. - Replaced inline activity context setup with shared helper in `InputPropertyEvaluationTests`, `WrappedInputEvaluationTests`, and related test suites. - Simplified test method names for clarity and consistency. - Updated test annotations to enhance readability and align with naming conventions. * Remove redundant test cases and unused imports - Deleted duplicated and non-essential test cases across evaluation test suites. - Removed unused imports to improve code cleanliness and readability. - Streamlined variable initializations and method calls within test setups. * Remove redundant test case from `InputEvaluationErrorTests` - Deleted the `ContinuesEvaluationForMultipleInputs` test, as it overlaps with existing tests and does not provide additional coverage. * Remove redundant assertion from `InputPropertyEvaluationTests` - Deleted `Assert.True(context.GetHasEvaluatedProperties())`, as it is unnecessary for verifying test outcomes. * Remove redundant test cases from `WrappedInputEvaluationTests` - Deleted `UsesDefaultValueWhenInputIsNull` and `EvaluatesExpression` tests as they are either duplicated or unnecessary for current test coverage. * Add unit test projects for `Elsa.Workflows.Management` and `Elsa.Expressions` - Introduced new test projects to separate and organize unit tests for `Elsa.Workflows.Management` and `Elsa.Expressions`. - Updated `Elsa.sln` to include references to the newly added test projects. - Adjusted namespaces in affected test classes for consistency with the updated project structure. * Refactor `ExpressionEvaluatorTests` for clarity and consistency - Simplified test method names and annotations for improved readability. - Replaced duplicate mock setups with helper functions (`CreateContextAsync`, `CreateContextWithMockHandlerAsync`, and related methods). - Streamlined test setups by removing redundant code and consolidating context creation logic. - Updated test annotations to include descriptive `DisplayName` attributes. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove redundant comment from `ExpressionEvaluatorTests` for clarity * Remove redundant blank lines from unit test classes - Eliminated unnecessary blank lines across `ActivityExecutionContextExtensions` test suites to improve code readability and consistency. * Add unit tests for Flowchart activity - Introduced `FlowchartTests` to verify common Flowchart behavior, including start activity scheduling, execution without a start activity, and `UseTokenFlow` handling. - Added `FlowchartTestHelpers` to encapsulate shared test logic. - Updated project file to include the new `Flow` folder for organization. * Add integration tests for Flowchart activity execution strategies - Introduced `FlowchartCounterBasedTests` and `FlowchartTokenBasedTests` to verify different Flowchart execution strategies. - Added `FlowchartTestHelpers` for shared test logic, including helper methods for creating various flowchart configurations and connections. - Enhanced test coverage with scenarios for linear, parallel, and conditional flows, mixed merge modes, nested flowcharts, and token handling. - Updated project structure to include new test classes under the `Flow` folder. * Remove obsolete tag from `FlowJoin` activity description * Handle both string and enum values in `GetMergeMode` for backwards compatibility * Group flowchart integration tests into non-parallelizable test collection - Introduced `FlowchartTestCollection` to prevent parallel execution of flowchart tests due to shared `Flowchart.UseTokenFlow` flag. - Updated `FlowchartCounterBasedTests` and `FlowchartTokenBasedTests` to implement `IDisposable` and manage `UseTokenFlow` cleanup. * Remove unused `Flow` folder reference from test project file * Add `ParallelTests` for unit and integration testing with various scenarios (#6988) - Added unit tests for `Parallel` activity to ensure proper scheduling of child activities, including empty and mixed activity cases. - Added integration tests to validate execution flow and edge cases for `Parallel` activities (e.g., nested parallelism, fault handling). - Enhanced `ScheduleChildrenAsync` in `Parallel` to handle no activity scenario by completing immediately. * Fix null-check and memory declaration in `ActivityTestFixture` to prevent potential `NullReferenceException`. * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts (#6984) * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts - Added `IWorkflowExecutionContextSchedulerStrategy` and `IActivityExecutionContextSchedulerStrategy` interfaces. - Implemented `WorkflowExecutionContextSchedulerStrategy` and `ActivityExecutionContextSchedulerStrategy` for scheduling activities in workflows. - Refactored scheduling logic to utilize the new scheduler strategies. - Updated unit tests and test helpers to reflect refactoring, introducing fake implementations for testing purposes. - Adjusted background execution scheduling and improved extensibility for custom scheduler strategies. * Refactor `SendHttpRequestTests`: simplify scheduling assertions, use shared extensions, and standardize method naming. Streamline helper methods and remove unused test logic. * Refactor: Replace `ActivityTestHelper` with `ActivityTestFixture` in unit tests for streamlined activity testing - Introduced `ActivityTestFixture` with a fluent API for better test setup and execution of activities. - Added extension methods `ActivityTestFixtureExtensions` and `ActivityTestFixtureHttpExtensions` for configuring attributes and HTTP services. - Updated test guidelines and unit tests to use the new fixture and extensions. - Removed `ActivityTestHelper`. * Refactor: Move `ActivityTestFixture` and related extensions to shared project for reuse across test suites - Consolidated `ActivityTestFixture`, `ActivityTestFixtureExtensions`, and `ActivityTestFixtureHttpExtensions` into `Elsa.Testing.Shared`. - Updated namespaces and imports across unit tests to reflect new structure. - Enhanced `AssertActivityAttributes` and added fluent configuration APIs. - Adjusted `Directory.Packages.props` with new dependencies, including `NSubstitute` and `xunit.assert`. * Refactor `SetVariableTests`: inline `ActivityTestFixture` initialization to simplify test setup. * Refactor `ActivityTestFixture`: eliminate redundant field `_services`, add `UsedImplicitly` attributes, and improve service collection management * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for `ActivityExecutionContextExtensions`, detailing methods and parameters. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for scheduler strategies and their methods - Updated `IActivityExecutionContextSchedulerStrategy` and `IWorkflowExecutionContextSchedulerStrategy` interfaces with XML summaries for methods. - Added XML documentation to implementations (`ActivityExecutionContextSchedulerStrategy`, `WorkflowExecutionContextSchedulerStrategy`) and test fakes for clarity. * Refactor `WriteLineTests`: consolidate duplicate test logic, simplify setup with shared helper method, and enhance readability in assertions. * Refactor `WriteLineTests` and `SetVariableTests`: replace `WriteLineAsync` assertions with synchronous `WriteLine`, streamline exception recording in `SetVariableTests`, and remove unused imports. * Add `ParallelTests` for unit and integration testing with various scenarios (#6988) - Added unit tests for `Parallel` activity to ensure proper scheduling of child activities, including empty and mixed activity cases. - Added integration tests to validate execution flow and edge cases for `Parallel` activities (e.g., nested parallelism, fault handling). - Enhanced `ScheduleChildrenAsync` in `Parallel` to handle no activity scenario by completing immediately. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add new unit and integration tests for activity input and expression evaluation (#6990) * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts - Added `IWorkflowExecutionContextSchedulerStrategy` and `IActivityExecutionContextSchedulerStrategy` interfaces. - Implemented `WorkflowExecutionContextSchedulerStrategy` and `ActivityExecutionContextSchedulerStrategy` for scheduling activities in workflows. - Refactored scheduling logic to utilize the new scheduler strategies. - Updated unit tests and test helpers to reflect refactoring, introducing fake implementations for testing purposes. - Adjusted background execution scheduling and improved extensibility for custom scheduler strategies. * Refactor `SendHttpRequestTests`: simplify scheduling assertions, use shared extensions, and standardize method naming. Streamline helper methods and remove unused test logic. * Refactor: Replace `ActivityTestHelper` with `ActivityTestFixture` in unit tests for streamlined activity testing - Introduced `ActivityTestFixture` with a fluent API for better test setup and execution of activities. - Added extension methods `ActivityTestFixtureExtensions` and `ActivityTestFixtureHttpExtensions` for configuring attributes and HTTP services. - Updated test guidelines and unit tests to use the new fixture and extensions. - Removed `ActivityTestHelper`. * Refactor: Move `ActivityTestFixture` and related extensions to shared project for reuse across test suites - Consolidated `ActivityTestFixture`, `ActivityTestFixtureExtensions`, and `ActivityTestFixtureHttpExtensions` into `Elsa.Testing.Shared`. - Updated namespaces and imports across unit tests to reflect new structure. - Enhanced `AssertActivityAttributes` and added fluent configuration APIs. - Adjusted `Directory.Packages.props` with new dependencies, including `NSubstitute` and `xunit.assert`. * Refactor `SetVariableTests`: inline `ActivityTestFixture` initialization to simplify test setup. * Refactor `ActivityTestFixture`: eliminate redundant field `_services`, add `UsedImplicitly` attributes, and improve service collection management * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for `ActivityExecutionContextExtensions`, detailing methods and parameters. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for scheduler strategies and their methods - Updated `IActivityExecutionContextSchedulerStrategy` and `IWorkflowExecutionContextSchedulerStrategy` interfaces with XML summaries for methods. - Added XML documentation to implementations (`ActivityExecutionContextSchedulerStrategy`, `WorkflowExecutionContextSchedulerStrategy`) and test fakes for clarity. * Refactor `WriteLineTests`: consolidate duplicate test logic, simplify setup with shared helper method, and enhance readability in assertions. * Refactor `WriteLineTests` and `SetVariableTests`: replace `WriteLineAsync` assertions with synchronous `WriteLine`, streamline exception recording in `SetVariableTests`, and remove unused imports. * Add new unit and integration tests for activity input and expression evaluation - Introduced comprehensive test suites covering activity input evaluation, expression handling, and fault scenarios. - Added unit tests for `ExpressionDescriptorRegistry`, `ExpressionEvaluator`, and activity execution context extensions. - Added integration tests: `CustomInputEvaluatorTests`, `InputEvaluationErrorTests`, and `InputPropertyEvaluationTests`. - Enhanced code coverage for edge cases and async evaluation logic. * Remove unused `RunWorkflowAsync` extension method from `RunActivityExtensions`. * Rename `CustomInputEvaluatorTests` to `InputEvaluationTests` for consistency with naming conventions. * Remove unused `Elsa.Workflows.Activities` import from `RunActivityExtensions`. * Remove redundant comments from `InputEvaluationErrorTests` for clarity. * Refactor unit tests to streamline activity and expression evaluations - Refactored `ExecuteActivityAsync` and `ExecuteWriteLineAsync` into shared helpers for consistency and reuse across tests. - Replaced redundant mock setups with helper methods in `ExpressionDescriptorRegistryTests`. - Simplified test setup for expression and activity evaluation by removing unused imports and consolidating configuration logic. - Enhanced readability by reducing duplicate code and leveraging shared utility methods. * Refactor activity input evaluation tests - Extracted `CreateContextAsync` helper into `EvaluationTestHelpers` for reuse across evaluation test suites. - Replaced inline activity context setup with shared helper in `InputPropertyEvaluationTests`, `WrappedInputEvaluationTests`, and related test suites. - Simplified test method names for clarity and consistency. - Updated test annotations to enhance readability and align with naming conventions. * Remove redundant test cases and unused imports - Deleted duplicated and non-essential test cases across evaluation test suites. - Removed unused imports to improve code cleanliness and readability. - Streamlined variable initializations and method calls within test setups. * Remove redundant test case from `InputEvaluationErrorTests` - Deleted the `ContinuesEvaluationForMultipleInputs` test, as it overlaps with existing tests and does not provide additional coverage. * Remove redundant assertion from `InputPropertyEvaluationTests` - Deleted `Assert.True(context.GetHasEvaluatedProperties())`, as it is unnecessary for verifying test outcomes. * Remove redundant test cases from `WrappedInputEvaluationTests` - Deleted `UsesDefaultValueWhenInputIsNull` and `EvaluatesExpression` tests as they are either duplicated or unnecessary for current test coverage. * Add unit test projects for `Elsa.Workflows.Management` and `Elsa.Expressions` - Introduced new test projects to separate and organize unit tests for `Elsa.Workflows.Management` and `Elsa.Expressions`. - Updated `Elsa.sln` to include references to the newly added test projects. - Adjusted namespaces in affected test classes for consistency with the updated project structure. * Refactor `ExpressionEvaluatorTests` for clarity and consistency - Simplified test method names and annotations for improved readability. - Replaced duplicate mock setups with helper functions (`CreateContextAsync`, `CreateContextWithMockHandlerAsync`, and related methods). - Streamlined test setups by removing redundant code and consolidating context creation logic. - Updated test annotations to include descriptive `DisplayName` attributes. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove redundant comment from `ExpressionEvaluatorTests` for clarity * Remove redundant blank lines from unit test classes - Eliminated unnecessary blank lines across `ActivityExecutionContextExtensions` test suites to improve code readability and consistency. * Update src/modules/Elsa.Expressions/Services/ExpressionEvaluator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Expand `test-guidelines.md` with testing best practices, helper references, and example snippets - Added detailed guidance on test project organization, updated helper documentation, and streamlined example code for activity unit testing. - Introduced scheduler strategy information and integration test patterns for deterministic tests. - Clarified usage of shared infrastructure like `ActivityTestFixture` and `AsyncWorkflowRunner`. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix merge issue * Add missing `using Elsa.Expressions.Models` directive to `SetVariableTests` * Update `SetVariableTests` and `ActivityTestFixture` to fix exception type assertion and improve test utility execution handling. * Update `SetVariableTests` and `ActivityTestFixture` to handle null variables, fix exception type assertion, and simplify context usage. --------- Co-authored-by: lucas.hipolito <lukhipolito@yahoo.com.br> Co-authored-by: lukhipolito-nexxbiz <lucas.hipolito@nexxbiz.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-22 18:54:58 +00:00
namespace Elsa.Activities.UnitTests.Flow;
/// <summary>
/// Shared helper methods for Flowchart unit tests.
/// </summary>
public static class FlowchartTestHelpers
{
Configures Flowchart Execution via DI (#7141) * Introduce `FlowchartExecutionMode` to streamline flowchart execution logic. - Added `FlowchartExecutionMode` enum to represent execution modes (Default, TokenBased, CounterBased). - Updated flowchart-related integration and unit tests to use the new execution mode. - Removed the global `UseTokenFlow` flag in favor of execution-specific configuration via `RunWorkflowOptions`. - Refactored flowchart-related APIs and test helpers for improved flexibility and modularity. * Add support for configuring flowchart execution behavior via `FlowchartOptions` and DI. - Introduced extensions for `FlowchartFeature` to simplify configuration. - Added DI support for setting default execution modes. - Refactored flowchart execution logic to prioritize configuration. * Update default Flowchart execution settings to align with version 3.5.2 behavior - Changed `DefaultExecutionMode` to `CounterBased`. - Updated `UseTokenFlow` default to `false`. * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Models/FlowchartExecutionMode.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Extensions/FlowchartFeatureExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update test/integration/Elsa.Workflows.IntegrationTests/Scenarios/FlowchartNextActivity/Tests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Extensions/RunWorkflowOptionsExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor flowchart integration tests for improved formatting and consistency * Refactor workflow tests and related services to improve reusability and align with updated Flowchart execution behavior * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Options/FlowchartOptions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor flowchart execution logic to use `FlowchartExecutionMode` enum, replacing boolean checks for improved clarity and extensibility. * Refactor tests and workflow logic to replace boolean `useTokenFlow` with `FlowchartExecutionMode` enum for clarity and consistency. * Refactor flowchart execution logic to centralize mode-based behavior handling and simplify implementation. * Remove unnecessary whitespace in Flowchart.cs to improve code formatting * Remove unnecessary whitespace in FlowJoinTests.cs to improve code formatting * Update src/common/Elsa.Testing.Shared.Integration/WorkflowTestFixture.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-15 09:15:39 +00:00
public static async Task<ActivityExecutionContext> ExecuteFlowchartAsync(Flowchart flowchart, FlowchartExecutionMode? executionMode = null)
Adds SetVariable activity unit tests (#6989) * Update doc/qa/test-guidelines.md Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com> * Improvements on maintainability of sendhttprequest unit tests * Improving tests and scheduled activity evaluation for activity context * Refactor and splitting unnecessary grouped tests * Improvements on SendHttp Unit tests * Improvements on tests * Update test/unit/Elsa.Activities.UnitTests/HTTP/SendHttpRequestTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Small suggestions from copilot * Update test/unit/Elsa.Activities.UnitTests/HTTP/SendHttpRequestTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * small copilot suggestion * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts - Added `IWorkflowExecutionContextSchedulerStrategy` and `IActivityExecutionContextSchedulerStrategy` interfaces. - Implemented `WorkflowExecutionContextSchedulerStrategy` and `ActivityExecutionContextSchedulerStrategy` for scheduling activities in workflows. - Refactored scheduling logic to utilize the new scheduler strategies. - Updated unit tests and test helpers to reflect refactoring, introducing fake implementations for testing purposes. - Adjusted background execution scheduling and improved extensibility for custom scheduler strategies. * Refactor `SendHttpRequestTests`: simplify scheduling assertions, use shared extensions, and standardize method naming. Streamline helper methods and remove unused test logic. * Refactor: Replace `ActivityTestHelper` with `ActivityTestFixture` in unit tests for streamlined activity testing - Introduced `ActivityTestFixture` with a fluent API for better test setup and execution of activities. - Added extension methods `ActivityTestFixtureExtensions` and `ActivityTestFixtureHttpExtensions` for configuring attributes and HTTP services. - Updated test guidelines and unit tests to use the new fixture and extensions. - Removed `ActivityTestHelper`. * Refactor: Move `ActivityTestFixture` and related extensions to shared project for reuse across test suites - Consolidated `ActivityTestFixture`, `ActivityTestFixtureExtensions`, and `ActivityTestFixtureHttpExtensions` into `Elsa.Testing.Shared`. - Updated namespaces and imports across unit tests to reflect new structure. - Enhanced `AssertActivityAttributes` and added fluent configuration APIs. - Adjusted `Directory.Packages.props` with new dependencies, including `NSubstitute` and `xunit.assert`. * Refactor `SetVariableTests`: inline `ActivityTestFixture` initialization to simplify test setup. * Refactor `ActivityTestFixture`: eliminate redundant field `_services`, add `UsedImplicitly` attributes, and improve service collection management * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for `ActivityExecutionContextExtensions`, detailing methods and parameters. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for scheduler strategies and their methods - Updated `IActivityExecutionContextSchedulerStrategy` and `IWorkflowExecutionContextSchedulerStrategy` interfaces with XML summaries for methods. - Added XML documentation to implementations (`ActivityExecutionContextSchedulerStrategy`, `WorkflowExecutionContextSchedulerStrategy`) and test fakes for clarity. * Refactor `WriteLineTests`: consolidate duplicate test logic, simplify setup with shared helper method, and enhance readability in assertions. * Refactor `WriteLineTests` and `SetVariableTests`: replace `WriteLineAsync` assertions with synchronous `WriteLine`, streamline exception recording in `SetVariableTests`, and remove unused imports. * Add integration and unit tests for `SetVariable` activity: ensure variable scoping, null handling, and value setting are covered. * Add new `SetVariableOfTTests` and update `SetVariableTests` for improved test coverage and type handling. * Add new unit and integration tests for activity input and expression evaluation - Introduced comprehensive test suites covering activity input evaluation, expression handling, and fault scenarios. - Added unit tests for `ExpressionDescriptorRegistry`, `ExpressionEvaluator`, and activity execution context extensions. - Added integration tests: `CustomInputEvaluatorTests`, `InputEvaluationErrorTests`, and `InputPropertyEvaluationTests`. - Enhanced code coverage for edge cases and async evaluation logic. * Remove unused `RunWorkflowAsync` extension method from `RunActivityExtensions`. * Rename `CustomInputEvaluatorTests` to `InputEvaluationTests` for consistency with naming conventions. * Remove unused `Elsa.Workflows.Activities` import from `RunActivityExtensions`. * Remove redundant comments from `InputEvaluationErrorTests` for clarity. * Refactor unit tests to streamline activity and expression evaluations - Refactored `ExecuteActivityAsync` and `ExecuteWriteLineAsync` into shared helpers for consistency and reuse across tests. - Replaced redundant mock setups with helper methods in `ExpressionDescriptorRegistryTests`. - Simplified test setup for expression and activity evaluation by removing unused imports and consolidating configuration logic. - Enhanced readability by reducing duplicate code and leveraging shared utility methods. * Refactor activity input evaluation tests - Extracted `CreateContextAsync` helper into `EvaluationTestHelpers` for reuse across evaluation test suites. - Replaced inline activity context setup with shared helper in `InputPropertyEvaluationTests`, `WrappedInputEvaluationTests`, and related test suites. - Simplified test method names for clarity and consistency. - Updated test annotations to enhance readability and align with naming conventions. * Remove redundant test cases and unused imports - Deleted duplicated and non-essential test cases across evaluation test suites. - Removed unused imports to improve code cleanliness and readability. - Streamlined variable initializations and method calls within test setups. * Remove redundant test case from `InputEvaluationErrorTests` - Deleted the `ContinuesEvaluationForMultipleInputs` test, as it overlaps with existing tests and does not provide additional coverage. * Remove redundant assertion from `InputPropertyEvaluationTests` - Deleted `Assert.True(context.GetHasEvaluatedProperties())`, as it is unnecessary for verifying test outcomes. * Remove redundant test cases from `WrappedInputEvaluationTests` - Deleted `UsesDefaultValueWhenInputIsNull` and `EvaluatesExpression` tests as they are either duplicated or unnecessary for current test coverage. * Add unit test projects for `Elsa.Workflows.Management` and `Elsa.Expressions` - Introduced new test projects to separate and organize unit tests for `Elsa.Workflows.Management` and `Elsa.Expressions`. - Updated `Elsa.sln` to include references to the newly added test projects. - Adjusted namespaces in affected test classes for consistency with the updated project structure. * Refactor `ExpressionEvaluatorTests` for clarity and consistency - Simplified test method names and annotations for improved readability. - Replaced duplicate mock setups with helper functions (`CreateContextAsync`, `CreateContextWithMockHandlerAsync`, and related methods). - Streamlined test setups by removing redundant code and consolidating context creation logic. - Updated test annotations to include descriptive `DisplayName` attributes. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove redundant comment from `ExpressionEvaluatorTests` for clarity * Remove redundant blank lines from unit test classes - Eliminated unnecessary blank lines across `ActivityExecutionContextExtensions` test suites to improve code readability and consistency. * Add unit tests for Flowchart activity - Introduced `FlowchartTests` to verify common Flowchart behavior, including start activity scheduling, execution without a start activity, and `UseTokenFlow` handling. - Added `FlowchartTestHelpers` to encapsulate shared test logic. - Updated project file to include the new `Flow` folder for organization. * Add integration tests for Flowchart activity execution strategies - Introduced `FlowchartCounterBasedTests` and `FlowchartTokenBasedTests` to verify different Flowchart execution strategies. - Added `FlowchartTestHelpers` for shared test logic, including helper methods for creating various flowchart configurations and connections. - Enhanced test coverage with scenarios for linear, parallel, and conditional flows, mixed merge modes, nested flowcharts, and token handling. - Updated project structure to include new test classes under the `Flow` folder. * Remove obsolete tag from `FlowJoin` activity description * Handle both string and enum values in `GetMergeMode` for backwards compatibility * Group flowchart integration tests into non-parallelizable test collection - Introduced `FlowchartTestCollection` to prevent parallel execution of flowchart tests due to shared `Flowchart.UseTokenFlow` flag. - Updated `FlowchartCounterBasedTests` and `FlowchartTokenBasedTests` to implement `IDisposable` and manage `UseTokenFlow` cleanup. * Remove unused `Flow` folder reference from test project file * Add `ParallelTests` for unit and integration testing with various scenarios (#6988) - Added unit tests for `Parallel` activity to ensure proper scheduling of child activities, including empty and mixed activity cases. - Added integration tests to validate execution flow and edge cases for `Parallel` activities (e.g., nested parallelism, fault handling). - Enhanced `ScheduleChildrenAsync` in `Parallel` to handle no activity scenario by completing immediately. * Fix null-check and memory declaration in `ActivityTestFixture` to prevent potential `NullReferenceException`. * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts (#6984) * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts - Added `IWorkflowExecutionContextSchedulerStrategy` and `IActivityExecutionContextSchedulerStrategy` interfaces. - Implemented `WorkflowExecutionContextSchedulerStrategy` and `ActivityExecutionContextSchedulerStrategy` for scheduling activities in workflows. - Refactored scheduling logic to utilize the new scheduler strategies. - Updated unit tests and test helpers to reflect refactoring, introducing fake implementations for testing purposes. - Adjusted background execution scheduling and improved extensibility for custom scheduler strategies. * Refactor `SendHttpRequestTests`: simplify scheduling assertions, use shared extensions, and standardize method naming. Streamline helper methods and remove unused test logic. * Refactor: Replace `ActivityTestHelper` with `ActivityTestFixture` in unit tests for streamlined activity testing - Introduced `ActivityTestFixture` with a fluent API for better test setup and execution of activities. - Added extension methods `ActivityTestFixtureExtensions` and `ActivityTestFixtureHttpExtensions` for configuring attributes and HTTP services. - Updated test guidelines and unit tests to use the new fixture and extensions. - Removed `ActivityTestHelper`. * Refactor: Move `ActivityTestFixture` and related extensions to shared project for reuse across test suites - Consolidated `ActivityTestFixture`, `ActivityTestFixtureExtensions`, and `ActivityTestFixtureHttpExtensions` into `Elsa.Testing.Shared`. - Updated namespaces and imports across unit tests to reflect new structure. - Enhanced `AssertActivityAttributes` and added fluent configuration APIs. - Adjusted `Directory.Packages.props` with new dependencies, including `NSubstitute` and `xunit.assert`. * Refactor `SetVariableTests`: inline `ActivityTestFixture` initialization to simplify test setup. * Refactor `ActivityTestFixture`: eliminate redundant field `_services`, add `UsedImplicitly` attributes, and improve service collection management * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for `ActivityExecutionContextExtensions`, detailing methods and parameters. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for scheduler strategies and their methods - Updated `IActivityExecutionContextSchedulerStrategy` and `IWorkflowExecutionContextSchedulerStrategy` interfaces with XML summaries for methods. - Added XML documentation to implementations (`ActivityExecutionContextSchedulerStrategy`, `WorkflowExecutionContextSchedulerStrategy`) and test fakes for clarity. * Refactor `WriteLineTests`: consolidate duplicate test logic, simplify setup with shared helper method, and enhance readability in assertions. * Refactor `WriteLineTests` and `SetVariableTests`: replace `WriteLineAsync` assertions with synchronous `WriteLine`, streamline exception recording in `SetVariableTests`, and remove unused imports. * Add `ParallelTests` for unit and integration testing with various scenarios (#6988) - Added unit tests for `Parallel` activity to ensure proper scheduling of child activities, including empty and mixed activity cases. - Added integration tests to validate execution flow and edge cases for `Parallel` activities (e.g., nested parallelism, fault handling). - Enhanced `ScheduleChildrenAsync` in `Parallel` to handle no activity scenario by completing immediately. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add new unit and integration tests for activity input and expression evaluation (#6990) * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts - Added `IWorkflowExecutionContextSchedulerStrategy` and `IActivityExecutionContextSchedulerStrategy` interfaces. - Implemented `WorkflowExecutionContextSchedulerStrategy` and `ActivityExecutionContextSchedulerStrategy` for scheduling activities in workflows. - Refactored scheduling logic to utilize the new scheduler strategies. - Updated unit tests and test helpers to reflect refactoring, introducing fake implementations for testing purposes. - Adjusted background execution scheduling and improved extensibility for custom scheduler strategies. * Refactor `SendHttpRequestTests`: simplify scheduling assertions, use shared extensions, and standardize method naming. Streamline helper methods and remove unused test logic. * Refactor: Replace `ActivityTestHelper` with `ActivityTestFixture` in unit tests for streamlined activity testing - Introduced `ActivityTestFixture` with a fluent API for better test setup and execution of activities. - Added extension methods `ActivityTestFixtureExtensions` and `ActivityTestFixtureHttpExtensions` for configuring attributes and HTTP services. - Updated test guidelines and unit tests to use the new fixture and extensions. - Removed `ActivityTestHelper`. * Refactor: Move `ActivityTestFixture` and related extensions to shared project for reuse across test suites - Consolidated `ActivityTestFixture`, `ActivityTestFixtureExtensions`, and `ActivityTestFixtureHttpExtensions` into `Elsa.Testing.Shared`. - Updated namespaces and imports across unit tests to reflect new structure. - Enhanced `AssertActivityAttributes` and added fluent configuration APIs. - Adjusted `Directory.Packages.props` with new dependencies, including `NSubstitute` and `xunit.assert`. * Refactor `SetVariableTests`: inline `ActivityTestFixture` initialization to simplify test setup. * Refactor `ActivityTestFixture`: eliminate redundant field `_services`, add `UsedImplicitly` attributes, and improve service collection management * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for `ActivityExecutionContextExtensions`, detailing methods and parameters. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for scheduler strategies and their methods - Updated `IActivityExecutionContextSchedulerStrategy` and `IWorkflowExecutionContextSchedulerStrategy` interfaces with XML summaries for methods. - Added XML documentation to implementations (`ActivityExecutionContextSchedulerStrategy`, `WorkflowExecutionContextSchedulerStrategy`) and test fakes for clarity. * Refactor `WriteLineTests`: consolidate duplicate test logic, simplify setup with shared helper method, and enhance readability in assertions. * Refactor `WriteLineTests` and `SetVariableTests`: replace `WriteLineAsync` assertions with synchronous `WriteLine`, streamline exception recording in `SetVariableTests`, and remove unused imports. * Add new unit and integration tests for activity input and expression evaluation - Introduced comprehensive test suites covering activity input evaluation, expression handling, and fault scenarios. - Added unit tests for `ExpressionDescriptorRegistry`, `ExpressionEvaluator`, and activity execution context extensions. - Added integration tests: `CustomInputEvaluatorTests`, `InputEvaluationErrorTests`, and `InputPropertyEvaluationTests`. - Enhanced code coverage for edge cases and async evaluation logic. * Remove unused `RunWorkflowAsync` extension method from `RunActivityExtensions`. * Rename `CustomInputEvaluatorTests` to `InputEvaluationTests` for consistency with naming conventions. * Remove unused `Elsa.Workflows.Activities` import from `RunActivityExtensions`. * Remove redundant comments from `InputEvaluationErrorTests` for clarity. * Refactor unit tests to streamline activity and expression evaluations - Refactored `ExecuteActivityAsync` and `ExecuteWriteLineAsync` into shared helpers for consistency and reuse across tests. - Replaced redundant mock setups with helper methods in `ExpressionDescriptorRegistryTests`. - Simplified test setup for expression and activity evaluation by removing unused imports and consolidating configuration logic. - Enhanced readability by reducing duplicate code and leveraging shared utility methods. * Refactor activity input evaluation tests - Extracted `CreateContextAsync` helper into `EvaluationTestHelpers` for reuse across evaluation test suites. - Replaced inline activity context setup with shared helper in `InputPropertyEvaluationTests`, `WrappedInputEvaluationTests`, and related test suites. - Simplified test method names for clarity and consistency. - Updated test annotations to enhance readability and align with naming conventions. * Remove redundant test cases and unused imports - Deleted duplicated and non-essential test cases across evaluation test suites. - Removed unused imports to improve code cleanliness and readability. - Streamlined variable initializations and method calls within test setups. * Remove redundant test case from `InputEvaluationErrorTests` - Deleted the `ContinuesEvaluationForMultipleInputs` test, as it overlaps with existing tests and does not provide additional coverage. * Remove redundant assertion from `InputPropertyEvaluationTests` - Deleted `Assert.True(context.GetHasEvaluatedProperties())`, as it is unnecessary for verifying test outcomes. * Remove redundant test cases from `WrappedInputEvaluationTests` - Deleted `UsesDefaultValueWhenInputIsNull` and `EvaluatesExpression` tests as they are either duplicated or unnecessary for current test coverage. * Add unit test projects for `Elsa.Workflows.Management` and `Elsa.Expressions` - Introduced new test projects to separate and organize unit tests for `Elsa.Workflows.Management` and `Elsa.Expressions`. - Updated `Elsa.sln` to include references to the newly added test projects. - Adjusted namespaces in affected test classes for consistency with the updated project structure. * Refactor `ExpressionEvaluatorTests` for clarity and consistency - Simplified test method names and annotations for improved readability. - Replaced duplicate mock setups with helper functions (`CreateContextAsync`, `CreateContextWithMockHandlerAsync`, and related methods). - Streamlined test setups by removing redundant code and consolidating context creation logic. - Updated test annotations to include descriptive `DisplayName` attributes. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove redundant comment from `ExpressionEvaluatorTests` for clarity * Remove redundant blank lines from unit test classes - Eliminated unnecessary blank lines across `ActivityExecutionContextExtensions` test suites to improve code readability and consistency. * Update src/modules/Elsa.Expressions/Services/ExpressionEvaluator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Expand `test-guidelines.md` with testing best practices, helper references, and example snippets - Added detailed guidance on test project organization, updated helper documentation, and streamlined example code for activity unit testing. - Introduced scheduler strategy information and integration test patterns for deterministic tests. - Clarified usage of shared infrastructure like `ActivityTestFixture` and `AsyncWorkflowRunner`. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix merge issue * Add missing `using Elsa.Expressions.Models` directive to `SetVariableTests` * Update `SetVariableTests` and `ActivityTestFixture` to fix exception type assertion and improve test utility execution handling. * Update `SetVariableTests` and `ActivityTestFixture` to handle null variables, fix exception type assertion, and simplify context usage. --------- Co-authored-by: lucas.hipolito <lukhipolito@yahoo.com.br> Co-authored-by: lukhipolito-nexxbiz <lucas.hipolito@nexxbiz.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-22 18:54:58 +00:00
{
var fixture = new ActivityTestFixture(flowchart);
Configures Flowchart Execution via DI (#7141) * Introduce `FlowchartExecutionMode` to streamline flowchart execution logic. - Added `FlowchartExecutionMode` enum to represent execution modes (Default, TokenBased, CounterBased). - Updated flowchart-related integration and unit tests to use the new execution mode. - Removed the global `UseTokenFlow` flag in favor of execution-specific configuration via `RunWorkflowOptions`. - Refactored flowchart-related APIs and test helpers for improved flexibility and modularity. * Add support for configuring flowchart execution behavior via `FlowchartOptions` and DI. - Introduced extensions for `FlowchartFeature` to simplify configuration. - Added DI support for setting default execution modes. - Refactored flowchart execution logic to prioritize configuration. * Update default Flowchart execution settings to align with version 3.5.2 behavior - Changed `DefaultExecutionMode` to `CounterBased`. - Updated `UseTokenFlow` default to `false`. * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Models/FlowchartExecutionMode.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Extensions/FlowchartFeatureExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update test/integration/Elsa.Workflows.IntegrationTests/Scenarios/FlowchartNextActivity/Tests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Extensions/RunWorkflowOptionsExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor flowchart integration tests for improved formatting and consistency * Refactor workflow tests and related services to improve reusability and align with updated Flowchart execution behavior * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Options/FlowchartOptions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor flowchart execution logic to use `FlowchartExecutionMode` enum, replacing boolean checks for improved clarity and extensibility. * Refactor tests and workflow logic to replace boolean `useTokenFlow` with `FlowchartExecutionMode` enum for clarity and consistency. * Refactor flowchart execution logic to centralize mode-based behavior handling and simplify implementation. * Remove unnecessary whitespace in Flowchart.cs to improve code formatting * Remove unnecessary whitespace in FlowJoinTests.cs to improve code formatting * Update src/common/Elsa.Testing.Shared.Integration/WorkflowTestFixture.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-15 09:15:39 +00:00
if (executionMode.HasValue)
{
fixture.ConfigureContext(context =>
{
context.WorkflowExecutionContext.Properties[Flowchart.ExecutionModePropertyKey] = executionMode.Value;
});
}
Adds SetVariable activity unit tests (#6989) * Update doc/qa/test-guidelines.md Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com> * Improvements on maintainability of sendhttprequest unit tests * Improving tests and scheduled activity evaluation for activity context * Refactor and splitting unnecessary grouped tests * Improvements on SendHttp Unit tests * Improvements on tests * Update test/unit/Elsa.Activities.UnitTests/HTTP/SendHttpRequestTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Small suggestions from copilot * Update test/unit/Elsa.Activities.UnitTests/HTTP/SendHttpRequestTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * small copilot suggestion * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts - Added `IWorkflowExecutionContextSchedulerStrategy` and `IActivityExecutionContextSchedulerStrategy` interfaces. - Implemented `WorkflowExecutionContextSchedulerStrategy` and `ActivityExecutionContextSchedulerStrategy` for scheduling activities in workflows. - Refactored scheduling logic to utilize the new scheduler strategies. - Updated unit tests and test helpers to reflect refactoring, introducing fake implementations for testing purposes. - Adjusted background execution scheduling and improved extensibility for custom scheduler strategies. * Refactor `SendHttpRequestTests`: simplify scheduling assertions, use shared extensions, and standardize method naming. Streamline helper methods and remove unused test logic. * Refactor: Replace `ActivityTestHelper` with `ActivityTestFixture` in unit tests for streamlined activity testing - Introduced `ActivityTestFixture` with a fluent API for better test setup and execution of activities. - Added extension methods `ActivityTestFixtureExtensions` and `ActivityTestFixtureHttpExtensions` for configuring attributes and HTTP services. - Updated test guidelines and unit tests to use the new fixture and extensions. - Removed `ActivityTestHelper`. * Refactor: Move `ActivityTestFixture` and related extensions to shared project for reuse across test suites - Consolidated `ActivityTestFixture`, `ActivityTestFixtureExtensions`, and `ActivityTestFixtureHttpExtensions` into `Elsa.Testing.Shared`. - Updated namespaces and imports across unit tests to reflect new structure. - Enhanced `AssertActivityAttributes` and added fluent configuration APIs. - Adjusted `Directory.Packages.props` with new dependencies, including `NSubstitute` and `xunit.assert`. * Refactor `SetVariableTests`: inline `ActivityTestFixture` initialization to simplify test setup. * Refactor `ActivityTestFixture`: eliminate redundant field `_services`, add `UsedImplicitly` attributes, and improve service collection management * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for `ActivityExecutionContextExtensions`, detailing methods and parameters. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for scheduler strategies and their methods - Updated `IActivityExecutionContextSchedulerStrategy` and `IWorkflowExecutionContextSchedulerStrategy` interfaces with XML summaries for methods. - Added XML documentation to implementations (`ActivityExecutionContextSchedulerStrategy`, `WorkflowExecutionContextSchedulerStrategy`) and test fakes for clarity. * Refactor `WriteLineTests`: consolidate duplicate test logic, simplify setup with shared helper method, and enhance readability in assertions. * Refactor `WriteLineTests` and `SetVariableTests`: replace `WriteLineAsync` assertions with synchronous `WriteLine`, streamline exception recording in `SetVariableTests`, and remove unused imports. * Add integration and unit tests for `SetVariable` activity: ensure variable scoping, null handling, and value setting are covered. * Add new `SetVariableOfTTests` and update `SetVariableTests` for improved test coverage and type handling. * Add new unit and integration tests for activity input and expression evaluation - Introduced comprehensive test suites covering activity input evaluation, expression handling, and fault scenarios. - Added unit tests for `ExpressionDescriptorRegistry`, `ExpressionEvaluator`, and activity execution context extensions. - Added integration tests: `CustomInputEvaluatorTests`, `InputEvaluationErrorTests`, and `InputPropertyEvaluationTests`. - Enhanced code coverage for edge cases and async evaluation logic. * Remove unused `RunWorkflowAsync` extension method from `RunActivityExtensions`. * Rename `CustomInputEvaluatorTests` to `InputEvaluationTests` for consistency with naming conventions. * Remove unused `Elsa.Workflows.Activities` import from `RunActivityExtensions`. * Remove redundant comments from `InputEvaluationErrorTests` for clarity. * Refactor unit tests to streamline activity and expression evaluations - Refactored `ExecuteActivityAsync` and `ExecuteWriteLineAsync` into shared helpers for consistency and reuse across tests. - Replaced redundant mock setups with helper methods in `ExpressionDescriptorRegistryTests`. - Simplified test setup for expression and activity evaluation by removing unused imports and consolidating configuration logic. - Enhanced readability by reducing duplicate code and leveraging shared utility methods. * Refactor activity input evaluation tests - Extracted `CreateContextAsync` helper into `EvaluationTestHelpers` for reuse across evaluation test suites. - Replaced inline activity context setup with shared helper in `InputPropertyEvaluationTests`, `WrappedInputEvaluationTests`, and related test suites. - Simplified test method names for clarity and consistency. - Updated test annotations to enhance readability and align with naming conventions. * Remove redundant test cases and unused imports - Deleted duplicated and non-essential test cases across evaluation test suites. - Removed unused imports to improve code cleanliness and readability. - Streamlined variable initializations and method calls within test setups. * Remove redundant test case from `InputEvaluationErrorTests` - Deleted the `ContinuesEvaluationForMultipleInputs` test, as it overlaps with existing tests and does not provide additional coverage. * Remove redundant assertion from `InputPropertyEvaluationTests` - Deleted `Assert.True(context.GetHasEvaluatedProperties())`, as it is unnecessary for verifying test outcomes. * Remove redundant test cases from `WrappedInputEvaluationTests` - Deleted `UsesDefaultValueWhenInputIsNull` and `EvaluatesExpression` tests as they are either duplicated or unnecessary for current test coverage. * Add unit test projects for `Elsa.Workflows.Management` and `Elsa.Expressions` - Introduced new test projects to separate and organize unit tests for `Elsa.Workflows.Management` and `Elsa.Expressions`. - Updated `Elsa.sln` to include references to the newly added test projects. - Adjusted namespaces in affected test classes for consistency with the updated project structure. * Refactor `ExpressionEvaluatorTests` for clarity and consistency - Simplified test method names and annotations for improved readability. - Replaced duplicate mock setups with helper functions (`CreateContextAsync`, `CreateContextWithMockHandlerAsync`, and related methods). - Streamlined test setups by removing redundant code and consolidating context creation logic. - Updated test annotations to include descriptive `DisplayName` attributes. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove redundant comment from `ExpressionEvaluatorTests` for clarity * Remove redundant blank lines from unit test classes - Eliminated unnecessary blank lines across `ActivityExecutionContextExtensions` test suites to improve code readability and consistency. * Add unit tests for Flowchart activity - Introduced `FlowchartTests` to verify common Flowchart behavior, including start activity scheduling, execution without a start activity, and `UseTokenFlow` handling. - Added `FlowchartTestHelpers` to encapsulate shared test logic. - Updated project file to include the new `Flow` folder for organization. * Add integration tests for Flowchart activity execution strategies - Introduced `FlowchartCounterBasedTests` and `FlowchartTokenBasedTests` to verify different Flowchart execution strategies. - Added `FlowchartTestHelpers` for shared test logic, including helper methods for creating various flowchart configurations and connections. - Enhanced test coverage with scenarios for linear, parallel, and conditional flows, mixed merge modes, nested flowcharts, and token handling. - Updated project structure to include new test classes under the `Flow` folder. * Remove obsolete tag from `FlowJoin` activity description * Handle both string and enum values in `GetMergeMode` for backwards compatibility * Group flowchart integration tests into non-parallelizable test collection - Introduced `FlowchartTestCollection` to prevent parallel execution of flowchart tests due to shared `Flowchart.UseTokenFlow` flag. - Updated `FlowchartCounterBasedTests` and `FlowchartTokenBasedTests` to implement `IDisposable` and manage `UseTokenFlow` cleanup. * Remove unused `Flow` folder reference from test project file * Add `ParallelTests` for unit and integration testing with various scenarios (#6988) - Added unit tests for `Parallel` activity to ensure proper scheduling of child activities, including empty and mixed activity cases. - Added integration tests to validate execution flow and edge cases for `Parallel` activities (e.g., nested parallelism, fault handling). - Enhanced `ScheduleChildrenAsync` in `Parallel` to handle no activity scenario by completing immediately. * Fix null-check and memory declaration in `ActivityTestFixture` to prevent potential `NullReferenceException`. * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts (#6984) * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts - Added `IWorkflowExecutionContextSchedulerStrategy` and `IActivityExecutionContextSchedulerStrategy` interfaces. - Implemented `WorkflowExecutionContextSchedulerStrategy` and `ActivityExecutionContextSchedulerStrategy` for scheduling activities in workflows. - Refactored scheduling logic to utilize the new scheduler strategies. - Updated unit tests and test helpers to reflect refactoring, introducing fake implementations for testing purposes. - Adjusted background execution scheduling and improved extensibility for custom scheduler strategies. * Refactor `SendHttpRequestTests`: simplify scheduling assertions, use shared extensions, and standardize method naming. Streamline helper methods and remove unused test logic. * Refactor: Replace `ActivityTestHelper` with `ActivityTestFixture` in unit tests for streamlined activity testing - Introduced `ActivityTestFixture` with a fluent API for better test setup and execution of activities. - Added extension methods `ActivityTestFixtureExtensions` and `ActivityTestFixtureHttpExtensions` for configuring attributes and HTTP services. - Updated test guidelines and unit tests to use the new fixture and extensions. - Removed `ActivityTestHelper`. * Refactor: Move `ActivityTestFixture` and related extensions to shared project for reuse across test suites - Consolidated `ActivityTestFixture`, `ActivityTestFixtureExtensions`, and `ActivityTestFixtureHttpExtensions` into `Elsa.Testing.Shared`. - Updated namespaces and imports across unit tests to reflect new structure. - Enhanced `AssertActivityAttributes` and added fluent configuration APIs. - Adjusted `Directory.Packages.props` with new dependencies, including `NSubstitute` and `xunit.assert`. * Refactor `SetVariableTests`: inline `ActivityTestFixture` initialization to simplify test setup. * Refactor `ActivityTestFixture`: eliminate redundant field `_services`, add `UsedImplicitly` attributes, and improve service collection management * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for `ActivityExecutionContextExtensions`, detailing methods and parameters. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for scheduler strategies and their methods - Updated `IActivityExecutionContextSchedulerStrategy` and `IWorkflowExecutionContextSchedulerStrategy` interfaces with XML summaries for methods. - Added XML documentation to implementations (`ActivityExecutionContextSchedulerStrategy`, `WorkflowExecutionContextSchedulerStrategy`) and test fakes for clarity. * Refactor `WriteLineTests`: consolidate duplicate test logic, simplify setup with shared helper method, and enhance readability in assertions. * Refactor `WriteLineTests` and `SetVariableTests`: replace `WriteLineAsync` assertions with synchronous `WriteLine`, streamline exception recording in `SetVariableTests`, and remove unused imports. * Add `ParallelTests` for unit and integration testing with various scenarios (#6988) - Added unit tests for `Parallel` activity to ensure proper scheduling of child activities, including empty and mixed activity cases. - Added integration tests to validate execution flow and edge cases for `Parallel` activities (e.g., nested parallelism, fault handling). - Enhanced `ScheduleChildrenAsync` in `Parallel` to handle no activity scenario by completing immediately. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add new unit and integration tests for activity input and expression evaluation (#6990) * Introduce Scheduler Strategy Interfaces and Implementations for Workflow and Activity Execution Contexts - Added `IWorkflowExecutionContextSchedulerStrategy` and `IActivityExecutionContextSchedulerStrategy` interfaces. - Implemented `WorkflowExecutionContextSchedulerStrategy` and `ActivityExecutionContextSchedulerStrategy` for scheduling activities in workflows. - Refactored scheduling logic to utilize the new scheduler strategies. - Updated unit tests and test helpers to reflect refactoring, introducing fake implementations for testing purposes. - Adjusted background execution scheduling and improved extensibility for custom scheduler strategies. * Refactor `SendHttpRequestTests`: simplify scheduling assertions, use shared extensions, and standardize method naming. Streamline helper methods and remove unused test logic. * Refactor: Replace `ActivityTestHelper` with `ActivityTestFixture` in unit tests for streamlined activity testing - Introduced `ActivityTestFixture` with a fluent API for better test setup and execution of activities. - Added extension methods `ActivityTestFixtureExtensions` and `ActivityTestFixtureHttpExtensions` for configuring attributes and HTTP services. - Updated test guidelines and unit tests to use the new fixture and extensions. - Removed `ActivityTestHelper`. * Refactor: Move `ActivityTestFixture` and related extensions to shared project for reuse across test suites - Consolidated `ActivityTestFixture`, `ActivityTestFixtureExtensions`, and `ActivityTestFixtureHttpExtensions` into `Elsa.Testing.Shared`. - Updated namespaces and imports across unit tests to reflect new structure. - Enhanced `AssertActivityAttributes` and added fluent configuration APIs. - Adjusted `Directory.Packages.props` with new dependencies, including `NSubstitute` and `xunit.assert`. * Refactor `SetVariableTests`: inline `ActivityTestFixture` initialization to simplify test setup. * Refactor `ActivityTestFixture`: eliminate redundant field `_services`, add `UsedImplicitly` attributes, and improve service collection management * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for `ActivityExecutionContextExtensions`, detailing methods and parameters. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add XML documentation for scheduler strategies and their methods - Updated `IActivityExecutionContextSchedulerStrategy` and `IWorkflowExecutionContextSchedulerStrategy` interfaces with XML summaries for methods. - Added XML documentation to implementations (`ActivityExecutionContextSchedulerStrategy`, `WorkflowExecutionContextSchedulerStrategy`) and test fakes for clarity. * Refactor `WriteLineTests`: consolidate duplicate test logic, simplify setup with shared helper method, and enhance readability in assertions. * Refactor `WriteLineTests` and `SetVariableTests`: replace `WriteLineAsync` assertions with synchronous `WriteLine`, streamline exception recording in `SetVariableTests`, and remove unused imports. * Add new unit and integration tests for activity input and expression evaluation - Introduced comprehensive test suites covering activity input evaluation, expression handling, and fault scenarios. - Added unit tests for `ExpressionDescriptorRegistry`, `ExpressionEvaluator`, and activity execution context extensions. - Added integration tests: `CustomInputEvaluatorTests`, `InputEvaluationErrorTests`, and `InputPropertyEvaluationTests`. - Enhanced code coverage for edge cases and async evaluation logic. * Remove unused `RunWorkflowAsync` extension method from `RunActivityExtensions`. * Rename `CustomInputEvaluatorTests` to `InputEvaluationTests` for consistency with naming conventions. * Remove unused `Elsa.Workflows.Activities` import from `RunActivityExtensions`. * Remove redundant comments from `InputEvaluationErrorTests` for clarity. * Refactor unit tests to streamline activity and expression evaluations - Refactored `ExecuteActivityAsync` and `ExecuteWriteLineAsync` into shared helpers for consistency and reuse across tests. - Replaced redundant mock setups with helper methods in `ExpressionDescriptorRegistryTests`. - Simplified test setup for expression and activity evaluation by removing unused imports and consolidating configuration logic. - Enhanced readability by reducing duplicate code and leveraging shared utility methods. * Refactor activity input evaluation tests - Extracted `CreateContextAsync` helper into `EvaluationTestHelpers` for reuse across evaluation test suites. - Replaced inline activity context setup with shared helper in `InputPropertyEvaluationTests`, `WrappedInputEvaluationTests`, and related test suites. - Simplified test method names for clarity and consistency. - Updated test annotations to enhance readability and align with naming conventions. * Remove redundant test cases and unused imports - Deleted duplicated and non-essential test cases across evaluation test suites. - Removed unused imports to improve code cleanliness and readability. - Streamlined variable initializations and method calls within test setups. * Remove redundant test case from `InputEvaluationErrorTests` - Deleted the `ContinuesEvaluationForMultipleInputs` test, as it overlaps with existing tests and does not provide additional coverage. * Remove redundant assertion from `InputPropertyEvaluationTests` - Deleted `Assert.True(context.GetHasEvaluatedProperties())`, as it is unnecessary for verifying test outcomes. * Remove redundant test cases from `WrappedInputEvaluationTests` - Deleted `UsesDefaultValueWhenInputIsNull` and `EvaluatesExpression` tests as they are either duplicated or unnecessary for current test coverage. * Add unit test projects for `Elsa.Workflows.Management` and `Elsa.Expressions` - Introduced new test projects to separate and organize unit tests for `Elsa.Workflows.Management` and `Elsa.Expressions`. - Updated `Elsa.sln` to include references to the newly added test projects. - Adjusted namespaces in affected test classes for consistency with the updated project structure. * Refactor `ExpressionEvaluatorTests` for clarity and consistency - Simplified test method names and annotations for improved readability. - Replaced duplicate mock setups with helper functions (`CreateContextAsync`, `CreateContextWithMockHandlerAsync`, and related methods). - Streamlined test setups by removing redundant code and consolidating context creation logic. - Updated test annotations to include descriptive `DisplayName` attributes. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove redundant comment from `ExpressionEvaluatorTests` for clarity * Remove redundant blank lines from unit test classes - Eliminated unnecessary blank lines across `ActivityExecutionContextExtensions` test suites to improve code readability and consistency. * Update src/modules/Elsa.Expressions/Services/ExpressionEvaluator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Expand `test-guidelines.md` with testing best practices, helper references, and example snippets - Added detailed guidance on test project organization, updated helper documentation, and streamlined example code for activity unit testing. - Introduced scheduler strategy information and integration test patterns for deterministic tests. - Clarified usage of shared infrastructure like `ActivityTestFixture` and `AsyncWorkflowRunner`. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix merge issue * Add missing `using Elsa.Expressions.Models` directive to `SetVariableTests` * Update `SetVariableTests` and `ActivityTestFixture` to fix exception type assertion and improve test utility execution handling. * Update `SetVariableTests` and `ActivityTestFixture` to handle null variables, fix exception type assertion, and simplify context usage. --------- Co-authored-by: lucas.hipolito <lukhipolito@yahoo.com.br> Co-authored-by: lukhipolito-nexxbiz <lucas.hipolito@nexxbiz.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-22 18:54:58 +00:00
return await fixture.ExecuteAsync();
}
}