-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic test demonstrating serializer.
- Loading branch information
1 parent
82371f6
commit 87a4948
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue440Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IInterface>() | ||
.Register() | ||
.Serializer() | ||
.Using(Serializer.Default) | ||
.Create() | ||
.ForTesting(); | ||
var instance = new Container {Interface = new Implementation()}; | ||
container.Cycle(instance) | ||
.Interface.Should() | ||
.BeOfType<Implementation>() | ||
.And.Subject.To<Implementation>() | ||
.Created.Should() | ||
.BeTrue(); | ||
} | ||
|
||
sealed class Container | ||
{ | ||
public IInterface Interface { get; set; } | ||
} | ||
|
||
sealed class Serializer : ISerializer<IInterface> | ||
{ | ||
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; } | ||
} | ||
} | ||
} |