コード例 #1
0
        public void TestBasic()
        {
            const string schema        = @"{
    'type' : 'object',
    'properties' : {
        'foo' : {
            'type' : 'integer',
            'minimum' : 10,
            'maximum' : 15
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;
    using Cvent.SchemaToPoco.Core.ValidationAttributes;


    public class DefaultClassName
    {

        [MinValue(10)]
        [MaxValue(15)]
        public int Foo { get; set; }
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
コード例 #2
0
        public void TestBasic()
        {
            const string schema        = @"{
    'type' : 'object',
    'properties' : {
        'foo' : {
            'type' : 'string',
            'maxLength' : 10,
            'minLength' : 2
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;
    using System.ComponentModel.DataAnnotations;


    public class DefaultClassName
    {

        [StringLength(10, MinimumLength=2)]
        public string Foo { get; set; }
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
コード例 #3
0
        public void TestBasic()
        {
            const string schema        = @"{
    'type' : 'object',
    'properties' : {
        'foo' : {
            'type' : 'array',
            'items' : {
                'type' : 'string'
            },
            'uniqueItems' : true
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;
    using System.Collections.Generic;


    public class DefaultClassName
    {

        public HashSet<string> Foo { get; set; }
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
コード例 #4
0
        public void TestBasic()
        {
            const string schema        = @"{
    'type' : 'object',
    'properties' : {
        'foo' : {
            'type' : 'array',
            'items' : {
                'type' : 'string'
            },
            'minItems' : 10,
            'maxItems' : 20
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;


    public class DefaultClassName
    {

        [MinLength(10)]
        [MaxLength(20)]
        public List<string> Foo { get; set; }
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
コード例 #5
0
        public void TestBasic()
        {
            const string schema        = @"{
    'type' : 'object',
    'properties' : {
        'foo' : {
            'type' : 'string',
            'required' : true
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;
    using System.ComponentModel.DataAnnotations;


    public class DefaultClassName
    {

        [Required()]
        public string Foo { get; set; }
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
コード例 #6
0
        public void TestBasic()
        {
            const string schema        = @"{
    'type' : 'object',
    'properties' : {
        'foo' : {
            'type' : 'object',
            'enum' : ['one', '2two2', 'Three_ _third_']
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;


    public enum Foo
    {

        One,

        _2two2,

        Three__third_,
    }

    public class DefaultClassName
    {
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
コード例 #7
0
        public void TestBasic()
        {
            const string schema        = @"{
    'title' : 'NewClassName',
    'type' : 'object',
    'description' : 'Description for class!',
    'properties' : {
        'foo' : {
            'type' : 'string',
            'description' : 'Description for foo!'
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;


    // Description for class!
    public class NewClassName
    {

        // Description for foo!
        public string Foo { get; set; }
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
コード例 #8
0
        public void TestBasic()
        {
            const string schema        = @"{
    'type' : 'object',
    'properties' : {
        'foo' : {
            'type' : 'string',
            'description' : 'Match the regex \\\""dev\""\'[a-c] ',
            'pattern' : '^\\\""dev\""\'[a-c]\\s$'
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;
    using System.ComponentModel.DataAnnotations;


    public class DefaultClassName
    {

        // Match the regex ""dev""'[a-c]
        [RegularExpression(@""^\\\""""dev\""""\'[a-c]\s$"")]
        public string Foo { get; set; }
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
コード例 #9
0
        public void TestBasic()
        {
            const string schema        = @"{
    'title' : 'NewClassName',
    'type' : 'object'
}";
            const string correctResult = @"namespace generated
{
    using System;


    public class NewClassName
    {
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
コード例 #10
0
        public void TestBasic()
        {
            const string schema        = @"{
    'type' : 'object',
    'properties' : {
        'foo' : {
            'type' : 'integer',
            'minimum' : 10,
            'maximum' : 15,
            'exclusiveMinimum' : true,
            'exclusiveMaximum' : false
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;
    using Cvent.SchemaToPoco.Core.ValidationAttributes;


    public class DefaultClassName
    {

        private int _foo;

        [MinValue(11)]
        [MaxValue(15)]
        public virtual int Foo
        {
            get
            {
                return _foo;
            }
            set
            {
                _foo = value;
            }
        }
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
コード例 #11
0
        public void TestBasic()
        {
            const string schema        = @"{
    'type' : 'object',
    'properties' : {
        'foo' : {
            'type' : 'array',
            'items' : {
                'type' : 'string'
            }
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;
    using System.Collections.Generic;

    public class DefaultClassName
    {

        private List<string> _foo;

        public virtual List<string> Foo
        {
            get
            {
                return _foo;
            }
            set
            {
                _foo = value;
            }
        }
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
コード例 #12
0
        public void TestBasic()
        {
            const string schema        = @"{
    'type' : 'object',
    'properties' : {
        'foo' : {
            'type': 'string',
            'default': 'hello'
        },
        'number' : {
            'type': 'integer',
            'default': 10
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;
    
    
    public class DefaultClassName
    {
        
        public string Foo { get; set; }
        
        public int Number { get; set; }
        
        public DefaultClassName()
        {
            Foo = ""hello"";
            Number = 10;
        }
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
コード例 #13
0
        public void TestBasic()
        {
            const string schema        = @"{
    'type' : 'object',
    'properties' : {
        'foo' : {
            'type' : 'string'
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;


    public class DefaultClassName
    {

        public string Foo { get; set; }
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }
        /// <summary>
        ///     Constructor taking in command line arguments.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        public JsonSchemaToPocoCLExecutor(IEnumerable <string> args)
        {
            _settings = ConfigureCommandLineOptions(args);

            _controller = new JsonSchemaToPoco(_settings.Config);
        }
コード例 #15
0
        public void TestBasic()
        {
            const string schema        = @"{
    'type' : 'object',
    'properties' : {
        'foo' : {
            'type': 'string',
            'default': 'hello'
        },
        'number' : {
            'type': 'integer',
            'default': 10
        }
    }
}";
            const string correctResult = @"namespace generated
{
    using System;


    public class DefaultClassName
    {

        private string _foo;

        private int _number;

        public DefaultClassName()
        {
            _foo = ""hello"";
            _number = 10;
        }

        public virtual string Foo
        {
            get
            {
                return _foo;
            }
            set
            {
                _foo = value;
            }
        }

        public virtual int Number
        {
            get
            {
                return _number;
            }
            set
            {
                _number = value;
            }
        }
    }
}";

            TestBasicEquals(correctResult, JsonSchemaToPoco.Generate(schema));
        }