Skip to content

Commit

Permalink
Test to showcase list of repeated elements. Related to #263
Browse files Browse the repository at this point in the history
  • Loading branch information
cleftheris committed Jul 5, 2024
1 parent bdf5f01 commit 70a3674
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ test_script:
- ps: dotnet test

artifacts:
- path: artifacts\*.nupkg
- path: artifacts\*nupkg
26 changes: 26 additions & 0 deletions test/indice.Edi.Tests/Models/EdiFact_Issue263.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using indice.Edi.Serialization;

namespace indice.Edi.Tests.Models;
public class Interchange_Issue263
{
public GIN GIN_Segment { get; set; }

[EdiSegment, EdiPath("GIN")]
public class GIN
{
[EdiValue("X(3)", Path = "GIN/0/0")]
public string Qualifier { get; set; }

[EdiPath("GIN/1..*")]
public List<IdentityNumber> IdentityNumbers { get; set; }

[EdiElement]
public class IdentityNumber
{
[EdiValue("X(35)", Path = "GIN/*/0")]
public string Text { get; set; }

}
}
}
26 changes: 26 additions & 0 deletions test/indice.Edi.Tests/SerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Xml.Serialization;
using indice.Edi.Tests.Models;
using Xunit;
using static indice.Edi.Tests.Models.Interchange_Issue263.GIN;

namespace indice.Edi.Tests;

Expand Down Expand Up @@ -464,4 +465,29 @@ string Serialize<T>(T data) {
Regex unbRegex = new Regex("UNB");
Assert.Single(unbRegex.Matches(output));
}

[Fact, Trait(Traits.Tag, "EDIFact"), Trait(Traits.Issue, "#263")]
public void Serialize_Should_Write_List_Of_Repeating_Elements_Issue235() {
var source = new Interchange_Issue263.GIN {
Qualifier = "AW",
IdentityNumbers = [
new () { Text = "9998219" },
new () { Text = "9998218" },
new () { Text = "9998217" },
new () { Text = "9998216" },
new () { Text = "9998215" },
]
};

string Serialize<T>(T data) {
var grammar = EdiGrammar.NewEdiFact();

using var writer = new StringWriter();
new EdiSerializer().Serialize(writer, grammar, data);
return writer.ToString();
}
var expected = $"UNA:+.? '{Environment.NewLine}GIN+AW+9998219+9998218+9998217+9998216+9998215'{Environment.NewLine}";
var output = Serialize(source);
Assert.Equal(expected, output);
}
}
2 changes: 2 additions & 0 deletions test/indice.Edi.Tests/indice.Edi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<Description>indice.Edi.Tests Class Library</Description>
<TargetFrameworks>net60;net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<LangVersion>Latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 70a3674

Please sign in to comment.