Browse Source

Fix schema synchronizer.

pull/432/head
Sebastian Stehle 6 years ago
parent
commit
3b8782cf6f
  1. 4
      src/Squidex.Domain.Apps.Core.Operations/EventSynchronization/SchemaSynchronizer.cs
  2. 6
      tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/AssertHelper.cs
  3. 37
      tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/SchemaSynchronizerTests.cs

4
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 };
}
}
}

6
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"));
}
}
}

37
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<long> { 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<long> { 10, 50, 11 } }
);
}
}
}

Loading…
Cancel
Save