public static async Task <ContentOperationContext> CreateAsync(
            Guid appId,
            Guid schemaId,
            ContentCommand command,
            IAppProvider appProvider,
            IAssetRepository assetRepository,
            IContentRepository contentRepository,
            IScriptEngine scriptEngine,
            Func <string> message)
        {
            var(appEntity, schemaEntity) = await appProvider.GetAppWithSchemaAsync(appId, schemaId);

            var context = new ContentOperationContext
            {
                appEntity         = appEntity,
                assetRepository   = assetRepository,
                command           = command,
                contentRepository = contentRepository,
                message           = message,
                schemaId          = schemaId,
                schemaEntity      = schemaEntity,
                scriptEngine      = scriptEngine
            };

            return(context);
        }
        public ContentCommandMiddlewareTests()
        {
            var schemaDef =
                new Schema("my-schema")
                .AddField(new NumberField(1, "my-field1", Partitioning.Invariant,
                                          new NumberFieldProperties {
                IsRequired = true
            }))
                .AddField(new NumberField(2, "my-field2", Partitioning.Invariant,
                                          new NumberFieldProperties {
                IsRequired = false
            }));

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

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

            A.CallTo(() => appProvider.GetAppAsync(AppName)).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(() => appProvider.GetAppWithSchemaAsync(AppId, SchemaId)).Returns((app, schema));
        }
示例#3
0
        public static async Task <ContentOperationContext> CreateAsync(
            IContentRepository contentRepository,
            ContentDomainObject content,
            ContentCommand command,
            IAppProvider appProvider,
            IAssetRepository assetRepository,
            IScriptEngine scriptEngine,
            Func <string> message)
        {
            var a = content.Snapshot.AppId;
            var s = content.Snapshot.SchemaId;

            if (command is CreateContent createContent)
            {
                a = a ?? createContent.AppId;
                s = s ?? createContent.SchemaId;
            }

            var(appEntity, schemaEntity) = await appProvider.GetAppWithSchemaAsync(a.Id, s.Id);

            var context = new ContentOperationContext
            {
                appEntity         = appEntity,
                assetRepository   = assetRepository,
                contentRepository = contentRepository,
                content           = content,
                command           = command,
                message           = message,
                schemaEntity      = schemaEntity,
                scriptEngine      = scriptEngine
            };

            return(context);
        }
示例#4
0
        public ContentGrainTests()
        {
            var schemaDef =
                new Schema("my-schema")
                .AddNumber(1, "my-field1", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsRequired = true
            })
                .AddNumber(2, "my-field2", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsRequired = false
            });

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

            A.CallTo(() => appProvider.GetAppAsync(AppName)).Returns(app);
            A.CallTo(() => appProvider.GetAppWithSchemaAsync(AppId, SchemaId)).Returns((app, schema));

            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(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .Ignored, A <string> .Ignored))
            .ReturnsLazily(x => x.GetArgument <ScriptContext>(0).Data);

            patched = patch.MergeInto(data);

            sut = new ContentGrain(Store, A.Dummy <ISemanticLog>(), appProvider, A.Dummy <IAssetRepository>(), scriptEngine, A.Dummy <IContentRepository>());
            sut.OnActivateAsync(Id).Wait();
        }
示例#5
0
        public ContentDomainObjectTests()
        {
            app = Mocks.App(AppNamedId, Language.DE);

            var scripts = new SchemaScripts
            {
                Change = "<change-script>",
                Create = "<create-script>",
                Delete = "<delete-script>",
                Update = "<update-script>"
            };

            var schemaDef =
                new Schema("my-schema")
                .AddNumber(1, "my-field1", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsRequired = true
            })
                .AddNumber(2, "my-field2", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsRequired = false
            })
                .SetScripts(scripts);

            schema = Mocks.Schema(AppNamedId, SchemaNamedId, schemaDef);

            A.CallTo(() => appProvider.GetAppAsync(AppName, false))
            .Returns(app);

            A.CallTo(() => appProvider.GetAppWithSchemaAsync(AppId, SchemaId, false))
            .Returns((app, schema));

            A.CallTo(() => scriptEngine.TransformAsync(A <ScriptVars> ._, A <string> ._, ScriptOptions()))
            .ReturnsLazily(x => Task.FromResult(x.GetArgument <ScriptVars>(0) !.Data !));

            patched = patch.MergeInto(data);

            var validators = Enumerable.Repeat(new DefaultValidatorsFactory(), 1);

            var context = new ContentOperationContext(
                appProvider,
                validators,
                contentWorkflow,
                contentRepository,
                TestUtils.DefaultSerializer,
                scriptEngine, A.Fake <ISemanticLog>());

            sut = new ContentDomainObject(Store, A.Dummy <ISemanticLog>(), context);
            sut.Setup(Id);
        }
        public ContentGrainTests()
        {
            var schemaDef =
                new Schema("my-schema")
                .AddField(new NumberField(1, "my-field1", Partitioning.Invariant,
                                          new NumberFieldProperties {
                IsRequired = true
            }))
                .AddField(new NumberField(2, "my-field2", Partitioning.Invariant,
                                          new NumberFieldProperties {
                IsRequired = false
            }));

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

            A.CallTo(() => appProvider.GetAppAsync(AppName)).Returns(app);
            A.CallTo(() => appProvider.GetAppWithSchemaAsync(AppId, SchemaId)).Returns((app, schema));

            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(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .That.Matches(x => ReferenceEquals(x.Data, data)), A <string> .Ignored))
            .Returns(data);

            A.CallTo(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .That.Matches(x => ReferenceEquals(x.Data, invalidData)), A <string> .Ignored))
            .Returns(invalidData);

            A.CallTo(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .That.Matches(x => ReferenceEquals(x.Data, patch)), A <string> .Ignored))
            .Returns(patch);

            A.CallTo(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .That.Matches(x => ReferenceEquals(x.Data, otherData)), A <string> .Ignored))
            .Returns(otherData);

            patched = patch.MergeInto(data);

            sut = new ContentGrain(Store, appProvider, A.Dummy <IAssetRepository>(), scriptEngine, A.Dummy <IContentRepository>());
            sut.OnActivateAsync(Id).Wait();
        }
示例#7
0
        public async Task LoadAsync(NamedId <Guid> appId, NamedId <Guid> schemaId, ContentCommand command, Func <string> message, bool optimized)
        {
            var(app, schema) = await appProvider.GetAppWithSchemaAsync(appId.Id, schemaId.Id);

            if (app == null)
            {
                throw new InvalidOperationException("Cannot resolve app.");
            }

            if (schema == null)
            {
                throw new InvalidOperationException("Cannot resolve schema.");
            }

            this.app     = app;
            this.schema  = schema;
            this.command = command;
            this.message = message;

            validationContext = new ValidationContext(appId, schemaId, schema.SchemaDef, command.ContentId).Optimized(optimized);
        }
示例#8
0
        public ContentGrainTests()
        {
            app = Mocks.App(AppNamedId, Language.DE);

            var scripts = new SchemaScripts
            {
                Change = "<change-script>",
                Create = "<create-script>",
                Delete = "<delete-script>",
                Update = "<update-script>"
            };

            var schemaDef =
                new Schema("my-schema")
                .AddNumber(1, "my-field1", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsRequired = true
            })
                .AddNumber(2, "my-field2", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsRequired = false
            })
                .ConfigureScripts(scripts);

            schema = Mocks.Schema(AppNamedId, SchemaNamedId, schemaDef);

            A.CallTo(() => appProvider.GetAppAsync(AppName))
            .Returns(app);

            A.CallTo(() => appProvider.GetAppWithSchemaAsync(AppId, SchemaId))
            .Returns((app, schema));

            A.CallTo(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .Ignored, A <string> .Ignored))
            .ReturnsLazily(x => x.GetArgument <ScriptContext>(0).Data);

            patched = patch.MergeInto(data);

            sut = new ContentGrain(Store, A.Dummy <ISemanticLog>(), appProvider, A.Dummy <IAssetRepository>(), scriptEngine, contentWorkflow, contentRepository, limit);
            sut.ActivateAsync(Id).Wait();
        }
示例#9
0
        public async Task LoadAsync(NamedId <DomainId> appId, NamedId <DomainId> schemaId, ContentCommand command, bool optimized)
        {
            this.command = command;

            var(app, schema) = await appProvider.GetAppWithSchemaAsync(appId.Id, schemaId.Id);

            if (app == null)
            {
                throw new DomainObjectNotFoundException(appId.ToString());
            }

            this.app = app;

            if (schema == null)
            {
                throw new DomainObjectNotFoundException(schemaId.ToString());
            }

            this.schema = schema;

            validationContext = new ValidationContext(appId, schemaId, schema.SchemaDef, command.ContentId).Optimized(optimized);
        }
示例#10
0
        public static async Task <ContentOperationContext> CreateAsync(
            Guid appId,
            Guid schemaId,
            ContentCommand command,
            IAppProvider appProvider,
            IAssetRepository assetRepository,
            IContentRepository contentRepository,
            IScriptEngine scriptEngine,
            Func <string> message)
        {
            var(appEntity, schemaEntity) = await appProvider.GetAppWithSchemaAsync(appId, schemaId);

            if (appEntity == null)
            {
                throw new InvalidOperationException("Cannot resolve app.");
            }

            if (schemaEntity == null)
            {
                throw new InvalidOperationException("Cannot resolve schema.");
            }

            var context = new ContentOperationContext
            {
                appEntity         = appEntity,
                assetRepository   = assetRepository,
                command           = command,
                contentRepository = contentRepository,
                message           = message,
                schemaId          = schemaId,
                schemaEntity      = schemaEntity,
                scriptEngine      = scriptEngine
            };

            return(context);
        }
示例#11
0
        public static async Task <ContentOperationContext> CreateAsync(
            IContentRepository contentRepository,
            ContentDomainObject content,
            ContentCommand command,
            IAppProvider appProvider,
            IAssetRepository assetRepository,
            IScriptEngine scriptEngine,
            Func <string> message)
        {
            var(appEntity, schemaEntity) = await appProvider.GetAppWithSchemaAsync(command.AppId.Name, command.SchemaId.Id);

            var context = new ContentOperationContext();

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

            return(context);
        }