* Add DispatchWorkflow tests with new workflow definitions - Introduced multiple workflow definitions with varied scenarios including input handling, correlation IDs, and fault handling. - Enhanced `DispatchWorkflowsTests` with comprehensive test cases to validate `DispatchWorkflow` behavior under different configurations. - Updated existing workflows and tests for improved structure, readability, and accuracy. - Refactored and renamed related workflows for consistency across test suites. * Update test/component/Elsa.Workflows.ComponentTests/Scenarios/Activities/DispatchWorkflows/DispatchWorkflowsTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor DispatchWorkflowsTests for readability and maintainability - Replaced hardcoded constants with named variables for improved clarity. - Enhanced assertions using utility methods like `Assert.Single` for cleaner code. - Updated WriteLine activity tests to handle null values reliably. - Introduced timeout handling for child workflow execution. * Update GUID length validation in JintJavaScriptFunctionBehaviorTests - Adjusted `shortGuid` length assertion to accommodate a range of 19-22 characters instead of 20-22. * Add extensive unit and component tests for scheduling activities - Introduced unit tests for `Cron`, `Delay`, `Timer`, and `StartAt` scheduling activities, covering general usage and corner cases. - Added component tests validating `Cron`, `Delay`, `Timer`, and `StartAt` workflows within broader scenarios, focusing on workflow execution, blocking, and resumption of activities. - Enhanced test project structures with new folder setups aligning to activity categories. - Updated namespaces and project files to match the new structure and added validation for scheduling logic. * Refactor Timer activity tests for consistency and reusability - Extracted shared logic for timer activity tests into `TimerActivityTestBase`. - Refactored `DelayTests`, `TimerTests`, `CronTests`, and `StartAtTests` to inherit from `TimerActivityTestBase`. - Removed redundant code and improved test consistency across all timer activity test cases. - Cleaned up unused imports and optimized namespaces. * Remove unused folder references from test project files * [WIP] Update unit and component tests for scheduling activities (#7037) * Initial plan * Replace ContainsKey + indexer with TryGetValue in CronTests Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Fixing build after merge * Remove DispatchWorkflowsTests and related references from the test suite --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> Co-authored-by: lucas.hipolito <lukhipolito@yahoo.com.br>
83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
using Elsa.Common;
|
|
using Elsa.Scheduling;
|
|
using Elsa.Scheduling.Activities;
|
|
using Elsa.Scheduling.Bookmarks;
|
|
using Elsa.Testing.Shared;
|
|
using Elsa.Workflows;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NSubstitute;
|
|
|
|
namespace Elsa.Activities.UnitTests.Scheduling;
|
|
|
|
public class DelayTests
|
|
{
|
|
[Theory]
|
|
[InlineData(1, 0, 0)] // 1 hour
|
|
[InlineData(0, 30, 0)] // 30 minutes
|
|
[InlineData(0, 0, 45)] // 45 seconds
|
|
[InlineData(24, 0, 0)] // 1 day
|
|
public async Task CreatesBookmark_WithCorrectResumeTime(int hours, int minutes, int seconds)
|
|
{
|
|
// Arrange
|
|
var now = new DateTimeOffset(2025, 1, 6, 12, 0, 0, TimeSpan.Zero);
|
|
var delay = new TimeSpan(hours, minutes, seconds);
|
|
var expectedResumeAt = now.Add(delay);
|
|
var clock = CreateClock(now);
|
|
|
|
var activity = new Delay(delay);
|
|
|
|
// Act
|
|
var context = await ExecuteAsync(activity, clock);
|
|
|
|
// Assert
|
|
Assert.Equal(ActivityStatus.Running, context.Status);
|
|
var payload = GetDelayPayload(context);
|
|
Assert.Equal(expectedResumeAt, payload.ResumeAt);
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(FactoryMethodTestCases))]
|
|
public async Task FactoryMethods_CreateCorrectTimeSpans(Delay activity, TimeSpan expected)
|
|
{
|
|
// Arrange
|
|
var now = new DateTimeOffset(2025, 1, 6, 12, 0, 0, TimeSpan.Zero);
|
|
var clock = CreateClock(now);
|
|
|
|
// Act
|
|
var context = await ExecuteAsync(activity, clock);
|
|
|
|
// Assert
|
|
var payload = GetDelayPayload(context);
|
|
Assert.Equal(now.Add(expected), payload.ResumeAt);
|
|
}
|
|
|
|
public static TheoryData<Delay, TimeSpan> FactoryMethodTestCases() => new()
|
|
{
|
|
{ Delay.FromSeconds(30), TimeSpan.FromSeconds(30) },
|
|
{ Delay.FromMinutes(5), TimeSpan.FromMinutes(5) },
|
|
{ Delay.FromHours(2), TimeSpan.FromHours(2) },
|
|
{ Delay.FromDays(1), TimeSpan.FromDays(1) }
|
|
};
|
|
|
|
private static async Task<ActivityExecutionContext> ExecuteAsync(Delay activity, ISystemClock clock)
|
|
{
|
|
return await new ActivityTestFixture(activity)
|
|
.ConfigureServices(services => services.AddSingleton(clock))
|
|
.ExecuteAsync();
|
|
}
|
|
|
|
private static ISystemClock CreateClock(DateTimeOffset now)
|
|
{
|
|
var clock = Substitute.For<ISystemClock>();
|
|
clock.UtcNow.Returns(now);
|
|
return clock;
|
|
}
|
|
|
|
private static DelayPayload GetDelayPayload(ActivityExecutionContext context)
|
|
{
|
|
var bookmark = Assert.Single(context.WorkflowExecutionContext.Bookmarks);
|
|
Assert.Equal(SchedulingStimulusNames.Delay, bookmark.Name);
|
|
return Assert.IsType<DelayPayload>(bookmark.Payload);
|
|
}
|
|
}
|