Add a test for JsonSchema.Serialize

This commit is contained in:
yutopp
2019-01-08 16:51:39 +09:00
parent c3ccc802da
commit 60041f70c3
2 changed files with 50 additions and 0 deletions

View File

@@ -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<CheckConstraintsTest>();
{
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);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f1d1c3d9d4d20db409e9d5d9d671abbe
timeCreated: 1546930461
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: