Esempio n. 1
0
        public IEvent Migrate()
        {
            var scripts = new SchemaScripts();

            if (!string.IsNullOrWhiteSpace(ScriptQuery))
            {
                scripts.Query = ScriptQuery;
            }

            if (!string.IsNullOrWhiteSpace(ScriptCreate))
            {
                scripts.Create = ScriptCreate;
            }

            if (!string.IsNullOrWhiteSpace(ScriptUpdate))
            {
                scripts.Update = ScriptUpdate;
            }

            if (!string.IsNullOrWhiteSpace(ScriptDelete))
            {
                scripts.Delete = ScriptDelete;
            }

            if (!string.IsNullOrWhiteSpace(ScriptChange))
            {
                scripts.Change = ScriptChange;
            }

            return(SimpleMapper.Map(this, new SchemaScriptsConfigured {
                Scripts = scripts
            }));
        }
Esempio n. 2
0
        public void Should_configure_scripts()
        {
            var scripts = new SchemaScripts
            {
                Query = "<query-script>"
            };

            var schema_1 = schema_0.ConfigureScripts(scripts);

            Assert.Equal(scripts, schema_1.Scripts);

            Assert.Equal("<query-script>", schema_1.Scripts.Query);
        }
Esempio n. 3
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 void Should_create_events_if_scripts_configured()
        {
            var scripts = new SchemaScripts
            {
                Create = "<create-script>"
            };

            var sourceSchema = new Schema("source");
            var targetSchema = new Schema("target").ConfigureScripts(scripts);

            var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);

            events.ShouldHaveSameEvents(
                new SchemaScriptsConfigured {
                Scripts = scripts
            }
                );
        }
Esempio n. 5
0
        public void Should_configure_scripts()
        {
            var scripts1 = new SchemaScripts
            {
                Query = "<query-script>"
            };
            var scripts2 = new SchemaScripts
            {
                Query = "<query-script>"
            };

            var schema_1 = schema_0.ConfigureScripts(scripts1);
            var schema_2 = schema_1.ConfigureScripts(scripts2);

            Assert.Equal("<query-script>", schema_1.Scripts.Query);

            Assert.Equal(scripts1, schema_1.Scripts);
            Assert.Equal(scripts1, schema_2.Scripts);
            Assert.Same(schema_1, schema_2);
        }
Esempio n. 6
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();
        }
Esempio n. 7
0
        public SchemaBuilder WithScripts(SchemaScripts scripts)
        {
            command.Scripts = scripts;

            return(this);
        }