diff --git a/src/indice.Edi/Serialization/EdiPropertyDescriptor.cs b/src/indice.Edi/Serialization/EdiPropertyDescriptor.cs index 29c8648..d90808d 100644 --- a/src/indice.Edi/Serialization/EdiPropertyDescriptor.cs +++ b/src/indice.Edi/Serialization/EdiPropertyDescriptor.cs @@ -110,7 +110,7 @@ public EdiPropertyDescriptor(PropertyInfo info, IEnumerable attrib if (_SegmentGroupInfo != null && _SegmentGroupInfo.StartInternal.Segment != null && pathInfo == null) { pathInfo = new EdiPathAttribute(_SegmentGroupInfo.StartInternal.Segment); } - if (pathInfo != null && structureType == EdiStructureType.None && pathInfo.PathInternal.Segment.IsWildcard) { + if (pathInfo != null && (structureType == EdiStructureType.None || structureType == EdiStructureType.Element) && pathInfo.PathInternal.Segment.IsWildcard) { var parentPathInfo = info.DeclaringType.GetTypeInfo().GetCustomAttributes().FirstOrDefault(); if (parentPathInfo != null) { pathInfo = new EdiPathAttribute(new EdiPath(new EdiPathFragment(parentPathInfo.Segment), pathInfo.PathInternal.Element, pathInfo.PathInternal.Component)); diff --git a/test/indice.Edi.Tests/Samples/Aperak_issue235 xml.txt b/test/indice.Edi.Tests/Samples/Aperak_issue235 xml.txt deleted file mode 100644 index 003b0a0..0000000 --- a/test/indice.Edi.Tests/Samples/Aperak_issue235 xml.txt +++ /dev/null @@ -1,96 +0,0 @@ - - - - - UNOA - 3 - - - 8717982000004 - 14 - - - 8717045000002 - 14 - - - 210504 - 1310 - - 4 - - - - 041310181 - - APERAK - D - 96A - UN - - - - - - 0109094405 - - - - - 137 - 202105041310 - 203 - - - - - - ON - 4506701767 - - - - - 171 - 20210504 - 102 - - - - - - BY - - 8717045000248 - 9 - - - - - - SU - - 8717982000004 - 9 - - - - - - DP - - 8717045000248 - 9 - - - - - 9 - 041310181 - - - - 1 - 4 - - \ No newline at end of file diff --git a/test/indice.Edi.Tests/Samples/Aperak_issue235.xml b/test/indice.Edi.Tests/Samples/Aperak_issue235.xml new file mode 100644 index 0000000..5fe45b3 Binary files /dev/null and b/test/indice.Edi.Tests/Samples/Aperak_issue235.xml differ diff --git a/test/indice.Edi.Tests/Samples/Apperak edi_out_issue235.txt b/test/indice.Edi.Tests/Samples/Apperak edi_out_issue235.edi similarity index 100% rename from test/indice.Edi.Tests/Samples/Apperak edi_out_issue235.txt rename to test/indice.Edi.Tests/Samples/Apperak edi_out_issue235.edi diff --git a/test/indice.Edi.Tests/SerializerTests.cs b/test/indice.Edi.Tests/SerializerTests.cs index b30598a..be4d631 100644 --- a/test/indice.Edi.Tests/SerializerTests.cs +++ b/test/indice.Edi.Tests/SerializerTests.cs @@ -3,7 +3,9 @@ using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; +using System.Xml.Serialization; using indice.Edi.Tests.Models; using Xunit; @@ -442,5 +444,27 @@ string Serialize(T data) { return writer.ToString(); } } + + [Fact, Trait(Traits.Tag, "EDIFact"), Trait(Traits.Issue, "#235")] + public void Serialize_Should_not_create_double_UNB_Segment_Issue235() { + var source = default(EDIFACT_APPERAK_issue235); + using (var stream = Helpers.GetResourceStream("Aperak_issue235.xml")) { + var serializer = new XmlSerializer(typeof(EDIFACT_APPERAK_issue235)); + source = (EDIFACT_APPERAK_issue235)serializer.Deserialize(stream); + } + Assert.NotNull(source); + + + string Serialize(T data) { + var grammar = EdiGrammar.NewEdiFact(); + using var writer = new StringWriter(); + new EdiSerializer().Serialize(writer, grammar, data); + return writer.ToString(); + } + + var output = Serialize(source); + Regex unbRegex = new Regex("UNB"); + Assert.Single(unbRegex.Matches(output)); + } } } diff --git a/test/indice.Edi.Tests/indice.Edi.Tests.csproj b/test/indice.Edi.Tests/indice.Edi.Tests.csproj index abac45b..61d2c56 100644 --- a/test/indice.Edi.Tests/indice.Edi.Tests.csproj +++ b/test/indice.Edi.Tests/indice.Edi.Tests.csproj @@ -8,6 +8,7 @@ + PreserveNewest