diff --git a/src/Squidex.Domain.Apps.Core.Operations/EventSynchronization/SchemaSynchronizer.cs b/src/Squidex.Domain.Apps.Core.Operations/EventSynchronization/SchemaSynchronizer.cs index d621782f2..68e916936 100644 --- a/src/Squidex.Domain.Apps.Core.Operations/EventSynchronization/SchemaSynchronizer.cs +++ b/src/Squidex.Domain.Apps.Core.Operations/EventSynchronization/SchemaSynchronizer.cs @@ -203,7 +203,9 @@ namespace Squidex.Domain.Apps.Core.EventSynchronization if (sourceNames.Intersect(targetNames).Count() == target.Ordered.Count && !sourceNames.SequenceEqual(targetNames)) { - yield return new SchemaFieldsReordered { FieldIds = sourceIds.Select(x => x.Id).ToList(), ParentFieldId = parentId }; + var fieldIds = targetNames.Select(x => sourceIds.FirstOrDefault(y => y.Name == x).Id).ToList(); + + yield return new SchemaFieldsReordered { FieldIds = fieldIds, ParentFieldId = parentId }; } } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/AssertHelper.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/AssertHelper.cs index 9b678d0d7..879bc0c74 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/AssertHelper.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/AssertHelper.cs @@ -33,7 +33,11 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization { lhs.Should().BeOfType(rhs.GetType()); - ((object)lhs).Should().BeEquivalentTo(rhs, o => o.IncludingAllRuntimeProperties().Excluding(x => x.SelectedMemberPath == "Properties.IsFrozen")); + ((object)lhs).Should().BeEquivalentTo(rhs, o => o + .WithStrictOrdering() + .IncludingNestedObjects() + .IncludingAllRuntimeProperties() + .Excluding(x => x.SelectedMemberPath == "Properties.IsFrozen")); } } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/SchemaSynchronizerTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/SchemaSynchronizerTests.cs index ff287fd62..a17f49887 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/SchemaSynchronizerTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/SchemaSynchronizerTests.cs @@ -486,8 +486,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization var targetSchema = new Schema("target") .AddArray(arrayId.Id, arrayId.Name, Partitioning.Invariant, f => f - .AddString(20, "f2") - .AddString(15, "f1")); + .AddString(1, "f2") + .AddString(2, "f1")); var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator); @@ -509,8 +509,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization var targetSchema = new Schema("target") - .AddString(20, "f2", Partitioning.Invariant) - .AddString(15, "f1", Partitioning.Invariant); + .AddString(1, "f2", Partitioning.Invariant) + .AddString(2, "f1", Partitioning.Invariant); var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator); @@ -532,8 +532,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization var targetSchema = new Schema("target") - .AddString(25, "f3", Partitioning.Invariant) - .AddString(20, "f1", Partitioning.Invariant); + .AddString(1, "f3", Partitioning.Invariant) + .AddString(2, "f1", Partitioning.Invariant); var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator); @@ -543,5 +543,30 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization new SchemaFieldsReordered { FieldIds = new List { 50, 10 } } ); } + + [Fact] + public void Should_create_events_if_fields_reordered_after_sync2() + { + var id1 = NamedId.Of(1, "f1"); + var id2 = NamedId.Of(2, "f1"); + + var sourceSchema = + new Schema("source") + .AddString(10, "f1", Partitioning.Invariant) + .AddString(11, "f2", Partitioning.Invariant); + + var targetSchema = + new Schema("target") + .AddString(1, "f1", Partitioning.Invariant) + .AddString(2, "f3", Partitioning.Invariant) + .AddString(3, "f2", Partitioning.Invariant); + + var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator); + + events.ShouldHaveSameEvents( + new FieldAdded { FieldId = NamedId.Of(50L, "f3"), Name = "f3", Partitioning = Partitioning.Invariant.Key, Properties = new StringFieldProperties() }, + new SchemaFieldsReordered { FieldIds = new List { 10, 50, 11 } } + ); + } } }