diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests_Extended.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests_Extended.cs new file mode 100644 index 00000000..4f5a18d4 --- /dev/null +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests_Extended.cs @@ -0,0 +1,40 @@ +using ExtendedXmlSerializer.Configuration; +using ExtendedXmlSerializer.Tests.ReportedIssues.Support; +using FluentAssertions; +using System.Collections.Generic; +using Xunit; + +namespace ExtendedXmlSerializer.Tests.ReportedIssues +{ + public sealed class Issue565Tests_Extended + { + [Fact] + public void Verify() + { + var subject = new ConfigurationContainer().Create().ForTesting(); + var instance = new Store + { + [new byte[2]] = "First", + [new byte[3]] = "Second", + [new byte[4]] = "Third" + }; + subject.Cycle(instance).Should().BeEquivalentTo(instance); + } + + sealed class Store : Dictionary + { + public Store() : base(Issue565Tests_Extended.Comparer.Instance) {} + } + + sealed class Comparer : EqualityComparer + { + public static Comparer Instance { get; } = new(); + + Comparer() {} + + public override bool Equals(byte[] x, byte[] y) => x.Length == y.Length; + + public override int GetHashCode(byte[] obj) => obj.Length.GetHashCode(); + } + } +} diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests_Extended_II.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests_Extended_II.cs new file mode 100644 index 00000000..45242f8d --- /dev/null +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests_Extended_II.cs @@ -0,0 +1,58 @@ +using ExtendedXmlSerializer.Configuration; +using ExtendedXmlSerializer.Tests.ReportedIssues.Support; +using FluentAssertions; +using System; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace ExtendedXmlSerializer.Tests.ReportedIssues +{ + public sealed class Issue565Tests_Extended_II + { + [Fact] + public void Verify() + { + List instance = new List(); + for (int i = 0; i < 2000; i++) + { + var newElement = new TestSerialization(); + if (i % 2 == 0) + { + newElement.MyString = "**********"; + newElement.MyDouble = Double.MaxValue; + newElement.MyBool = true; + newElement.MyInteger = i; + } + else + { + newElement.MyString = "----------"; + newElement.MyDouble = Double.MinValue; + newElement.MyBool = false; + newElement.MyInteger = i; + } + instance.Add(newElement); + } + + var serializer = new ConfigurationContainer().EnableImplicitTyping(typeof(List)) + .Create(); + + var cycle = serializer.Cycle(instance); + cycle.Should().BeEquivalentTo(instance); + cycle[0].Should().BeEquivalentTo(instance[0]); + cycle.Last().Should().BeEquivalentTo(instance.Last()); + } + + [Serializable] + public class TestSerialization + { + public string MyString { get; set; } + + public bool MyBool { get; set; } + + public double MyDouble { get; set; } + + public int MyInteger { get; set; } + } + } +} diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests_Extended_III.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests_Extended_III.cs new file mode 100644 index 00000000..a69d533d --- /dev/null +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests_Extended_III.cs @@ -0,0 +1,112 @@ +using ExtendedXmlSerializer.Configuration; +using ExtendedXmlSerializer.Tests.ReportedIssues.Support; +using FluentAssertions; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Xunit; + +namespace ExtendedXmlSerializer.Tests.ReportedIssues +{ + public sealed class Issue565Tests_Extended_III + { + [Fact] + public void Verify() + { + var instances = new[] + { + new Model + { + Key = new List + { + Encoding.UTF8.GetBytes("Hello"), + Encoding.UTF8.GetBytes("World"), + }, + Message = "First" + }, + new Model + { + Key = new List + { + Encoding.UTF8.GetBytes("Hello1"), + Encoding.UTF8.GetBytes("World1"), + }, + Message = "Second" + }, + new Model + { + Key = new List + { + Encoding.UTF8.GetBytes("Hello2"), + Encoding.UTF8.GetBytes("World2"), + }, + Message = "Third" + }, + new Model + { + Key = new List + { + Encoding.UTF8.GetBytes("Hello3"), + Encoding.UTF8.GetBytes("World3"), + }, + Message = "Fourth" + }, + new Model + { + Key = new List + { + Encoding.UTF8.GetBytes("Hello4"), + Encoding.UTF8.GetBytes("World4"), + }, + Message = "Fifth" + }, + new Model + { + Key = new List + { + Encoding.UTF8.GetBytes("Hello5"), + Encoding.UTF8.GetBytes("World5"), + }, + Message = "Sixth" + } + }; + var instance = new Store(); + foreach (var model in instances) + { + instance.Add(model.Key, model); + } + var subject = new ConfigurationContainer().EnableImplicitTyping(instance.GetType()).Create().ForTesting(); + var cycle = subject.Cycle(instance); + cycle.Values.Should().BeEquivalentTo(instance.Values); + cycle.Should().BeEquivalentTo(instance); + cycle.Count.Should().Be(instance.Count); + } + + public sealed class Model + { + public List Key { get; set; } + + public string Message { get; set; } + } + + sealed class Store : Dictionary, Model> + { + public Store() : base(Issue565Tests_Extended_III.Comparer.Instance) {} + } + + sealed class Comparer : EqualityComparer> + { + public static Comparer Instance { get; } = new(); + + Comparer() {} + + public override bool Equals(List x, List y) + => (x != null ? string.Join(string.Empty, x.Select(Encoding.UTF8.GetString)) : string.Empty) + == + (y != null ? string.Join(string.Empty, y.Select(Encoding.UTF8.GetString)) : string.Empty); + + public override int GetHashCode(List obj) + => string.Join(string.Empty, obj.Select(Encoding.UTF8.GetString)).GetHashCode(); + } + } +} \ No newline at end of file