mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-08 11:59:26 -05:00
Add a test for JsonSchema.Serialize
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1d1c3d9d4d20db409e9d5d9d671abbe
|
||||
timeCreated: 1546930461
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user