elsa-core/test/integration/Elsa.IntegrationTests/Serialization/SpecialPropertySerialization/Tests.cs
herblinernexxbizz a0bdf45851
Features/fix serialization issues (#3966)
* run locally

* commit created test

* updated test

* Island

* Commented code

* creating tests

* upodate tests

* revert

* create working tests

* fix test roundtrip Jobject

* update tests

* finish tests

* create branch without getdefinition by keys

* move test files add @

* Special properties deserialization test

* refactor tests make it shorter

* clean PolymorphicObjectConverter

* rename properties

* Escape keys starting with reserved symbols

* Fix fix of converter

* Add newline normalization

* Minor cleanup and handling nullability warnings

* compact tests

---------

Co-authored-by: Marius Vasile Vușcan <marius.vuscan@nexxbiz.io>
Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2023-04-28 10:29:06 +02:00

42 lines
1.5 KiB
C#

using Elsa.Testing.Shared;
using Elsa.Workflows.Core.Contracts;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text.Json.Nodes;
using Xunit;
using Xunit.Abstractions;
namespace Elsa.IntegrationTests.Serialization.SpecialPropertySerialization
{
public class Tests
{
private readonly IServiceProvider _services;
public Tests(ITestOutputHelper testOutputHelper)
{
_services = new TestApplicationBuilder(testOutputHelper).Build();
}
[Fact(DisplayName = "Serialize and deserialize properties with $ prefix")]
public void Test_Special_Properties_Serialization_roundtrip()
{
var payloadSerializer = _services.GetRequiredService<IPayloadSerializer>();
var jsonContent = "{\"prop1\":{\"script\":[{\"$id\":\"someid\"}]} }";
var dict = new Dictionary<string, object>
{
{ "Content", JsonNode.Parse(jsonContent)! }
};
var jsonSerialized = payloadSerializer.Serialize(dict);
var transformationModel = payloadSerializer.Deserialize<IDictionary<string, object>>(jsonSerialized);
var result = transformationModel["Content"].ToString()!;
var expected = "{\"prop1\":{\"script\":[{\"$id\":\"someid\"}]} }";
var jsonResult = JsonNode.Parse(result)?.ToString();
var jsonExpected = JsonNode.Parse(expected)?.ToString();
Assert.Equal(jsonExpected, jsonResult);
}
}
}