public void TestSerializeRolesSchema()
        {
            IValueSchema <string> schema = new RolesSchema()
            {
                AllowNull      = false,
                DefaultValue   = "abc",
                MaxLength      = 100,
                MinLength      = 2,
                PossibleValues = new[] { "abc", "def" }
            };
            SchemaJsonSerializationVisitor visitor = new SchemaJsonSerializationVisitor();

            schema.Accept(visitor);
            Assert.AreEqual(typeof(string), visitor.ValueType);
            Assert.AreEqual(typeof(RolesSchema), visitor.SchemaType);
            Assert.IsNotNull(visitor.JsonValue);
            Assert.AreNotEqual(0, visitor.JsonValue.Length);
        }
        public void TestDeserializeRolesSchema()
        {
            IValueSchema <string> schema = new RolesSchema
            {
                AllowNull      = true,
                DefaultValue   = "abc",
                MaxLength      = 100,
                MinLength      = 2,
                PossibleValues = new[] { "abc", "def" }
            };
            SchemaJsonSerializationVisitor visitor = new SchemaJsonSerializationVisitor();

            schema.Accept(visitor);

            IValueSchema <object> vs = JsonSchemaDeserializer.Deserialize(visitor.SchemaType, visitor.JsonValue);

            Assert.IsNotNull(vs);
            Assert.AreEqual(typeof(string), vs.Type);
        }
Пример #3
0
        /// <summary>
        /// Setup Properties with Associated Schemas in Property Set Collection
        /// </summary>
        /// <param name="collection"><see cref="IPropertySetCollection"/></param>
        /// <param name="vd"><see cref="VariableDefinition"/></param>
        public static void SetupVariable(this VariableDefinition vd, IPropertySetCollection collection)
        {
            switch (vd.VariableType)
            {
            case VariableTypeEnum.Char:
                var charSchema = collection.Schemas.SchemaFactory.Create(typeof(char));
                SetupConstraints <char?>(vd.Constraints, charSchema);
                collection.Add(vd.Name, charSchema);
                break;

            case VariableTypeEnum.Decimal:
                var doubleSchema = collection.Schemas.SchemaFactory.Create(typeof(double));
                SetupConstraints <double?>(vd.Constraints, doubleSchema);
                collection.Add(vd.Name, doubleSchema);
                break;

            case VariableTypeEnum.Int:
                var intSchema = collection.Schemas.SchemaFactory.Create(typeof(int));
                SetupConstraints <int?>(vd.Constraints, intSchema);
                collection.Add(vd.Name, intSchema);
                break;

            case VariableTypeEnum.GroupsList:
                var groupSchema = new GroupsSchema();
                SetupConstraints <string>(vd.Constraints, groupSchema.Wrap());
                collection.Add(vd.Name, groupSchema);
                break;

            case VariableTypeEnum.RolesList:
                var rolesSchema = new RolesSchema();
                SetupConstraints <string>(vd.Constraints, rolesSchema.Wrap());
                collection.Add(vd.Name, rolesSchema);
                break;

            case VariableTypeEnum.UsersList:
                var usersSchema = new UsersSchema();
                SetupConstraints <string>(vd.Constraints, usersSchema.Wrap());
                collection.Add(vd.Name, usersSchema);
                break;

            case VariableTypeEnum.String:
                var stringSchema = collection.Schemas.SchemaFactory.Create(typeof(string));
                SetupConstraints <string>(vd.Constraints, stringSchema);
                collection.Add(vd.Name, stringSchema);
                break;

            case VariableTypeEnum.Object:
                var objectSchema = collection.Schemas.SchemaFactory.Create(typeof(object));
                SetupConstraints <object>(vd.Constraints, objectSchema);
                collection.Add(vd.Name, objectSchema);
                break;

            case VariableTypeEnum.Json:
                var jsonSchema = collection.Schemas.SchemaFactory.Create(typeof(string));
                SetupConstraints <string>(vd.Constraints, jsonSchema);
                collection.Add(vd.Name, jsonSchema);
                break;

            case VariableTypeEnum.Boolean:
                var boolSchema = collection.Schemas.SchemaFactory.Create(typeof(bool));
                SetupConstraints <bool?>(vd.Constraints, boolSchema);
                collection.Add(vd.Name, boolSchema);
                break;

            case VariableTypeEnum.None:
                break;
            }
        }