Example #1
0
        public async Task CanCreate_should_throw_exception_if_ui_field_is_invalid()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <UpsertSchemaField>
                {
                    new UpsertSchemaField
                    {
                        Name       = "field1",
                        Properties = new UIFieldProperties
                        {
                            IsListField      = true,
                            IsReferenceField = true,
                        },
                        IsHidden     = true,
                        IsDisabled   = true,
                        Partitioning = Partitioning.Invariant.Key
                    }
                },
                Name = "new-schema"
            };

            await ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                               new ValidationError("UI field cannot be a list field.",
                                                                   "Fields[1].Properties.IsListField"),
                                               new ValidationError("UI field cannot be a reference field.",
                                                                   "Fields[1].Properties.IsReferenceField"),
                                               new ValidationError("UI field cannot be hidden.",
                                                                   "Fields[1].IsHidden"),
                                               new ValidationError("UI field cannot be disabled.",
                                                                   "Fields[1].IsDisabled"));
        }
Example #2
0
        public async Task CanCreate_should_throw_exception_if_nested_field_is_array()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <UpsertSchemaField>
                {
                    new UpsertSchemaField
                    {
                        Name         = "array",
                        Properties   = new ArrayFieldProperties(),
                        Partitioning = Partitioning.Invariant.Key,
                        Nested       = new List <UpsertSchemaNestedField>
                        {
                            new UpsertSchemaNestedField
                            {
                                Name       = "nested1",
                                Properties = new ArrayFieldProperties()
                            }
                        }
                    }
                },
                Name = "new-schema"
            };

            await ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                               new ValidationError("Nested field cannot be array fields.",
                                                                   "Fields[1].Nested[1].Properties"));
        }
Example #3
0
        public Task CanCreate_should_throw_exception_if_nested_field_name_invalid()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <CreateSchemaField>
                {
                    new CreateSchemaField
                    {
                        Name         = "array",
                        Properties   = new ArrayFieldProperties(),
                        Partitioning = Partitioning.Invariant.Key,
                        Nested       = new List <CreateSchemaNestedField>
                        {
                            new CreateSchemaNestedField
                            {
                                Name       = "invalid name",
                                Properties = new StringFieldProperties()
                            }
                        }
                    }
                },
                Name = "new-schema"
            };

            return(ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                                new ValidationError("Field name must be a valid javascript property name.",
                                                                    "Fields[1].Nested[1].Name")));
        }
        public async Task CanAssign_should_throw_exception_if_contributor_id_is_null()
        {
            var command = new AssignContributor();

            await ValidationAssert.ThrowsAsync(() => GuardAppContributors.CanAssign(command, App(contributors_0), users, appPlan),
                                               new ValidationError("Contributor ID or email is required.", "ContributorId"));
        }
Example #5
0
        public async Task CanCreate_should_throw_exception_if_data_is_null()
        {
            var command = new CreateContent();

            await ValidationAssert.ThrowsAsync(() => GuardContent.CanCreate(schema, contentWorkflow, command),
                                               new ValidationError("Data is required.", "Data"));
        }
Example #6
0
        public async Task CanUpdate_should_throw_exception_if_action_and_trigger_are_null()
        {
            var command = new UpdateRule();

            await ValidationAssert.ThrowsAsync(() => GuardRule.CanUpdate(command, appId.Id, appProvider),
                                               new ValidationError("Either trigger or action is required.", "Trigger", "Action"));
        }
        public Task CanCreate_should_throw_exception_if_fields_contains_duplicate_name()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <UpsertSchemaField>
                {
                    new UpsertSchemaField
                    {
                        Name         = "field1",
                        Properties   = new StringFieldProperties(),
                        Partitioning = Partitioning.Invariant.Key
                    },
                    new UpsertSchemaField
                    {
                        Name         = "field1",
                        Properties   = new StringFieldProperties(),
                        Partitioning = Partitioning.Invariant.Key
                    }
                },
                Name = "new-schema"
            };

            return(ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                                new ValidationError("Fields cannot have duplicate names.",
                                                                    "Fields")));
        }
Example #8
0
        public Task CanCreate_should_throw_exception_if_nested_field_properties_not_valid()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <CreateSchemaField>
                {
                    new CreateSchemaField
                    {
                        Name         = "array",
                        Properties   = new ArrayFieldProperties(),
                        Partitioning = Partitioning.Invariant.Key,
                        Nested       = new List <CreateSchemaNestedField>
                        {
                            new CreateSchemaNestedField
                            {
                                Name       = "nested1",
                                Properties = new StringFieldProperties {
                                    MinLength = 10, MaxLength = 5
                                }
                            }
                        }
                    }
                },
                Name = "new-schema"
            };

            return(ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                                new ValidationError("Max length must be greater than min length.",
                                                                    "Fields[1].Nested[1].Properties.MinLength",
                                                                    "Fields[1].Nested[1].Properties.MaxLength")));
        }
Example #9
0
        public Task CanAssign_should_throw_exception_if_contributor_id_is_null()
        {
            var command = new AssignContributor();

            return(ValidationAssert.ThrowsAsync(() => GuardAppContributors.CanAssign(contributors_0, command, users, appPlan, roles),
                                                new ValidationError("Contributor id is required.", "ContributorId")));
        }
Example #10
0
        public Task CanCreate_should_throw_exception_if_nested_field_properties_null()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <CreateSchemaField>
                {
                    new CreateSchemaField
                    {
                        Name         = "array",
                        Properties   = new ArrayFieldProperties(),
                        Partitioning = Partitioning.Invariant.Key,
                        Nested       = new List <CreateSchemaNestedField>
                        {
                            new CreateSchemaNestedField
                            {
                                Name       = "nested1",
                                Properties = null
                            }
                        }
                    }
                },
                Name = "new-schema"
            };

            return(ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                                new ValidationError("Field properties is required.",
                                                                    "Fields[1].Nested[1].Properties")));
        }
Example #11
0
        public Task CanCreate_should_throw_exception_if_nested_field_have_duplicate_names()
        {
            var command = new CreateSchema
            {
                AppId  = appId,
                Fields = new List <CreateSchemaField>
                {
                    new CreateSchemaField
                    {
                        Name         = "array",
                        Properties   = new ArrayFieldProperties(),
                        Partitioning = Partitioning.Invariant.Key,
                        Nested       = new List <CreateSchemaNestedField>
                        {
                            new CreateSchemaNestedField
                            {
                                Name       = "nested1",
                                Properties = new StringFieldProperties()
                            },
                            new CreateSchemaNestedField
                            {
                                Name       = "nested1",
                                Properties = new StringFieldProperties()
                            }
                        }
                    }
                },
                Name = "new-schema"
            };

            return(ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                                new ValidationError("Fields cannot have duplicate names.",
                                                                    "Fields[1].Nested")));
        }
Example #12
0
        public async Task CanMove_should_throw_exception_when_folder_has_not_changed()
        {
            var command = new MoveAsset {
                ParentId = Guid.NewGuid()
            };

            await ValidationAssert.ThrowsAsync(() => GuardAsset.CanMove(command, assetQuery, command.ParentId),
                                               new ValidationError("Asset is already part of this folder.", "ParentId"));
        }
Example #13
0
        public async Task CanUpdate_should_throw_exception_if_data_is_null()
        {
            var content = CreateContent(Status.Draft);

            var command = CreateCommand(new UpdateContent());

            await ValidationAssert.ThrowsAsync(() => GuardContent.CanUpdate(command, content, workflow),
                                               new ValidationError("Data is required.", "Data"));
        }
Example #14
0
        public Task CanCreate_should_throw_exception_if_name_already_in_use()
        {
            var command = new CreateSchema {
                AppId = appId, Name = "existing"
            };

            return(ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                                new ValidationError("A schema with the same name already exists.")));
        }
Example #15
0
        public Task CanAssign_should_throw_exception_if_role_not_valid()
        {
            var command = new AssignContributor {
                ContributorId = "1", Role = "Invalid"
            };

            return(ValidationAssert.ThrowsAsync(() => GuardAppContributors.CanAssign(contributors_0, command, users, appPlan, roles),
                                                new ValidationError("Role is not a valid value.", "Role")));
        }
Example #16
0
        public Task CanCreate_should_throw_exception_if_name_not_valid()
        {
            var command = new CreateApp {
                Name = "INVALID NAME"
            };

            return(ValidationAssert.ThrowsAsync(() => GuardApp.CanCreate(command, apps),
                                                new ValidationError("Name must be a valid slug.", "Name")));
        }
Example #17
0
        public Task CanCreate_should_throw_exception_if_name_already_in_use()
        {
            var command = new CreateApp {
                Name = "existing"
            };

            return(ValidationAssert.ThrowsAsync(() => GuardApp.CanCreate(command, apps),
                                                new ValidationError("An app with the same name already exists.", "Name")));
        }
Example #18
0
        public Task CanCreate_should_throw_exception_if_name_not_valid()
        {
            var command = new CreateSchema {
                AppId = appId, Name = "INVALID NAME"
            };

            return(ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
                                                new ValidationError("Name is not a valid slug.", "Name")));
        }
Example #19
0
        public Task CanAssign_should_throw_exception_if_permission_not_valid()
        {
            var command = new AssignContributor {
                ContributorId = "1", Permission = (AppContributorPermission)10
            };

            return(ValidationAssert.ThrowsAsync(() => GuardAppContributors.CanAssign(contributors_0, command, users, appPlan),
                                                new ValidationError("Permission is not valid.", "Permission")));
        }
        public async Task CanCreate_should_throw_exception_when_folder_name_not_defined()
        {
            var command = new CreateAssetFolder();

            A.CallTo(() => assetQuery.FindAssetFolderAsync(command.ParentId))
            .Returns(new List <IAssetFolderEntity>());

            await ValidationAssert.ThrowsAsync(() => GuardAssetFolder.CanCreate(command, assetQuery),
                                               new ValidationError("Folder name is required.", "FolderName"));
        }
Example #21
0
        public async Task CanChangeStatus_should_throw_exception_if_publishing_without_pending_changes()
        {
            var content = CreateContent(Status.Published, false);
            var command = new ChangeContentStatus {
                Status = Status.Published
            };

            await ValidationAssert.ThrowsAsync(() => GuardContent.CanChangeStatus(schema, content, contentWorkflow, command, true),
                                               new ValidationError("Content has no changes to publish.", "Status"));
        }
Example #22
0
        public async Task CanUpdate_should_throw_exception_if_rule_has_already_this_name()
        {
            var command = new UpdateRule
            {
                Name = "MyName"
            };

            await ValidationAssert.ThrowsAsync(() => GuardRule.CanUpdate(command, appId.Id, appProvider, rule_0),
                                               new ValidationError("Rule has already this name.", "Name"));
        }
Example #23
0
        public async Task CanPatch_should_throw_exception_if_data_is_null()
        {
            SetupCanUpdate(true);

            var content = CreateContent(Status.Draft);
            var command = new PatchContent();

            await ValidationAssert.ThrowsAsync(() => GuardContent.CanPatch(content, contentWorkflow, command),
                                               new ValidationError("Data is required.", "Data"));
        }
Example #24
0
        public Task CanAssign_should_throw_exception_if_user_already_exists_with_same_role()
        {
            var command = new AssignContributor {
                ContributorId = "1", Role = Role.Owner
            };

            var contributors_1 = contributors_0.Assign("1", Role.Owner);

            return(ValidationAssert.ThrowsAsync(() => GuardAppContributors.CanAssign(contributors_1, command, users, appPlan, roles),
                                                new ValidationError("Contributor has already this role.", "Role")));
        }
Example #25
0
        public Task CanAssign_should_throw_exception_if_user_already_exists_with_same_permission()
        {
            var command = new AssignContributor {
                ContributorId = "1"
            };

            var contributors_1 = contributors_0.Assign("1", AppContributorPermission.Owner);

            return(ValidationAssert.ThrowsAsync(() => GuardAppContributors.CanAssign(contributors_1, command, users, appPlan),
                                                new ValidationError("Contributor has already this permission.", "Permission")));
        }
        public async Task CanMove_should_throw_exception_when_folder_not_found()
        {
            var command = new MoveAssetFolder {
                ParentId = Guid.NewGuid()
            };

            A.CallTo(() => assetQuery.FindAssetFolderAsync(command.ParentId))
            .Returns(new List <IAssetFolderEntity>());

            await ValidationAssert.ThrowsAsync(() => GuardAssetFolder.CanMove(command, assetQuery, Guid.NewGuid(), Guid.NewGuid()),
                                               new ValidationError("Asset folder does not exist.", "ParentId"));
        }
Example #27
0
        public async Task CanUpdate_should_throw_exception_if_data_is_null()
        {
            var schema = CreateSchema(false);

            SetupCanUpdate(true);

            var content = CreateContent(Status.Draft, false);
            var command = new UpdateContent();

            await ValidationAssert.ThrowsAsync(() => GuardContent.CanUpdate(content, contentWorkflow, command, false),
                                               new ValidationError("Data is required.", "Data"));
        }
Example #28
0
        public async Task Should_throw_exception_if_moving_to_invalid_folder()
        {
            var parentId = DomainId.NewGuid();

            var operation = Operation(CreateAssetFolder());

            A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, parentId, A <CancellationToken> ._))
            .Returns(new List <IAssetFolderEntity>());

            await ValidationAssert.ThrowsAsync(() => operation.MustMoveToValidFolder(parentId),
                                               new ValidationError("Asset folder does not exist.", "ParentId"));
        }
Example #29
0
        public async Task CanMove_should_throw_exception_if_folder_not_found()
        {
            var command = new MoveAssetFolder {
                AppId = appId, ParentId = DomainId.NewGuid()
            };

            A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId, A <CancellationToken> ._))
            .Returns(new List <IAssetFolderEntity>());

            await ValidationAssert.ThrowsAsync(() => GuardAssetFolder.CanMove(command, AssetFolder(), assetQuery),
                                               new ValidationError("Asset folder does not exist.", "ParentId"));
        }
Example #30
0
        public async Task CanCreate_should_throw_exception_when_folder_not_found()
        {
            var command = new CreateAsset {
                AppId = appId, ParentId = DomainId.NewGuid()
            };

            A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId))
            .Returns(new List <IAssetFolderEntity>());

            await ValidationAssert.ThrowsAsync(() => GuardAsset.CanCreate(command, assetQuery),
                                               new ValidationError("Asset folder does not exist.", "ParentId"));
        }