Add JSON-LD expand/compact/canonicalize tests
This commit is contained in:
parent
9ac55fdeb8
commit
6bb356ea02
4 changed files with 52 additions and 5 deletions
|
@ -56,6 +56,6 @@ public static class LdHelpers {
|
||||||
public static JArray? Expand(object obj) => Expand(JToken.FromObject(obj));
|
public static JArray? Expand(object obj) => Expand(JToken.FromObject(obj));
|
||||||
public static JObject? Compact(JToken? json) => JsonLdProcessor.Compact(json, DefaultContext, Options);
|
public static JObject? Compact(JToken? json) => JsonLdProcessor.Compact(json, DefaultContext, Options);
|
||||||
public static JArray? Expand(JToken? json) => JsonLdProcessor.Expand(json, Options);
|
public static JArray? Expand(JToken? json) => JsonLdProcessor.Expand(json, Options);
|
||||||
public static string Canonicalize(JArray json) => JsonLdProcessor.Canonicalize(json);
|
public static string Canonicalize(JArray json) => JsonLdProcessor.Canonicalize(json.DeepClone() as JArray);
|
||||||
public static string Canonicalize(JObject json) => JsonLdProcessor.Canonicalize([json]);
|
public static string Canonicalize(JObject json) => JsonLdProcessor.Canonicalize([json.DeepClone()]);
|
||||||
}
|
}
|
|
@ -1,6 +1,4 @@
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using FluentAssertions;
|
|
||||||
using Iceshrimp.Backend.Core.Federation.ActivityStreams;
|
using Iceshrimp.Backend.Core.Federation.ActivityStreams;
|
||||||
using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
|
using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
|
||||||
using Iceshrimp.Backend.Core.Federation.Cryptography;
|
using Iceshrimp.Backend.Core.Federation.Cryptography;
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
global using FluentAssertions;
|
48
Iceshrimp.Tests/Serialization/JsonLdTests.cs
Normal file
48
Iceshrimp.Tests/Serialization/JsonLdTests.cs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
using Iceshrimp.Backend.Core.Federation.ActivityStreams;
|
||||||
|
using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
|
||||||
|
using Iceshrimp.Backend.Core.Helpers;
|
||||||
|
|
||||||
|
namespace Iceshrimp.Tests.Serialization;
|
||||||
|
|
||||||
|
[TestClass]
|
||||||
|
public class JsonLdTests {
|
||||||
|
private ASActor _actor = null!;
|
||||||
|
|
||||||
|
[TestInitialize]
|
||||||
|
public void Initialize() {
|
||||||
|
_actor = new ASActor {
|
||||||
|
Id = $"https://example.org/users/{IdHelpers.GenerateSlowflakeId()}",
|
||||||
|
Type = ["https://www.w3.org/ns/activitystreams#Person"],
|
||||||
|
Url = new ASLink("https://example.org/@test"),
|
||||||
|
Username = "test",
|
||||||
|
DisplayName = "Test account",
|
||||||
|
IsCat = false,
|
||||||
|
IsDiscoverable = true,
|
||||||
|
IsLocked = true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void RoundtripTest() {
|
||||||
|
var expanded = LdHelpers.Expand(_actor)!;
|
||||||
|
expanded.Should().NotBeNull();
|
||||||
|
|
||||||
|
var canonicalized = LdHelpers.Canonicalize(expanded);
|
||||||
|
canonicalized.Should().NotBeNull();
|
||||||
|
|
||||||
|
var compacted = LdHelpers.Compact(expanded);
|
||||||
|
compacted.Should().NotBeNull();
|
||||||
|
|
||||||
|
var expanded2 = LdHelpers.Expand(compacted)!;
|
||||||
|
expanded2.Should().NotBeNull();
|
||||||
|
expanded2.Should().BeEquivalentTo(expanded);
|
||||||
|
|
||||||
|
var compacted2 = LdHelpers.Compact(expanded2)!;
|
||||||
|
compacted2.Should().NotBeNull();
|
||||||
|
compacted2.Should().BeEquivalentTo(compacted);
|
||||||
|
|
||||||
|
var canonicalized2 = LdHelpers.Canonicalize(expanded2);
|
||||||
|
canonicalized2.Should().NotBeNull();
|
||||||
|
canonicalized2.Should().BeEquivalentTo(canonicalized);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue