Skip to content

Commit

Permalink
Fixed bug with references w/ exs:member="" attributes
Browse files Browse the repository at this point in the history
Fixes #407
  • Loading branch information
Mike-E-angelo authored Jun 22, 2020
1 parent 55d1042 commit c85bfa5
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ExtendedXmlSerializer.ContentModel;
using ExtendedXmlSerializer.ContentModel.Content;
using ExtendedXmlSerializer.ContentModel.Format;
using ExtendedXmlSerializer.ContentModel.Properties;
using ExtendedXmlSerializer.ContentModel.Reflection;
Expand Down Expand Up @@ -67,7 +68,7 @@ public Activator(IReader activator, IEntities entities, IReferenceMaps maps)

public object Get(IFormatReader parameter)
{
var element = parameter.Get().To<XmlReader>().NodeType != XmlNodeType.Attribute;
var element = parameter.Get().To<XmlReader>().NodeType != XmlNodeType.Attribute || MemberProperty.Default.Get(parameter);

var declared = element ? Identity(parameter) : null;
var result = _activator.Get(parameter);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ExtendedXmlSerializer.ContentModel;
using ExtendedXmlSerializer.ContentModel.Content;
using ExtendedXmlSerializer.ContentModel.Format;
using ExtendedXmlSerializer.ContentModel.Reflection;
using System.Reflection;
Expand Down Expand Up @@ -28,7 +29,7 @@ public ReferenceReader(IReader reader, IReferenceMaps maps, IEntities entities,

ReferenceIdentity? GetReference(IFormatReader parameter)
{
if (parameter.Get().To<XmlReader>().NodeType != XmlNodeType.Attribute)
if (parameter.Get().To<XmlReader>().NodeType != XmlNodeType.Attribute || MemberProperty.Default.Get(parameter))
{
var identity = ReferenceIdentity.Get(parameter);
if (identity.HasValue)
Expand Down
48 changes: 48 additions & 0 deletions test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue407Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using ExtendedXmlSerializer.Configuration;
using ExtendedXmlSerializer.Tests.ReportedIssues.Shared;
using ExtendedXmlSerializer.Tests.ReportedIssues.Support;
using FluentAssertions;
using System.Collections.Generic;
using Xunit;
// ReSharper disable UnusedAutoPropertyAccessor.Local

namespace ExtendedXmlSerializer.Tests.ReportedIssues
{
public sealed class Issue407Tests
{
[Fact]
public void Verify()
{
var type = new PathogenType{ Code = 'f', Description = "Fungus" };
var instance = new List<object>
{
new LookupTable<PathogenDto>
{
Models = new List<PathogenDto>
{
new Pathogen{ PathogenType = type }
}
},
new LookupTable<PathogenTypeDto>
{
Models = new List<PathogenTypeDto> { type }
}
};

var serializer = new ConfigurationContainer().EnableReferences().ForTesting();

var cycled = serializer.Cycle(instance);
var expected = cycled[1].To<LookupTable<PathogenTypeDto>>().Models.Only();

cycled[0].To<LookupTable<PathogenDto>>()
.Models[0].PathogenType.Should()
.BeSameAs(expected);

}

sealed class LookupTable<T>
{
public List<T> Models { get; set; } = new List<T>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace ExtendedXmlSerializer.Tests.ReportedIssues.Shared
{
sealed class Pathogen : PathogenDto {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ExtendedXmlSerializer.Tests.ReportedIssues.Shared
{
class PathogenDto
{
public PathogenType PathogenType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ExtendedXmlSerializer.Tests.ReportedIssues.Shared
{
sealed class PathogenType : PathogenTypeDto
{
public char Code { get; set; }

public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace ExtendedXmlSerializer.Tests.ReportedIssues.Shared
{
class PathogenTypeDto {}
}

0 comments on commit c85bfa5

Please sign in to comment.