From 60041f70c3a1cc159f48be13e4b0dc2d62f8eb54 Mon Sep 17 00:00:00 2001 From: yutopp Date: Tue, 8 Jan 2019 16:51:39 +0900 Subject: [PATCH] Add a test for JsonSchema.Serialize --- .../Tests/Json/SerializeWithSchemaTests.cs | 38 +++++++++++++++++++ .../Json/SerializeWithSchemaTests.cs.meta | 12 ++++++ 2 files changed, 50 insertions(+) create mode 100644 Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs create mode 100644 Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs.meta diff --git a/Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs b/Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs new file mode 100644 index 000000000..5d0556954 --- /dev/null +++ b/Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs @@ -0,0 +1,38 @@ +using NUnit.Framework; + +namespace UniJSON +{ + public class SerializeWithSchemaTests + { + [JsonSchema(Title="CheckConstraintsTest")] + public class CheckConstraintsTest + { + [JsonSchema(Minimum = 0)] + public int X; + + [JsonSchema(Minimum = 10)] // Not required, thus ignored when the value violates the constraints + public int Y; + } + + [Test] + public void TestCheckConstraints() + { + var obj = new CheckConstraintsTest() + { + X = 0, + Y = 0, // Will be excluded because 0 doesn't satisfy a requirement of "Minimum = 10" + }; + + var s = JsonSchema.FromType(); + { + var c = new JsonSchemaValidationContext(obj); + Assert.Null(s.Validator.Validate(c, s)); + } + var actual = s.Serialize(obj); + + var expected = @"{""X"":0}"; + + Assert.AreEqual(expected, actual); + } + } +} diff --git a/Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs.meta b/Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs.meta new file mode 100644 index 000000000..b0c9e7173 --- /dev/null +++ b/Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f1d1c3d9d4d20db409e9d5d9d671abbe +timeCreated: 1546930461 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: