Пример #1
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();
        }
        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);
        }
Пример #3
0
        public void Should_return_same_content_if_merging_same_references()
        {
            var source =
                new NamedContentData()
                .AddField("field1",
                          new ContentFieldData()
                          .AddValue("iv", 1))
                .AddField("field2",
                          new ContentFieldData()
                          .AddValue("de", 2));

            var actual = source.MergeInto(source);

            Assert.Same(source, actual);
        }
Пример #4
0
        public ContentDomainObject Patch(PatchContent command)
        {
            Guard.Valid(command, nameof(command), () => "Cannot patch content");

            VerifyCreatedAndNotDeleted();

            var newData = data.MergeInto(command.Data);

            if (!newData.Equals(data))
            {
                RaiseEvent(SimpleMapper.Map(command, new ContentUpdated {
                    Data = newData
                }));
            }

            return(this);
        }
Пример #5
0
        public void Should_merge_two_name_models()
        {
            var lhs =
                new NamedContentData()
                .AddField("field1",
                          new ContentFieldData()
                          .AddValue("iv", 1))
                .AddField("field2",
                          new ContentFieldData()
                          .AddValue("de", 2)
                          .AddValue("it", 2));

            var rhs =
                new NamedContentData()
                .AddField("field2",
                          new ContentFieldData()
                          .AddValue("it", 3)
                          .AddValue("en", 3))
                .AddField("field3",
                          new ContentFieldData()
                          .AddValue("iv", 4));

            var expected =
                new NamedContentData()
                .AddField("field1",
                          new ContentFieldData()
                          .AddValue("iv", 1))
                .AddField("field2",
                          new ContentFieldData()
                          .AddValue("it", 2)
                          .AddValue("de", 2)
                          .AddValue("en", 3))
                .AddField("field3",
                          new ContentFieldData()
                          .AddValue("iv", 4));

            var actual = lhs.MergeInto(rhs);

            Assert.Equal(expected, actual);
            Assert.NotSame(expected, rhs);
            Assert.NotSame(expected, lhs);
        }
Пример #6
0
        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 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();
        }
Пример #8
0
 public ContentDomainObjectTests()
 {
     patched = otherData.MergeInto(data);
 }
Пример #9
0
        public ContentDomainObjectTests()
        {
            patched = otherData.MergeInto(data);

            sut.ActivateAsync(Id, A.Fake <IStore <Guid> >());
        }