コード例 #1
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);
        }
コード例 #2
0
ファイル: ContentDataTests.cs プロジェクト: jrlost/squidex
        public void Should_return_same_content_if_merging_same_references()
        {
            var source =
                new ContentData()
                .AddField("field1",
                          new ContentFieldData()
                          .AddInvariant(1))
                .AddField("field2",
                          new ContentFieldData()
                          .AddLocalized("de", 2));

            var actual = source.MergeInto(source);

            Assert.Same(source, actual);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: ContentDataTests.cs プロジェクト: jrlost/squidex
        public void Should_merge_two_name_models()
        {
            var lhs =
                new ContentData()
                .AddField("field1",
                          new ContentFieldData()
                          .AddInvariant(1))
                .AddField("field2",
                          new ContentFieldData()
                          .AddLocalized("de", 2)
                          .AddLocalized("it", 2));

            var rhs =
                new ContentData()
                .AddField("field2",
                          new ContentFieldData()
                          .AddLocalized("it", 3)
                          .AddLocalized("en", 3))
                .AddField("field3",
                          new ContentFieldData()
                          .AddInvariant(4));

            var expected =
                new ContentData()
                .AddField("field1",
                          new ContentFieldData()
                          .AddInvariant(1))
                .AddField("field2",
                          new ContentFieldData()
                          .AddLocalized("it", 2)
                          .AddLocalized("de", 2)
                          .AddLocalized("en", 3))
                .AddField("field3",
                          new ContentFieldData()
                          .AddInvariant(4));

            var actual = lhs.MergeInto(rhs);

            Assert.Equal(expected, actual);
            Assert.NotSame(expected, rhs);
            Assert.NotSame(expected, lhs);
        }