コード例 #1
0
ファイル: TypeTests.cs プロジェクト: mParticle/mparticle-json
        public void TypeCombinedSchemaTests()
        {
            var schema = new MPSchema(
                MPJson.Object(
                    MPJson.Property("type", MPJson.Array("integer", "array", "string"))
                    )
                );

            Assert.True(schema.IsValid);
            Assert.False(schema.Validate(123.2));
            Assert.True(schema.Validate(54));
            Assert.False(schema.Validate(false));
            Assert.False(schema.Validate(true));
            Assert.False(schema.Validate(MPJson.Null));
            Assert.True(schema.Validate("x"));
            Assert.False(schema.Validate(MPJson.Object()));
            Assert.True(schema.Validate(MPJson.Array()));
        }
コード例 #2
0
ファイル: TypeTests.cs プロジェクト: mParticle/mparticle-json
        public void SchemaEnumTest()
        {
            var schema = new MPSchema(
                MPJson.Object(
                    MPJson.Property("enum", MPJson.Array(true, 54, MPJson.Array()))
                    )
                );

            Assert.True(schema.IsValid);
            Assert.False(schema.Validate(123.2));
            Assert.True(schema.Validate(54));
            Assert.False(schema.Validate(false));
            Assert.True(schema.Validate(true));
            Assert.False(schema.Validate(MPJson.Null));
            Assert.False(schema.Validate("x"));
            Assert.False(schema.Validate(MPJson.Object()));
            Assert.True(schema.Validate(MPJson.Array()));
        }
コード例 #3
0
        public void ObjectTest()
        {
            MPJson obj = MPJson.Object(
                MPJson.Property("a", 1),
                MPJson.Property("b", 2),
                MPJson.Property("c", 3)
                );

            Assert.Equal(JsonType.Object, obj.Type);
            Assert.True(obj.HasValue);
            Assert.False(obj.IsUndefined);
            Assert.Equal(1.0, obj["a"]);
            Assert.Equal(2.0, obj["b"]);
            Assert.Equal(3.0, obj["c"]);
            Assert.Equal(JsonType.Undefined, obj[0].Type);
            Assert.Equal(JsonType.Undefined, obj["d"].Type);
            Assert.Equal("{ \"a\":1, \"b\":2, \"c\":3 }", obj.ToString());
            Assert.Equal(3, obj.Keys.Count());
        }
コード例 #4
0
        public void AdditionalItemsFalseValidationTest()
        {
            MPSchema schema = MPJson.Object(
                MPJson.Property("items",
                                MPJson.Array(
                                    MPJson.Object(MPJson.Property("type", "number")),
                                    MPJson.Object(MPJson.Property("type", "string")),
                                    MPJson.Object(MPJson.Property("type", "boolean"))
                                    )),
                MPJson.Property("additionalItems",
                                false)
                );

            Assert.True(schema.IsValid);
            Assert.True(schema.Validate(MPJson.Array(0)));
            Assert.True(schema.Validate(MPJson.Array(2, "b")));
            Assert.True(schema.Validate(MPJson.Array(1, "a", true)));
            Assert.False(schema.Validate(MPJson.Array(3, "c", false, "x")));
            Assert.False(schema.Validate(MPJson.Array(3, "c", false, MPJson.Null)));
        }
コード例 #5
0
        public void ItemsTupleValidationTest()
        {
            var schema = SingletonSchema("items",
                                         MPJson.Array(
                                             MPJson.Object(MPJson.Property("type", "number")),
                                             MPJson.Object(MPJson.Property("type", "string")),
                                             MPJson.Object(MPJson.Property("type", "boolean"))
                                             ));

            Assert.True(schema.IsValid);
            Assert.True(schema.Validate(MPJson.Array(0)));
            Assert.True(schema.Validate(MPJson.Array(2, "b")));
            Assert.True(schema.Validate(MPJson.Array(1, "a", true)));
            Assert.True(schema.Validate(MPJson.Array(3, "c", false, "x")));
            Assert.True(schema.Validate(MPJson.Array(3, "c", false, MPJson.Null)));
            Assert.False(schema.Validate(MPJson.Array("a")));
            Assert.False(schema.Validate(MPJson.Array(2, 3)));
            Assert.False(schema.Validate(MPJson.Array(1, "a", 2)));
            Assert.False(schema.Validate(MPJson.Array("a", "c", false, "x")));
        }
コード例 #6
0
        public void IfThenElseTest()
        {
            MPSchema schema = new MPSchema(
                MPJson.Object(
                    MPJson.Property("if", m2),
                    MPJson.Property("then", m3),
                    MPJson.Property("else", m5)
                    ));

            Assert.True(schema.IsValid);

            // if T then T else T
            Assert.True(schema.Validate(0));
            Assert.True(schema.Validate(30));
            Assert.True(schema.Validate(60));
            Assert.True(schema.Validate("Not a number"));

            // if T then T else F
            Assert.True(schema.Validate(6));

            // if T then F else T
            Assert.False(schema.Validate(10));

            // if T then F else F
            Assert.False(schema.Validate(2));

            // if F then T else T
            Assert.True(schema.Validate(15));

            // if F then T else F
            Assert.False(schema.Validate(21));

            // if F then T else F
            Assert.False(schema.Validate(3));

            // if F then F else F
            Assert.False(schema.Validate(1));
        }
コード例 #7
0
        public void JsonMatchesObjectsTest()
        {
            MPJson j1 = MPJson.Object();
            MPJson j3 = MPJson.Object(
                MPJson.Property("a", 1),
                MPJson.Property("b", 2),
                MPJson.Property("c", 3)
                );
            MPJson j3b = MPJson.Object(
                MPJson.Property("c", 3),
                MPJson.Property("b", 2),
                MPJson.Property("a", 1)
                );
            MPJson j3c = MPJson.Object(
                MPJson.Property("c", 1),
                MPJson.Property("b", 2),
                MPJson.Property("a", 3)
                );

            Assert.NotEqual(j1, j3);
            Assert.NotEqual(j3, j3c);
            Assert.Equal(j3, j3b);
        }
コード例 #8
0
 MPSchema SimpleSchema(string keyword, MPJson json)
 {
     return(new MPSchema(MPJson.Object(MPJson.Property(keyword, json))));
 }
コード例 #9
0
 MPSchema SingletonSchema(string keyword, MPJson json)
 {
     return(MPJson.Object(MPJson.Property(keyword, json)));
 }