Add project files.
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
using Elsa.Testing.Shared;
|
||||
using Elsa.Workflows.State;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.JsonObjectSerialization;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for serializing and deserializing JSON objects containing reserved keywords such as $id.
|
||||
/// </summary>
|
||||
public class Tests
|
||||
{
|
||||
private readonly CapturingTextWriter _capturingTextWriter = new();
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IWorkflowStateSerializer _workflowStateSerializer;
|
||||
|
||||
public Tests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
_services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
|
||||
_workflowStateSerializer = _services.GetRequiredService<IWorkflowStateSerializer>();
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "User-objects containing $id don't break deserialization into ExpandoObject.")]
|
||||
public async Task Test1()
|
||||
{
|
||||
// Populate registries.
|
||||
await _services.PopulateRegistriesAsync();
|
||||
|
||||
// Import workflow.
|
||||
var workflowFileName = "Scenarios/JsonObjectSerialization/Workflows/instance-serialization.json";
|
||||
var workflowDefinition = await _services.ImportWorkflowDefinitionAsync(workflowFileName);
|
||||
|
||||
// Execute.
|
||||
var workflowState = await _services.RunWorkflowUntilEndAsync(workflowDefinition.DefinitionId);
|
||||
|
||||
// Serialize workflow state.
|
||||
var serializedWorkflowState = _workflowStateSerializer.Serialize(workflowState);
|
||||
|
||||
// Attempt to deserialize workflow state.
|
||||
_workflowStateSerializer.Deserialize<WorkflowState>(serializedWorkflowState);
|
||||
|
||||
// If we reach this point, the test has passed. Otherwise, an exception would have been thrown.
|
||||
}
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
{
|
||||
"id": "b78e443339b5bf1e",
|
||||
"definitionId": "861e51cdbe07931",
|
||||
"name": "Instance Serialization",
|
||||
"description": "This workflow stores a user-JSON object containing $id as a field, which should not affect the deserialization process form JSON back into ExpandoObject.",
|
||||
"createdAt": "2023-11-23T15:18:12.805077+00:00",
|
||||
"version": 13,
|
||||
"toolVersion": "3.0.0.0",
|
||||
"variables": [
|
||||
{
|
||||
"id": "d4f37df0c6781767",
|
||||
"name": "Variable1",
|
||||
"typeName": "Object",
|
||||
"isArray": false,
|
||||
"storageDriverTypeName": "Elsa.Workflows.Services.WorkflowStorageDriver, Elsa.Workflows.Core"
|
||||
},
|
||||
{
|
||||
"id": "4e256dab27d33eac",
|
||||
"name": "Variable2",
|
||||
"typeName": "Object",
|
||||
"isArray": false,
|
||||
"storageDriverTypeName": "Elsa.Workflows.Services.WorkflowStorageDriver, Elsa.Workflows.Core"
|
||||
}
|
||||
],
|
||||
"inputs": [],
|
||||
"outputs": [],
|
||||
"outcomes": [],
|
||||
"customProperties": {},
|
||||
"isReadonly": false,
|
||||
"isLatest": true,
|
||||
"isPublished": false,
|
||||
"options": {
|
||||
"autoUpdateConsumingWorkflows": false
|
||||
},
|
||||
"root": {
|
||||
"type": "Elsa.Flowchart",
|
||||
"version": 1,
|
||||
"id": "35cdc2a3529d9b55",
|
||||
"nodeId": "Workflow1:35cdc2a3529d9b55",
|
||||
"metadata": {},
|
||||
"customProperties": {
|
||||
"source": "FlowchartJsonConverter.cs:47",
|
||||
"notFoundConnections": [],
|
||||
"canStartWorkflow": false,
|
||||
"runAsynchronously": false
|
||||
},
|
||||
"activities": [
|
||||
{
|
||||
"variable": {
|
||||
"id": "d4f37df0c6781767",
|
||||
"name": "Variable1",
|
||||
"typeName": "Object",
|
||||
"storageDriverTypeName": "Elsa.Workflows.Services.WorkflowStorageDriver, Elsa.Workflows.Core"
|
||||
},
|
||||
"value": {
|
||||
"typeName": "Object",
|
||||
"expression": {
|
||||
"type": "JavaScript",
|
||||
"value": "return {\n \u0022inputSchema\u0022: {\n \u0022$schema\u0022: \u0022http://json-schema.org/draft-07/schema#\u0022,\n \u0022title\u0022: \u0022Inform front-office afd 2.0 input schema\u0022,\n \u0022description\u0022: \u0022Schema of the AFD 2.0 message that is sent to the front-office\u0022,\n \u0022$id\u0022: \u0022#/definitions/inform-front-office-input-afd\u0022,\n \u0022type\u0022: \u0022object\u0022\n }\n}"
|
||||
},
|
||||
"memoryReference": {
|
||||
"id": "d4f32ee0ad659ba5:input-0"
|
||||
}
|
||||
},
|
||||
"id": "d4f32ee0ad659ba5",
|
||||
"nodeId": "Workflow1:35cdc2a3529d9b55:d4f32ee0ad659ba5",
|
||||
"name": "SetVariable1",
|
||||
"type": "Elsa.SetVariable",
|
||||
"version": 1,
|
||||
"customProperties": {
|
||||
"canStartWorkflow": false,
|
||||
"runAsynchronously": false
|
||||
},
|
||||
"metadata": {
|
||||
"designer": {
|
||||
"position": {
|
||||
"x": -456.5988464355469,
|
||||
"y": -104.93463134765625
|
||||
},
|
||||
"size": {
|
||||
"width": 153.828125,
|
||||
"height": 50
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"variable": {
|
||||
"id": "4e256dab27d33eac",
|
||||
"name": "Variable2",
|
||||
"typeName": "Object",
|
||||
"storageDriverTypeName": "Elsa.Workflows.Services.WorkflowStorageDriver, Elsa.Workflows.Core"
|
||||
},
|
||||
"value": {
|
||||
"typeName": "Object",
|
||||
"expression": {
|
||||
"type": "JavaScript",
|
||||
"value": "return getVariable1()"
|
||||
},
|
||||
"memoryReference": {
|
||||
"id": "31c60a181a1a66d8:input-0"
|
||||
}
|
||||
},
|
||||
"id": "31c60a181a1a66d8",
|
||||
"nodeId": "Workflow1:35cdc2a3529d9b55:31c60a181a1a66d8",
|
||||
"name": "SetVariable2",
|
||||
"type": "Elsa.SetVariable",
|
||||
"version": 1,
|
||||
"customProperties": {
|
||||
"canStartWorkflow": false,
|
||||
"runAsynchronously": false
|
||||
},
|
||||
"metadata": {
|
||||
"designer": {
|
||||
"position": {
|
||||
"x": -210.69132232666016,
|
||||
"y": -104.93463134765625
|
||||
},
|
||||
"size": {
|
||||
"width": 153.828125,
|
||||
"height": 50
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"connections": [
|
||||
{
|
||||
"source": {
|
||||
"activity": "d4f32ee0ad659ba5",
|
||||
"port": "Done"
|
||||
},
|
||||
"target": {
|
||||
"activity": "31c60a181a1a66d8",
|
||||
"port": "In"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user