Example #1
0
        public void CanCreate_should_throw_exception_if_field_name_invalid()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <UpsertSchemaField>
                {
                    new UpsertSchemaField
                    {
                        Name         = "invalid name",
                        Properties   = new StringFieldProperties(),
                        Partitioning = Partitioning.Invariant.Key
                    }
                },
                Name = "new-schema"
            };

            ValidationAssert.Throws(() => GuardSchema.CanCreate(command),
                                    new ValidationError("Field name is not a Javascript property name.",
                                                        "Fields[1].Name"));
        }
Example #2
0
        public async Task CanCreate_should_throw_exception_if_field_properties_null()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <UpsertSchemaField>
                {
                    new UpsertSchemaField
                    {
                        Name         = "field1",
                        Properties   = null,
                        Partitioning = Partitioning.Invariant.Key
                    }
                },
                Name = "new-schema"
            };

            await ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                               new ValidationError("Field properties is required.",
                                                                   "Fields[1].Properties"));
        }
Example #3
0
        public async Task CanCreate_should_throw_exception_if_field_name_invalid()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <UpsertSchemaField>
                {
                    new UpsertSchemaField
                    {
                        Name         = "invalid name",
                        Properties   = new StringFieldProperties(),
                        Partitioning = Partitioning.Invariant.Key
                    }
                },
                Name = "new-schema"
            };

            await ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                               new ValidationError("Field name must be a valid javascript property name.",
                                                                   "Fields[1].Name"));
        }
Example #4
0
        public async Task CanCreate_should_throw_exception_if_field_partitioning_not_valid()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <UpsertSchemaField>
                {
                    new UpsertSchemaField
                    {
                        Name         = "field1",
                        Properties   = new StringFieldProperties(),
                        Partitioning = "INVALID"
                    }
                },
                Name = "new-schema"
            };

            await ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                               new ValidationError("Partitioning is not a valid value.",
                                                                   "Fields[1].Partitioning"));
        }
Example #5
0
        public Task CanCreate_should_throw_exception_if_field_properties_not_valid()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <CreateSchemaField>
                {
                    new CreateSchemaField
                    {
                        Name       = "field1",
                        Properties = new StringFieldProperties {
                            MinLength = 10, MaxLength = 5
                        },
                        Partitioning = Partitioning.Invariant.Key
                    }
                },
                Name = "new-schema"
            };

            return(ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                                new ValidationError("Max length must be greater than min length.",
                                                                    "Fields[1].Properties.MinLength",
                                                                    "Fields[1].Properties.MaxLength")));
        }
Example #6
0
        public void CanCreate_should_throw_exception_if_field_properties_not_valid()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <UpsertSchemaField>
                {
                    new UpsertSchemaField
                    {
                        Name       = "field1",
                        Properties = new StringFieldProperties {
                            MinLength = 10, MaxLength = 5
                        },
                        Partitioning = Partitioning.Invariant.Key
                    }
                },
                Name = "new-schema"
            };

            ValidationAssert.Throws(() => GuardSchema.CanCreate(command),
                                    new ValidationError("Max length must be greater or equal to min length.",
                                                        "Fields[1].Properties.MinLength",
                                                        "Fields[1].Properties.MaxLength"));
        }
Example #7
0
        public void CanDelete_should_not_throw_exception()
        {
            var command = new DeleteSchema();

            GuardSchema.CanDelete(schema_0, command);
        }
Example #8
0
        public void CanChangeCategory_should_not_throw_exception()
        {
            var command = new ChangeCategory();

            GuardSchema.CanChangeCategory(schema_0, command);
        }
Example #9
0
        public void CanUnpublish_should_throw_exception_if_already_unpublished()
        {
            var command = new UnpublishSchema();

            Assert.Throws <DomainException>(() => GuardSchema.CanUnpublish(schema_0, command));
        }
Example #10
0
        public void CanPublish_should_not_throw_exception_if_not_published()
        {
            var command = new PublishSchema();

            GuardSchema.CanPublish(schema_0, command);
        }
Example #11
0
        public Task CanCreate_should_throw_exception_if_fields_not_valid()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <CreateSchemaField>
                {
                    new CreateSchemaField
                    {
                        Name         = null,
                        Properties   = null,
                        Partitioning = "invalid"
                    },
                    new CreateSchemaField
                    {
                        Name         = null,
                        Properties   = InvalidProperties(),
                        Partitioning = "invalid"
                    },
                    new CreateSchemaField
                    {
                        Name         = null,
                        Properties   = new ArrayFieldProperties(),
                        Partitioning = "invalid",
                        Nested       = new List <CreateSchemaNestedField>
                        {
                            new CreateSchemaNestedField
                            {
                                Name       = null,
                                Properties = InvalidProperties()
                            },
                            new CreateSchemaNestedField
                            {
                                Name       = null,
                                Properties = InvalidProperties()
                            }
                        }
                    },
                    new CreateSchemaField
                    {
                        Name         = null,
                        Properties   = InvalidProperties(),
                        Partitioning = "invalid",
                        Nested       = new List <CreateSchemaNestedField>
                        {
                            new CreateSchemaNestedField
                            {
                                Name       = null,
                                Properties = InvalidProperties()
                            },
                            new CreateSchemaNestedField
                            {
                                Name       = null,
                                Properties = InvalidProperties()
                            }
                        }
                    }
                },
                Name = "new-schema"
            };

            return(Assert.ThrowsAsync <ValidationException>(() => GuardSchema.CanCreate(command, appProvider)));
        }