Browse Source

Get rid of unused code and more tests.

pull/697/head
Sebastian 5 years ago
parent
commit
e2d4cdcc52
  1. 14
      backend/src/Squidex.Infrastructure/Json/Newtonsoft/ConverterContractResolver.cs
  2. 44
      backend/tests/Squidex.Infrastructure.Tests/Collections/ImmutableDictionaryTests.cs
  3. 12
      backend/tests/Squidex.Infrastructure.Tests/Collections/ImmutableListTests.cs

14
backend/src/Squidex.Infrastructure/Json/Newtonsoft/ConverterContractResolver.cs

@ -46,20 +46,6 @@ namespace Squidex.Infrastructure.Json.Newtonsoft
return base.CreateArrayContract(implementationType);
}
if (objectType.BaseType?.IsGenericType == true && objectType.BaseType.GetGenericTypeDefinition() == typeof(ImmutableList<>))
{
var contract = base.CreateArrayContract(objectType);
return contract;
}
if (objectType.IsGenericType == true && objectType.GetGenericTypeDefinition() == typeof(ImmutableList<>))
{
var contract = base.CreateArrayContract(objectType);
return contract;
}
return base.CreateArrayContract(objectType);
}

44
backend/tests/Squidex.Infrastructure.Tests/Collections/ImmutableDictionaryTests.cs

@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using Squidex.Infrastructure.TestHelpers;
using Xunit;
namespace Squidex.Infrastructure.Collections
@ -40,13 +41,31 @@ namespace Squidex.Infrastructure.Collections
[Fact]
public void Should_make_correct_object_equal_comparisons()
{
var obj1a = new Dictionary<int, int> { [1] = 1 }.ToImmutableDictionary();
var obj1b = new Dictionary<int, int> { [1] = 1 }.ToImmutableDictionary();
var obj1a = new Dictionary<int, int>
{
[1] = 1
}.ToImmutableDictionary();
var dictionaryOtherValue = new Dictionary<int, int> { [1] = 2 }.ToImmutableDictionary();
var dictionaryOtherKey = new Dictionary<int, int> { [2] = 1 }.ToImmutableDictionary();
var obj1b = new Dictionary<int, int>
{
[1] = 1
}.ToImmutableDictionary();
var dictionaryOtherCount = new Dictionary<int, int> { [1] = 1, [2] = 2 }.ToImmutableDictionary();
var dictionaryOtherValue = new Dictionary<int, int>
{
[1] = 2
}.ToImmutableDictionary();
var dictionaryOtherKey = new Dictionary<int, int>
{
[2] = 1
}.ToImmutableDictionary();
var dictionaryOtherCount = new Dictionary<int, int>
{
[1] = 1,
[2] = 2
}.ToImmutableDictionary();
Assert.Equal(obj1a, obj1b);
Assert.Equal(obj1a.GetHashCode(), obj1b.GetHashCode());
@ -64,5 +83,20 @@ namespace Squidex.Infrastructure.Collections
Assert.NotEqual(obj1a.GetHashCode(), dictionaryOtherCount.GetHashCode());
Assert.False(obj1a.Equals((object)dictionaryOtherCount));
}
[Fact]
public void Should_serialize_and_deserialize()
{
var sut = new Dictionary<int, int>
{
[11] = 1,
[12] = 2,
[13] = 3
}.ToImmutableDictionary();
var serialized = sut.SerializeAndDeserialize();
Assert.Equal(sut, serialized);
}
}
}

12
backend/tests/Squidex.Infrastructure.Tests/Collections/ImmutableListTests.cs

@ -5,6 +5,8 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using FluentAssertions;
using Squidex.Infrastructure.TestHelpers;
using System.Linq;
using Xunit;
@ -57,5 +59,15 @@ namespace Squidex.Infrastructure.Collections
Assert.NotEqual(list1a.GetHashCode(), listOtherSize.GetHashCode());
Assert.False(list1a.Equals((object)listOtherSize));
}
[Fact]
public void Should_serialize_and_deserialize()
{
var sut = ImmutableList.Create(1, 2, 3);
var serialized = sut.SerializeAndDeserialize();
Assert.Equal(sut, serialized);
}
}
}

Loading…
Cancel
Save