diff --git a/backend/src/Squidex.Infrastructure/CollectionExtensions.cs b/backend/src/Squidex.Infrastructure/CollectionExtensions.cs index f4be61d44..51fe2ca6a 100644 --- a/backend/src/Squidex.Infrastructure/CollectionExtensions.cs +++ b/backend/src/Squidex.Infrastructure/CollectionExtensions.cs @@ -15,12 +15,12 @@ namespace Squidex.Infrastructure { public static bool SetEquals(this IReadOnlyCollection source, IReadOnlyCollection other) { - return source.Intersect(other).Count() == other.Count; + return source.Count == other.Count && source.Intersect(other).Count() == other.Count; } public static bool SetEquals(this IReadOnlyCollection source, IReadOnlyCollection other, IEqualityComparer comparer) { - return source.Intersect(other, comparer).Count() == other.Count; + return source.Count == other.Count && source.Intersect(other, comparer).Count() == other.Count; } public static IResultList SortSet(this IResultList input, Func idProvider, IReadOnlyList ids) where T : class diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/SchemaSynchronizerTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/SchemaSynchronizerTests.cs index f60d7364f..ed8ab0d7f 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/SchemaSynchronizerTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/SchemaSynchronizerTests.cs @@ -627,5 +627,27 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization new SchemaFieldsReordered { FieldIds = new List { 10, 50, 11 } } ); } + + [Fact] + public void Should_create_events_if_field_renamed() + { + var sourceSchema = + new Schema("source") + .AddString(10, "f1", Partitioning.Invariant) + .AddString(11, "f2", Partitioning.Invariant); + + var targetSchema = + new Schema("target") + .AddString(1, "f3", Partitioning.Invariant) + .AddString(2, "f2", Partitioning.Invariant); + + var events = sourceSchema.Synchronize(targetSchema, idGenerator); + + events.ShouldHaveSameEvents( + new FieldDeleted { FieldId = NamedId.Of(10L, "f1") }, + new FieldAdded { FieldId = NamedId.Of(50L, "f3"), Name = "f3", Partitioning = Partitioning.Invariant.Key, Properties = new StringFieldProperties() }, + new SchemaFieldsReordered { FieldIds = new List { 50, 11 } } + ); + } } } diff --git a/backend/tests/Squidex.Infrastructure.Tests/CollectionExtensionsTests.cs b/backend/tests/Squidex.Infrastructure.Tests/CollectionExtensionsTests.cs index 7e074b05c..50bd498d5 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/CollectionExtensionsTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/CollectionExtensionsTests.cs @@ -15,6 +15,26 @@ namespace Squidex.Infrastructure private readonly Dictionary valueDictionary = new Dictionary(); private readonly Dictionary> listDictionary = new Dictionary>(); + [Fact] + public void SetEquals_should_return_false_when_subset() + { + var set1 = new[] { 1, 2 }; + var set2 = new[] { 1, 2, 3 }; + + Assert.False(set1.SetEquals(set2)); + Assert.False(set2.SetEquals(set1)); + } + + [Fact] + public void SetEquals_should_return_true_for_same_items_in_different_order() + { + var set1 = new[] { 1, 2, 3 }; + var set2 = new[] { 3, 2, 1 }; + + Assert.True(set1.SetEquals(set2)); + Assert.True(set2.SetEquals(set1)); + } + [Fact] public void IndexOf_should_return_index_when_found() {