From 0992404d960c68de011ff89d992cc4834f79ee64 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 26 Dec 2024 11:17:54 +0100 Subject: [PATCH] Add integration test for workflow serialization Introduce a new integration test to verify workflow serialization functionality, ensuring that newly created workflow definitions can be serialized and deserialized correctly. Adjust default nullability for certain fields in `WorkflowDefinition` to improve consistency and prevent null reference issues. Minor argument update in `New` method of `WorkflowDefinitionPublisher`. --- .../Entities/WorkflowDefinition.cs | 8 ++--- .../Services/WorkflowDefinitionPublisher.cs | 2 +- .../Scenarios/Serialization/Tests.cs | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 test/integration/Elsa.Workflows.IntegrationTests/Scenarios/Serialization/Tests.cs diff --git a/src/modules/Elsa.Workflows.Management/Entities/WorkflowDefinition.cs b/src/modules/Elsa.Workflows.Management/Entities/WorkflowDefinition.cs index 5f15fbdc1..d465f0765 100644 --- a/src/modules/Elsa.Workflows.Management/Entities/WorkflowDefinition.cs +++ b/src/modules/Elsa.Workflows.Management/Entities/WorkflowDefinition.cs @@ -12,7 +12,7 @@ public class WorkflowDefinition : VersionedEntity /// /// The logical ID of the workflow. This ID is the same across versions. /// - public string DefinitionId { get; set; } = default!; + public string DefinitionId { get; set; } = null!; /// /// The name of the workflow. @@ -67,17 +67,17 @@ public class WorkflowDefinition : VersionedEntity /// /// The name of the workflow materializer to interpret the or . /// - public string MaterializerName { get; set; } = default!; + public string MaterializerName { get; set; } = null!; /// /// Provider-specific data. /// public string? MaterializerContext { get; set; } - + /// /// A textual representation of the workflow. The data is to be interpreted by the configured materializer. /// - public string? StringData { get; set; } + public string StringData { get; set; } = null!; /// /// A binary representation of the workflow. The data is to be interpreted by the configured materializer. diff --git a/src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionPublisher.cs b/src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionPublisher.cs index 75a20e2d4..0cdc9491e 100644 --- a/src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionPublisher.cs +++ b/src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionPublisher.cs @@ -46,7 +46,7 @@ public class WorkflowDefinitionPublisher : IWorkflowDefinitionPublisher } /// - public WorkflowDefinition New(IActivity? root = default) + public WorkflowDefinition New(IActivity? root = null) { root ??= new Sequence(); var id = _identityGenerator.GenerateId(); diff --git a/test/integration/Elsa.Workflows.IntegrationTests/Scenarios/Serialization/Tests.cs b/test/integration/Elsa.Workflows.IntegrationTests/Scenarios/Serialization/Tests.cs new file mode 100644 index 000000000..786c7a8ba --- /dev/null +++ b/test/integration/Elsa.Workflows.IntegrationTests/Scenarios/Serialization/Tests.cs @@ -0,0 +1,31 @@ +using Elsa.Testing.Shared; +using Elsa.Workflows.Management; +using Microsoft.Extensions.DependencyInjection; +using Xunit.Abstractions; + +namespace Elsa.Workflows.IntegrationTests.Scenarios.Serialization; + +public class Tests +{ + private readonly CapturingTextWriter _capturingTextWriter = new(); + private readonly IServiceProvider _services; + private readonly IWorkflowDefinitionPublisher _publisher; + private readonly IActivitySerializer _serializer; + + public Tests(ITestOutputHelper testOutputHelper) + { + _services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build(); + _services.GetRequiredService(); + _publisher = _services.GetRequiredService(); + _serializer = _services.GetRequiredService(); + } + + [Fact(DisplayName = "Can serialize newly created workflow definition")] + public async Task Test1() + { + await _services.PopulateRegistriesAsync(); + var workflowDefinition = _publisher.New(); + var root = _serializer.Deserialize(workflowDefinition.StringData); + Assert.NotNull(root); + } +} \ No newline at end of file