Skip to content

Commit

Permalink
Wildcard segment path on mixed properties fix. When props are element…
Browse files Browse the repository at this point in the history
…s structures and and values with segment wildcard the serializer does not sort for write correctly. Closes #235
  • Loading branch information
cleftheris committed May 24, 2024
1 parent 6ddda85 commit a16f807
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 97 deletions.
2 changes: 1 addition & 1 deletion src/indice.Edi/Serialization/EdiPropertyDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public EdiPropertyDescriptor(PropertyInfo info, IEnumerable<EdiAttribute> 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<EdiPathAttribute>().FirstOrDefault();
if (parentPathInfo != null) {
pathInfo = new EdiPathAttribute(new EdiPath(new EdiPathFragment(parentPathInfo.Segment), pathInfo.PathInternal.Element, pathInfo.PathInternal.Component));
Expand Down
96 changes: 0 additions & 96 deletions test/indice.Edi.Tests/Samples/Aperak_issue235 xml.txt

This file was deleted.

Binary file added test/indice.Edi.Tests/Samples/Aperak_issue235.xml
Binary file not shown.
24 changes: 24 additions & 0 deletions test/indice.Edi.Tests/SerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -442,5 +444,27 @@ string Serialize<T>(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>(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));
}
}
}
1 change: 1 addition & 0 deletions test/indice.Edi.Tests/indice.Edi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<EmbeddedResource Include="Samples\**\*.edi" />
<EmbeddedResource Include="Samples\**\*.xml" />
<None Update="SamplesBig\**\*.edi">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down

0 comments on commit a16f807

Please sign in to comment.