public void ValidationConstraintTests_ParseOptionalFloat() { var testInstance = new TestSerialization(); var constraint = new ValidationConstraint <TestSerialization>("f", JTokenType.Float, false, 0, 0, (s, p) => p.FloatField = s.ToObject <float>()); testInstance.FloatField = 42.42f; constraint.ParseAndThrowOnFailure(JsonObject, testInstance); Assert.AreEqual(0.666f, testInstance.FloatField); }
public void ValidationConstraintTests_ParseOptionalBoolean() { var testInstance = new TestSerialization(); var constraint = new ValidationConstraint <TestSerialization>("b", JTokenType.Boolean, false, 0, 0, (s, p) => p.BoolField = s.ToObject <bool>()); testInstance.BoolField = true; constraint.ParseAndThrowOnFailure(JsonObject, testInstance); Assert.AreEqual(false, testInstance.BoolField); }
public void ValidationConstraintTests_ParseOptionalString() { var testInstance = new TestSerialization(); var constraint = new ValidationConstraint <TestSerialization>("s", JTokenType.String, false, 0, 0, (s, p) => p.StringField = s.ToObject <string>()); testInstance.StringField = null; constraint.ParseAndThrowOnFailure(JsonObject, testInstance); Assert.IsNotNull(testInstance.StringField); Assert.AreEqual("string value", testInstance.StringField); }
public void ValidationConstraintTests_ParseOptionalVersion() { var testInstance = new TestSerialization(); var constraint = new ValidationConstraint <TestSerialization>("v", JTokenType.Array, false, 2, 2, (s, p) => p.Version = s.ToObject <int[]>()); testInstance.Version = new[] { 42, 42 }; constraint.ParseAndThrowOnFailure(JsonObject, testInstance); Assert.IsNotNull(testInstance.Version); Assert.AreEqual(1, testInstance.Version[0]); Assert.AreEqual(0, testInstance.Version[1]); }
public void ValidationConstraintTests_ParseRequiredVersion() { var testInstance = new TestSerialization(); var constraint = new ValidationConstraint <TestSerialization>(path: "v", type: JTokenType.Array, isRequired: true, miniumChildren: 2, maximumChildren: 2, parse: (s, p) => p.Version = s.ToObject <int[]>()); testInstance.Version = new[] { 42, 42 }; constraint.ParseAndThrowOnFailure(JsonObject, testInstance); Assert.IsNotNull(testInstance.Version); Assert.AreEqual(1, testInstance.Version[0]); Assert.AreEqual(0, testInstance.Version[1]); }