diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue440Tests.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue440Tests.cs new file mode 100644 index 000000000..34515a0c5 --- /dev/null +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue440Tests.cs @@ -0,0 +1,64 @@ +using ExtendedXmlSerializer.Configuration; +using ExtendedXmlSerializer.ContentModel; +using ExtendedXmlSerializer.ContentModel.Format; +using ExtendedXmlSerializer.Tests.ReportedIssues.Support; +using FluentAssertions; +using System; +using Xunit; + +namespace ExtendedXmlSerializer.Tests.ReportedIssues +{ + public sealed class Issue440Tests + { + [Fact] + public void Verify() + { + var container = new ConfigurationContainer().Type() + .Register() + .Serializer() + .Using(Serializer.Default) + .Create() + .ForTesting(); + var instance = new Container {Interface = new Implementation()}; + container.Cycle(instance) + .Interface.Should() + .BeOfType() + .And.Subject.To() + .Created.Should() + .BeTrue(); + } + + sealed class Container + { + public IInterface Interface { get; set; } + } + + sealed class Serializer : ISerializer + { + public static Serializer Default { get; } = new Serializer(); + + Serializer() {} + + public IInterface Get(IFormatReader parameter) + { + var name = parameter.Content(); + var type = Type.GetType(name) ?? throw new InvalidOperationException($"Could not parse '{name}'"); + var result = (Implementation)Activator.CreateInstance(type); + result.Created = true; + return result; + } + + public void Write(IFormatWriter writer, IInterface instance) + { + writer.Content(instance.GetType().AssemblyQualifiedName); + } + } + + public interface IInterface {} + + public sealed class Implementation : IInterface + { + public bool Created { get; set; } + } + } +} \ No newline at end of file