Browse Source

Fix a bug in schema synchronizer

pull/544/head
Sebastian 6 years ago
parent
commit
00753a7a91
  1. 4
      backend/src/Squidex.Infrastructure/CollectionExtensions.cs
  2. 22
      backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/SchemaSynchronizerTests.cs
  3. 20
      backend/tests/Squidex.Infrastructure.Tests/CollectionExtensionsTests.cs

4
backend/src/Squidex.Infrastructure/CollectionExtensions.cs

@ -15,12 +15,12 @@ namespace Squidex.Infrastructure
{ {
public static bool SetEquals<T>(this IReadOnlyCollection<T> source, IReadOnlyCollection<T> other) public static bool SetEquals<T>(this IReadOnlyCollection<T> source, IReadOnlyCollection<T> other)
{ {
return source.Intersect(other).Count() == other.Count; return source.Count == other.Count && source.Intersect(other).Count() == other.Count;
} }
public static bool SetEquals<T>(this IReadOnlyCollection<T> source, IReadOnlyCollection<T> other, IEqualityComparer<T> comparer) public static bool SetEquals<T>(this IReadOnlyCollection<T> source, IReadOnlyCollection<T> other, IEqualityComparer<T> comparer)
{ {
return source.Intersect(other, comparer).Count() == other.Count; return source.Count == other.Count && source.Intersect(other, comparer).Count() == other.Count;
} }
public static IResultList<T> SortSet<T, TKey>(this IResultList<T> input, Func<T, TKey> idProvider, IReadOnlyList<TKey> ids) where T : class public static IResultList<T> SortSet<T, TKey>(this IResultList<T> input, Func<T, TKey> idProvider, IReadOnlyList<TKey> ids) where T : class

22
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<long> { 10, 50, 11 } } new SchemaFieldsReordered { FieldIds = new List<long> { 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<long> { 50, 11 } }
);
}
} }
} }

20
backend/tests/Squidex.Infrastructure.Tests/CollectionExtensionsTests.cs

@ -15,6 +15,26 @@ namespace Squidex.Infrastructure
private readonly Dictionary<int, int> valueDictionary = new Dictionary<int, int>(); private readonly Dictionary<int, int> valueDictionary = new Dictionary<int, int>();
private readonly Dictionary<int, List<int>> listDictionary = new Dictionary<int, List<int>>(); private readonly Dictionary<int, List<int>> listDictionary = new Dictionary<int, List<int>>();
[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] [Fact]
public void IndexOf_should_return_index_when_found() public void IndexOf_should_return_index_when_found()
{ {

Loading…
Cancel
Save