mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.9 KiB
99 lines
2.9 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using Squidex.Infrastructure.TestHelpers;
|
|
using Xunit;
|
|
|
|
namespace Squidex.Infrastructure.Collections
|
|
{
|
|
public class ReadonlyListTests
|
|
{
|
|
internal sealed class Inherited : ReadonlyList<int>
|
|
{
|
|
public Inherited(IList<int> inner)
|
|
: base(inner)
|
|
{
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_return_empty_instance_for_empty_array()
|
|
{
|
|
var result = ReadonlyList.Create<int>();
|
|
|
|
Assert.Same(ReadonlyList.Empty<int>(), result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_return_empty_instance_for_null_array()
|
|
{
|
|
var result = ReadonlyList.Create((int[]?)null);
|
|
|
|
Assert.Same(ReadonlyList.Empty<int>(), result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_return_empty_instance_for_empty_enumerable()
|
|
{
|
|
var result = Enumerable.Empty<int>().ToReadonlyList();
|
|
|
|
Assert.Same(ReadonlyList.Empty<int>(), result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_make_correct_equal_comparisons()
|
|
{
|
|
var list1a = ReadonlyList.Create(1);
|
|
var list1b = ReadonlyList.Create(1);
|
|
|
|
var listOtherValue = ReadonlyList.Create(2);
|
|
var listOtherSize = ReadonlyList.Create(1, 2);
|
|
|
|
Assert.Equal(list1a, list1b);
|
|
Assert.Equal(list1a.GetHashCode(), list1b.GetHashCode());
|
|
Assert.True(list1a.Equals((object)list1b));
|
|
|
|
Assert.NotEqual(list1a, listOtherValue);
|
|
Assert.NotEqual(list1a.GetHashCode(), listOtherValue.GetHashCode());
|
|
Assert.False(list1a.Equals((object)listOtherValue));
|
|
|
|
Assert.NotEqual(list1a, listOtherSize);
|
|
Assert.NotEqual(list1a.GetHashCode(), listOtherSize.GetHashCode());
|
|
Assert.False(list1a.Equals((object)listOtherSize));
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_serialize_and_deserialize()
|
|
{
|
|
var sut = new List<int>
|
|
{
|
|
1,
|
|
2,
|
|
3
|
|
}.ToReadonlyList();
|
|
|
|
var serialized = sut.SerializeAndDeserialize();
|
|
|
|
Assert.Equal(sut, serialized);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_serialize_and_deserialize_inherited()
|
|
{
|
|
var sut = new Inherited(new List<int>
|
|
{
|
|
1,
|
|
2,
|
|
3
|
|
});
|
|
|
|
var serialized = sut.SerializeAndDeserialize();
|
|
|
|
Assert.Equal(sut, serialized);
|
|
}
|
|
}
|
|
}
|
|
|