From 758a282d8f60b42362a96ab4cddf89ce503a68a1 Mon Sep 17 00:00:00 2001 From: Bartosz Sypytkowski Date: Wed, 28 Jun 2017 17:52:27 +0200 Subject: [PATCH] (not working) repro case of an issue #58 --- Hyperion.Tests/Bugs.cs | 73 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/Hyperion.Tests/Bugs.cs b/Hyperion.Tests/Bugs.cs index e5ae4441..92bcc141 100644 --- a/Hyperion.Tests/Bugs.cs +++ b/Hyperion.Tests/Bugs.cs @@ -8,6 +8,8 @@ #endregion using System; +using System.Collections.Generic; +using System.Collections.Immutable; using System.IO; using Xunit; @@ -16,6 +18,49 @@ namespace Hyperion.Tests public class Bugs { + #region issue 58 + + public enum TrustLevel { Unknown, Suspicious, Partial, Fully } + public interface IContainer + { + T Value { get; } + TrustLevel TrustLevel { get; } + } + public class Container : IContainer + { + public T Value { get; } + public TrustLevel TrustLevel { get; } + + public Container(T value, TrustLevel trustLevel) + { + Value = value; + TrustLevel = trustLevel; + } + } + public class Name + { + public IContainer Title { get; } + public IContainer GivenName { get; } + public IContainer FamilyName { get; } + + public Name(IContainer title, IContainer givenName, IContainer familyName) + { + Title = title; + GivenName = givenName; + FamilyName = familyName; + } + } + public class ProvisioningResultMessage + { + private T Result { get; } + + public ProvisioningResultMessage(T result) + { + Result = result; + } + } + + #endregion public class ByteMessage { @@ -65,6 +110,34 @@ public void CanSerialieCustomType_bug() var actual = serializer.Deserialize(stream); } + [Fact] + public void CanSerializeImmutableGenericInterfaces() + { + var serializer = new Serializer(new SerializerOptions(versionTolerance: true, preserveObjectReferences: true)); + var names = new List + { + new Name(new Container("Mr", TrustLevel.Partial), + new Container("Bob", TrustLevel.Partial), + new Container("Smith", TrustLevel.Suspicious)), + new Name(new Container("Mrs", TrustLevel.Suspicious), + new Container("Jane", TrustLevel.Suspicious), + new Container("Smith", TrustLevel.Suspicious)), + new Name(new Container("Master", TrustLevel.Fully), + new Container("Fred", TrustLevel.Fully), new Container("Smith", TrustLevel.Fully)), + new Name(new Container("Miss", TrustLevel.Partial), + new Container("Sandra", TrustLevel.Partial), + new Container("Smith", TrustLevel.Suspicious)) + }; + var message = new ProvisioningResultMessage>(names.ToImmutableArray()); + + using (var stream = new MemoryStream()) + { + serializer.Serialize(message, stream); + stream.Position = 0; + var actual = serializer.Deserialize(stream); + } + } + public class SnapshotSelectionCriteria { public static SnapshotSelectionCriteria Latest { get; set; } = new SnapshotSelectionCriteria()