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));
        }
Пример #2
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));
        }
Пример #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));
        }
        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));
        }
        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));
        }
        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));
        }
Пример #14
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));
        }