Ejemplo n.º 1
0
        public async void ValidateJsonStructure_WithNotNullElementAndNotGivenValueInsideJson_ShouldReturnFalse()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    new Field
                    {
                        Id       = "test_city",
                        Name     = "city",
                        DataType = DataTypeEnum.String,
                        Nullable = false
                    },
                    new Field
                    {
                        Id       = "test_country",
                        Name     = "country",
                        DataType = DataTypeEnum.String,
                        Nullable = false
                    }
                }
            };

            Assert.False(await structure.ValidateJsonStructure(new { city = "Tabriz" }));
        }
Ejemplo n.º 2
0
        public async void ValidateJsonStructure_WithNullableIntegerAndNotNullableStringWithWrongValue_ShouldReturnFalse()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    new Field
                    {
                        Id       = "test_age",
                        Name     = "age",
                        DataType = DataTypeEnum.Integer,
                        Nullable = true
                    },
                    new Field
                    {
                        Id       = "test_name",
                        Name     = "name",
                        DataType = DataTypeEnum.String,
                        Nullable = false
                    }
                }
            };

            Assert.False(await structure.ValidateJsonStructure(new { name = "Yashar", age = "gfh" }));
        }
Ejemplo n.º 3
0
        public async void ValidateJsonStructure_WithNotNullElementAndFullValueInsideJson_ShouldReturnTrue()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    Field.NotNullString("test_city", "city"),
                    Field.NotNullString("test_country", "country")
                }
            };

            Assert.True(await structure.ValidateJsonStructure(new { city = "Tabriz", country = "Iran" }));
        }
Ejemplo n.º 4
0
        public async void ValidateJsonStructure_WithSimpleInteger_ShouldValidate()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    new Field
                    {
                        Id        = "test_age",
                        Name      = "age",
                        DataType  = DataTypeEnum.Integer,
                        Structure = null
                    }
                }
            };

            Assert.True(await structure.ValidateJsonStructure(new { age = 34 }));
        }
Ejemplo n.º 5
0
        public async void ValidateJsonStructure_WithBase64ElementInStructureAndWrongDataInsideJson_ShouldReturnFalse()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    new Field
                    {
                        Id       = "test_binary",
                        Name     = "binary",
                        DataType = DataTypeEnum.Binary,
                        Nullable = false
                    }
                }
            };

            Assert.False(await structure.ValidateJsonStructure(new { binary = "123" }));
        }
Ejemplo n.º 6
0
        public async void ValidateJsonStructure_WithSimpleStringAndIntegerInput_ShouldNotValidate()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    new Field
                    {
                        Id        = "test_name",
                        Name      = "name",
                        DataType  = DataTypeEnum.String,
                        Structure = null
                    }
                }
            };

            Assert.False(await structure.ValidateJsonStructure(new { name = 34 }));
        }
Ejemplo n.º 7
0
        public async void ValidateJsonStructure_WithTimeElementInStructureAndInsideJson_ShouldReturnTrue()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    new Field
                    {
                        Id       = "test_time",
                        Name     = "time",
                        DataType = DataTypeEnum.Time,
                        Nullable = false
                    }
                }
            };

            Assert.True(await structure.ValidateJsonStructure(new { time = "12:30" }));
        }
Ejemplo n.º 8
0
        public async void ValidateJsonStructure_WithSimpleString_ShouldValidate()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    new Field
                    {
                        Id        = "test_name",
                        Name      = "name",
                        DataType  = DataTypeEnum.String,
                        Structure = null
                    }
                }
            };

            Assert.True(await structure.ValidateJsonStructure(new { name = "Yashar" }));
        }
Ejemplo n.º 9
0
        public async void ValidateJsonStructure_WithNullableInteger_ShouldReturnTrue()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    new Field
                    {
                        Id        = "test_age",
                        Name      = "age",
                        DataType  = DataTypeEnum.Integer,
                        Nullable  = true,
                        Structure = null
                    }
                }
            };

            Assert.True(await structure.ValidateJsonStructure(new { name = "Yashar" }));
        }
Ejemplo n.º 10
0
        public async void ValidateJsonStructure_WithObjectInStructureAndWrongInput_ShouldReturnFalse()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    new Field
                    {
                        Id        = "test_address",
                        Name      = "address",
                        DataType  = DataTypeEnum.Object,
                        Nullable  = false,
                        Structure = new StructureDefinition
                        {
                            Id     = "address",
                            Name   = "address",
                            Fields = new List <Field>
                            {
                                new Field
                                {
                                    Id       = "test_city",
                                    Name     = "city",
                                    DataType = DataTypeEnum.String,
                                    Nullable = false
                                },
                                new Field
                                {
                                    Id       = "test_country",
                                    Name     = "country",
                                    DataType = DataTypeEnum.String,
                                    Nullable = false
                                }
                            }
                        }
                    }
                }
            };

            Assert.False(await structure.ValidateJsonStructure(new { name = "Yashar", age = "gfh" }));
        }