mirror of https://github.com/Squidex/squidex.git
10 changed files with 125 additions and 7 deletions
@ -0,0 +1,20 @@ |
|||||
|
{ |
||||
|
"appId": "06c68527-a2ca-4d84-91eb-a1707aa5b6fb,hotels", |
||||
|
"ruleDef": { |
||||
|
"trigger": { |
||||
|
"triggerType": "ManualTrigger" |
||||
|
}, |
||||
|
"action": { |
||||
|
"actionType": "Webhook", |
||||
|
"url": "http://squidex.io" |
||||
|
}, |
||||
|
"isEnabled": true |
||||
|
}, |
||||
|
"isDeleted": false, |
||||
|
"id": "265aaf1e-5dff-4c40-b1e6-1149f652cd30", |
||||
|
"createdBy": "subject:63761585e06d5466c71521b3", |
||||
|
"lastModifiedBy": "subject:63761585e06d5466c71521b3", |
||||
|
"created": "2022-12-05T11:00:23Z", |
||||
|
"lastModified": "2022-12-05T11:00:23Z", |
||||
|
"version": 0 |
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Text.Json.Serialization; |
||||
|
using Squidex.Domain.Apps.Core.HandleRules; |
||||
|
using Squidex.Domain.Apps.Core.Rules; |
||||
|
using Squidex.Domain.Apps.Core.TestHelpers; |
||||
|
using Squidex.Infrastructure.Json; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Rules.DomainObject; |
||||
|
|
||||
|
public class RuleStateTests |
||||
|
{ |
||||
|
private readonly IJsonSerializer serializer = TestUtils.CreateSerializer(options => |
||||
|
{ |
||||
|
options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; |
||||
|
}); |
||||
|
|
||||
|
[RuleAction] |
||||
|
public sealed record WebhookAction : RuleAction |
||||
|
{ |
||||
|
public Uri Url { get; set; } |
||||
|
} |
||||
|
|
||||
|
static RuleStateTests() |
||||
|
{ |
||||
|
TestUtils.TypeRegistry.Map(new RuleTypeProvider().Add<WebhookAction>()); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_deserialize_state() |
||||
|
{ |
||||
|
var json = File.ReadAllText("Rules/DomainObject/RuleState.json"); |
||||
|
|
||||
|
var deserialized = serializer.Deserialize<RuleDomainObject.State>(json); |
||||
|
|
||||
|
Assert.NotNull(deserialized); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_deserialize_state_from_old_representation() |
||||
|
{ |
||||
|
var json = File.ReadAllText("Rules/DomainObject/RuleState_Old.json"); |
||||
|
|
||||
|
var deserialized = serializer.Deserialize<RuleDomainObject.State>(json); |
||||
|
|
||||
|
Assert.NotNull(deserialized); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_serialize_deserialize_state() |
||||
|
{ |
||||
|
var json = File.ReadAllText("Rules/DomainObject/RuleState.json").CleanJson(); |
||||
|
|
||||
|
var serialized = serializer.Serialize(serializer.Deserialize<RuleDomainObject.State>(json), true); |
||||
|
|
||||
|
Assert.Equal(json, serialized); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
{ |
||||
|
"appId": "06c68527-a2ca-4d84-91eb-a1707aa5b6fb,hotels", |
||||
|
"ruleDef": { |
||||
|
"trigger": { |
||||
|
"$type": "ManualTrigger" |
||||
|
}, |
||||
|
"action": { |
||||
|
"$type": "WebhookAction", |
||||
|
"url": "http://squidex.io" |
||||
|
}, |
||||
|
"isEnabled": true |
||||
|
}, |
||||
|
"isDeleted": false, |
||||
|
"id": "265aaf1e-5dff-4c40-b1e6-1149f652cd30", |
||||
|
"createdBy": "subject:63761585e06d5466c71521b3", |
||||
|
"lastModifiedBy": "subject:63761585e06d5466c71521b3", |
||||
|
"created": "2022-12-05T11:00:23Z", |
||||
|
"lastModified": "2022-12-05T11:00:23Z", |
||||
|
"version": 0 |
||||
|
} |
||||
Loading…
Reference in new issue