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`.
This commit is contained in:
parent
5f3623aa0b
commit
0992404d96
|
|
@ -12,7 +12,7 @@ public class WorkflowDefinition : VersionedEntity
|
|||
/// <summary>
|
||||
/// The logical ID of the workflow. This ID is the same across versions.
|
||||
/// </summary>
|
||||
public string DefinitionId { get; set; } = default!;
|
||||
public string DefinitionId { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the workflow.
|
||||
|
|
@ -67,17 +67,17 @@ public class WorkflowDefinition : VersionedEntity
|
|||
/// <summary>
|
||||
/// The name of the workflow materializer to interpret the <see cref="StringData"/> or <see cref="BinaryData"/>.
|
||||
/// </summary>
|
||||
public string MaterializerName { get; set; } = default!;
|
||||
public string MaterializerName { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Provider-specific data.
|
||||
/// </summary>
|
||||
public string? MaterializerContext { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A textual representation of the workflow. The data is to be interpreted by the configured materializer.
|
||||
/// </summary>
|
||||
public string? StringData { get; set; }
|
||||
public string StringData { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// A binary representation of the workflow. The data is to be interpreted by the configured materializer.
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class WorkflowDefinitionPublisher : IWorkflowDefinitionPublisher
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public WorkflowDefinition New(IActivity? root = default)
|
||||
public WorkflowDefinition New(IActivity? root = null)
|
||||
{
|
||||
root ??= new Sequence();
|
||||
var id = _identityGenerator.GenerateId();
|
||||
|
|
|
|||
|
|
@ -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<IWorkflowBuilderFactory>();
|
||||
_publisher = _services.GetRequiredService<IWorkflowDefinitionPublisher>();
|
||||
_serializer = _services.GetRequiredService<IActivitySerializer>();
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue