Skip to content

Commit 578f44c

Browse files
authored
feat: ✨ convert BO4E ➡ EDIFACT (#7)
1 parent b35755e commit 578f44c

12 files changed

Lines changed: 288 additions & 20 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ Then, you can use the client like this:
3333
## Development
3434

3535
To run the integration test login to your docker to access the transformer.bee image.
36+
3637
```bash
3738
docker login ghcr.io -u YOUR_GITHUB_USERNAME
3839
```
40+
3941
then paste your PAT similarly to described in the [integration test CI pipeline](.github/workflows/integrationtests.yml)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
using EDILibrary;
4+
using FluentAssertions;
5+
using TransformerBeeClient.Model;
6+
using Xunit;
7+
8+
namespace TransformerBeeClient.IntegrationTest;
9+
10+
/// <summary>
11+
/// Tests that a bo4e can be converted to edifact
12+
/// </summary>
13+
public class Bo4eToEdifactTests : IClassFixture<ClientFixture>
14+
{
15+
private readonly ClientFixture _client;
16+
17+
public Bo4eToEdifactTests(ClientFixture clientFixture)
18+
{
19+
_client = clientFixture;
20+
}
21+
22+
[Fact]
23+
public async Task BOneyComb_Can_Be_Converted_To_Edifact()
24+
{
25+
var httpClientFactory = _client.HttpClientFactory;
26+
ICanConvertToEdifact client = new TransformerBeeRestClient(httpClientFactory);
27+
var boneyCombString = await File.ReadAllTextAsync("TestEdifacts/FV2310/55001.json");
28+
var deserializerOptions = new JsonSerializerOptions
29+
{
30+
Converters =
31+
{
32+
new JsonStringEnumConverter()
33+
}
34+
};
35+
var boneyComb = System.Text.Json.JsonSerializer.Deserialize<BOneyComb>(boneyCombString, deserializerOptions);
36+
boneyComb.Should().NotBeNull();
37+
var result = await client.ConvertToEdifact(boneyComb, EdifactFormatVersion.FV2310);
38+
result.Should().BeOfType<string>().And.StartWith("UNB+UNOC");
39+
}
40+
}

TransformerBeeClient/TransformerBeeClient.IntegrationTest/EdifactToBo4eTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using EDILibrary;
22
using FluentAssertions;
3-
using Microsoft.Extensions.DependencyInjection;
43
using TransformerBeeClient.Model;
54
using Xunit;
65

@@ -11,7 +10,6 @@ namespace TransformerBeeClient.IntegrationTest;
1110
/// </summary>
1211
public class EdifactToBo4eTests : IClassFixture<ClientFixture>
1312
{
14-
1513
private readonly ClientFixture _client;
1614

1715
public EdifactToBo4eTests(ClientFixture clientFixture)
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"stammdaten": [
3+
{
4+
"boTyp": "MARKTLOKATION",
5+
"versionStruktur": "1",
6+
"marktlokationsId": "78889918283",
7+
"sparte": "STROM",
8+
"energierichtung": "AUSSP",
9+
"lokationsadresse": {
10+
"postleitzahl": "92247",
11+
"ort": "Vilseck",
12+
"strasse": "Flughafenstrasse",
13+
"hausnummer": "64",
14+
"landescode": "DE"
15+
}
16+
},
17+
{
18+
"boTyp": "VERTRAG",
19+
"versionStruktur": "1",
20+
"vertragsart": "ENERGIELIEFERVERTRAG",
21+
"sparte": "STROM",
22+
"vertragsbeginn": "2022-12-31T23:00:00+00:00",
23+
"vertragspartner2": {
24+
"boTyp": "GESCHAEFTSPARTNER",
25+
"versionStruktur": "1",
26+
"anrede": "FRAU",
27+
"name1": "Schaefer",
28+
"name2": "Ulrike",
29+
"gewerbekennzeichnung": false,
30+
"partneradresse": {
31+
"postleitzahl": "92247",
32+
"ort": "Vilseck",
33+
"strasse": "Flughafenstrasse",
34+
"hausnummer": "64",
35+
"landescode": "DE"
36+
},
37+
"grundlageZurVerringerungDerUmlagenNachEnfg": "KEINE_ANGABE"
38+
},
39+
"vertragskonditionen": {
40+
"haushaltskunde": true,
41+
"netznutzungsvertrag": "LIEFERANTEN_NB",
42+
"netznutzungszahler": "LIEFERANT"
43+
},
44+
"gemeinderabatt": 0
45+
},
46+
{
47+
"boTyp": "ZAEHLER",
48+
"versionStruktur": "1",
49+
"zaehlernummer": "788811123",
50+
"sparte": "STROM",
51+
"zaehlerkonstante": 1
52+
},
53+
{
54+
"boTyp": "MESSLOKATION",
55+
"versionStruktur": "1",
56+
"messlokationsId": "DE0000111122223333444455556667778",
57+
"sparte": "STROM"
58+
},
59+
{
60+
"boTyp": "ANSPRECHPARTNER",
61+
"versionStruktur": "1",
62+
"anrede": "FRAU",
63+
"vorname": "Ulrike",
64+
"nachname": "Schaefer",
65+
"adresse": {
66+
"postleitzahl": "92247",
67+
"ort": "Vilseck",
68+
"strasse": "Flughafenstrasse",
69+
"hausnummer": "64",
70+
"landescode": "DE"
71+
},
72+
"zustaendigkeit": [
73+
{
74+
"themengebiet": "MSCONS"
75+
}
76+
],
77+
"gewerbekennzeichnung": false
78+
},
79+
{
80+
"boTyp": "ANSPRECHPARTNER",
81+
"versionStruktur": "1",
82+
"anrede": "FRAU",
83+
"vorname": "Ulrike",
84+
"nachname": "Schaefer",
85+
"adresse": {
86+
"postleitzahl": "92247",
87+
"ort": "Vilseck",
88+
"strasse": "Flughafenstrasse",
89+
"hausnummer": "64",
90+
"landescode": "DE"
91+
},
92+
"zustaendigkeit": [
93+
{
94+
"themengebiet": "LIEFERANTENWECHSEL"
95+
}
96+
],
97+
"gewerbekennzeichnung": false
98+
},
99+
{
100+
"boTyp": "BILANZIERUNG",
101+
"versionStruktur": "1",
102+
"bilanzkreis": "11X0-0000-0116-J"
103+
},
104+
{
105+
"boTyp": "MARKTTEILNEHMER",
106+
"versionStruktur": "1",
107+
"gewerbekennzeichnung": true,
108+
"rollencodenummer": "9912345789012",
109+
"rollencodetyp": "BDEW"
110+
},
111+
{
112+
"boTyp": "MARKTTEILNEHMER",
113+
"versionStruktur": "1",
114+
"gewerbekennzeichnung": true,
115+
"rollencodenummer": "9909876543210",
116+
"rollencodetyp": "BDEW"
117+
}
118+
],
119+
"links": {
120+
"bo4e://Messlokation/DE0000111122223333444455556667778/Messlokationszaehler": [
121+
"bo4e://zaehler/788811123"
122+
]
123+
},
124+
"transaktionsdaten": {
125+
"sparte": "STROM",
126+
"vorgangsnummer": "918273746512345678901",
127+
"identifikationslogik": "Z13",
128+
"transaktionsgrund": "E01",
129+
"lieferrichtung": "AUSSP",
130+
"vertragsbeginn": "2022-12-31T23:00:00Z",
131+
"pruefidentifikator": "55001",
132+
"messlokation": "DE0000111122223333444455556667778",
133+
"datenaustauschreferenz": "ASDFHGJ",
134+
"absender": "bo4e://Marktteilnehmer/9912345789012",
135+
"empfaenger": "bo4e://Marktteilnehmer/9909876543210",
136+
"dokumentennummer": "918273746512345678901",
137+
"kategorie": "E01",
138+
"nachrichtendatum": "2023-06-30T05:58:00Z",
139+
"nachrichtenReferenznummer": "11223344556678"
140+
}
141+
}

TransformerBeeClient/TransformerBeeClient.IntegrationTest/TransformerBeeClient.IntegrationTest.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<None Update="TestEdifacts\FV2310\55001.edi">
2727
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2828
</None>
29+
<None Update="TestEdifacts\FV2310\55001.json">
30+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
31+
</None>
2932
</ItemGroup>
3033

3134
</Project>

TransformerBeeClient/TransformerBeeClient.IntegrationTest/UnitTest1.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2-
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=de4efd69_002D9f4a_002D4e00_002D83fa_002Ddaa381865bd8/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="ConnectionTest" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
2+
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=1c8bdc71_002Dfc3e_002D44fe_002D9812_002D1b49b4ba3413/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
3+
&lt;Solution /&gt;&#xD;
4+
&lt;/SessionState&gt;</s:String>
5+
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=4fa21289_002Debff_002D4c5a_002D8d89_002D3c311da32c05/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="All tests from Solution #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
6+
&lt;Solution /&gt;&#xD;
7+
&lt;/SessionState&gt;</s:String>
8+
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=591857ee_002D832a_002D4abe_002D964d_002Db61be9cce36e/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="BOneyComb_Can_Be_Converted_To_Edifact" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
39
&lt;TestAncestor&gt;&#xD;
4-
&lt;TestId&gt;xUnit::80EF1570-CB4E-4E56-A8BC-56C787A48543::net8.0::TransformerBeeClient.UnitTest.ConnectionTests&lt;/TestId&gt;&#xD;
5-
&lt;TestId&gt;xUnit::77598126-7BB0-4C07-BF06-331033E0DE78::net8.0::TransformerBeeClient.IntegrationTest.EdifactToBo4eTests.Edifact_Shall_Be_Converted_To_Bo4e&lt;/TestId&gt;&#xD;
10+
&lt;TestId&gt;xUnit::77598126-7BB0-4C07-BF06-331033E0DE78::net8.0::TransformerBeeClient.IntegrationTest.Bo4eToEdifactTests.BOneyComb_Can_Be_Converted_To_Edifact&lt;/TestId&gt;&#xD;
611
&lt;/TestAncestor&gt;&#xD;
12+
&lt;/SessionState&gt;</s:String>
13+
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=de4efd69_002D9f4a_002D4e00_002D83fa_002Ddaa381865bd8/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="ConnectionTest" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
14+
&lt;Solution /&gt;&#xD;
715
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>

TransformerBeeClient/TransformerBeeClient/Interfaces.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,18 @@ public interface ICanConvertToBo4e
1717
/// <returns><see cref="Marktnachricht"/></returns>
1818
public Task<List<Marktnachricht>> ConvertToBo4e(string edifact, EdifactFormatVersion formatVersion);
1919
}
20+
21+
/// <summary>
22+
/// Interface of all the things that can convert EDIFACT to BO4E
23+
/// </summary>
24+
/// <remarks>This will be useful if you want to mock the client elsewhere</remarks>
25+
public interface ICanConvertToEdifact
26+
{
27+
/// <summary>
28+
/// convert bo4e to edifact
29+
/// </summary>
30+
/// <param name="boneyComb">transaktion/Geschäftsvorfall as boneycomb</param>
31+
/// <param name="formatVersion"><see cref="EdifactFormatVersion"/></param>
32+
/// <returns>the edifact as plain string</returns>
33+
public Task<string> ConvertToEdifact(BOneyComb boneyComb, EdifactFormatVersion formatVersion);
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using EDILibrary;
2+
3+
namespace TransformerBeeClient.Model;
4+
5+
/// <summary>
6+
/// The request to convert a single transaction/BOneyComb to edifact
7+
/// </summary>
8+
internal class Bo4eTransactionToEdifactRequest
9+
{
10+
// internally we only use system.text, no newtonsoft
11+
12+
/// <summary>
13+
/// the BOneyComb as json string
14+
/// </summary>
15+
[System.Text.Json.Serialization.JsonPropertyName("BO4E")]
16+
public string Bo4eJsonString { get; set; }
17+
18+
/// <summary>
19+
/// the format version to use
20+
/// </summary>
21+
[System.Text.Json.Serialization.JsonPropertyName("FormatPackage")]
22+
public EdifactFormatVersion FormatVersion { get; set; }
23+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace TransformerBeeClient.Model;
2+
3+
/// <summary>
4+
/// The response to a <see cref="Bo4eTransactionToEdifactRequest"/>
5+
/// </summary>
6+
internal class Bo4eTransactionToEdifactResponse
7+
{
8+
// internally we only use system.text, no newtonsoft
9+
10+
/// <summary>
11+
/// the edifact as plain string
12+
/// </summary>
13+
[System.Text.Json.Serialization.JsonPropertyName("EDI")]
14+
public string Edifact { get; set; }
15+
}

0 commit comments

Comments
 (0)