Пример #1
0
        public static async Task <ContentOperationContext> CreateAsync(
            IContentRepository contentRepository,
            ContentDomainObject content,
            ContentCommand command,
            IAppProvider appProvider,
            ISchemaProvider schemas,
            IScriptEngine scriptEngine,
            IAssetRepository assetRepository,
            Func <string> message)
        {
            var taskForApp    = appProvider.FindAppByIdAsync(command.AppId.Id);
            var taskForSchema = schemas.FindSchemaByIdAsync(command.SchemaId.Id);

            await Task.WhenAll(taskForApp, taskForSchema);

            var context = new ContentOperationContext();

            context.appEntity         = taskForApp.Result;
            context.assetRepository   = assetRepository;
            context.contentRepository = contentRepository;
            context.content           = content;
            context.command           = command;
            context.message           = message;
            context.schemaEntity      = taskForSchema.Result;
            context.scriptEngine      = scriptEngine;

            return(context);
        }
        public ContentCommandMiddlewareTests()
        {
            var schemaDef =
                Schema.Create("my-schema", new SchemaProperties())
                .AddOrUpdateField(new NumberField(1, "my-field", Partitioning.Invariant,
                                                  new NumberFieldProperties {
                IsRequired = true
            }));

            content = new ContentDomainObject(contentId, -1);

            sut = new ContentCommandMiddleware(Handler, appProvider, A.Dummy <IAssetRepository>(), schemas, scriptEngine, A.Dummy <IContentRepository>());

            A.CallTo(() => app.LanguagesConfig).Returns(languagesConfig);
            A.CallTo(() => app.PartitionResolver).Returns(languagesConfig.ToResolver());

            A.CallTo(() => appProvider.FindAppByIdAsync(AppId)).Returns(app);

            A.CallTo(() => schema.SchemaDef).Returns(schemaDef);
            A.CallTo(() => schema.ScriptCreate).Returns("<create-script>");
            A.CallTo(() => schema.ScriptChange).Returns("<change-script>");
            A.CallTo(() => schema.ScriptUpdate).Returns("<update-script>");
            A.CallTo(() => schema.ScriptDelete).Returns("<delete-script>");

            A.CallTo(() => schemas.FindSchemaByIdAsync(SchemaId, false)).Returns(schema);
        }
Пример #3
0
        private async Task ValidateAsync(ContentDataCommand command, Func <string> message, bool enrich = false)
        {
            Guard.Valid(command, nameof(command), message);

            var taskForApp    = appProvider.FindAppByIdAsync(command.AppId.Id);
            var taskForSchema = schemas.FindSchemaByIdAsync(command.SchemaId.Id);

            await Task.WhenAll(taskForApp, taskForSchema);

            var languages = new HashSet <Language>(taskForApp.Result.Languages);

            var schemaObject = taskForSchema.Result.Schema;
            var schemaErrors = new List <ValidationError>();

            await command.Data.ValidateAsync(schemaObject, languages, schemaErrors);

            if (schemaErrors.Count > 0)
            {
                throw new ValidationException(message(), schemaErrors);
            }

            if (enrich)
            {
                command.Data.Enrich(schemaObject, languages);
            }
        }
Пример #4
0
        public ContentCommandMiddlewareTests()
        {
            var schema =
                Schema.Create("my-schema", new SchemaProperties())
                .AddOrUpdateField(new NumberField(1, "my-field", Partitioning.Invariant,
                                                  new NumberFieldProperties {
                IsRequired = true
            }));

            content = new ContentDomainObject(contentId, -1);

            sut = new ContentCommandMiddleware(Handler, appProvider, A.Dummy <IAssetRepository>(), schemaProvider, A.Dummy <IContentRepository>());

            A.CallTo(() => appEntity.LanguagesConfig).Returns(languagesConfig);
            A.CallTo(() => appEntity.PartitionResolver).Returns(languagesConfig.ToResolver());
            A.CallTo(() => appProvider.FindAppByIdAsync(AppId)).Returns(Task.FromResult(appEntity));

            A.CallTo(() => schemaEntity.Schema).Returns(schema);
            A.CallTo(() => schemaProvider.FindSchemaByIdAsync(SchemaId, false)).Returns(Task.FromResult(schemaEntity));
        }
        private async Task ValidateAsync(ContentDataCommand command, Func <string> message, bool enrich = false)
        {
            Guard.Valid(command, nameof(command), message);

            var taskForApp    = appProvider.FindAppByIdAsync(command.AppId.Id);
            var taskForSchema = schemas.FindSchemaByIdAsync(command.SchemaId.Id);

            await Task.WhenAll(taskForApp, taskForSchema);

            var schemaObject = taskForSchema.Result.Schema;
            var schemaErrors = new List <ValidationError>();

            var appId = command.AppId.Id;

            var validationContext =
                new ValidationContext(
                    (contentIds, schemaId) =>
            {
                return(contentRepository.QueryNotFoundAsync(appId, schemaId, contentIds.ToList()));
            },
                    assetIds =>
            {
                return(assetRepository.QueryNotFoundAsync(appId, assetIds.ToList()));
            });

            await command.Data.ValidateAsync(validationContext, schemaObject, taskForApp.Result.PartitionResolver, schemaErrors);

            if (schemaErrors.Count > 0)
            {
                throw new ValidationException(message(), schemaErrors);
            }

            if (enrich)
            {
                command.Data.Enrich(schemaObject, taskForApp.Result.PartitionResolver);
            }
        }