From 06d5c0eb6270a6bb499e4ad55f5ec72e9ac50357 Mon Sep 17 00:00:00 2001 From: konstantin Date: Thu, 1 Feb 2024 18:07:40 +0000 Subject: [PATCH 01/12] add docs --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ebe5d64..2d11220 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,20 @@ dotnet add package TransformerBeeClient ### Use it in your code -Then, you can use the client like this: +This library is thought to be used in ASP.NET Core applications. +That's why it assumes that you have an `IHttpClientFactory` available in your dependency injection container. +Then, setup your dependency injection container like this: ```csharp - +using TransformerBeeClient; +// ... +builder.Services.AddHttpClient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); ``` +If you're not using ASP.NET Core, you can still use this library, by using [this little workaround](https://chat.openai.com/share/fa63110a-646e-4fd1-aacb-3d449c285750). + ## Development ### Integration Tests From 3624171917c884298fce36b5372872a7836e9b37 Mon Sep 17 00:00:00 2001 From: konstantin Date: Thu, 1 Feb 2024 18:09:28 +0000 Subject: [PATCH 02/12] add example app --- TransformerBeeClient/.gitignore | 2 + .../ExampleAspNetCoreApplication.csproj | 13 +++++++ .../ExampleAspNetCoreApplication/Program.cs | 11 ++++++ .../Properties/launchSettings.json | 38 +++++++++++++++++++ .../appsettings.Development.json | 8 ++++ .../appsettings.json | 9 +++++ 6 files changed, 81 insertions(+) create mode 100644 TransformerBeeClient/ExampleAspNetCoreApplication/ExampleAspNetCoreApplication.csproj create mode 100644 TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs create mode 100644 TransformerBeeClient/ExampleAspNetCoreApplication/Properties/launchSettings.json create mode 100644 TransformerBeeClient/ExampleAspNetCoreApplication/appsettings.Development.json create mode 100644 TransformerBeeClient/ExampleAspNetCoreApplication/appsettings.json diff --git a/TransformerBeeClient/.gitignore b/TransformerBeeClient/.gitignore index e2e4cef..0161f82 100644 --- a/TransformerBeeClient/.gitignore +++ b/TransformerBeeClient/.gitignore @@ -4,3 +4,5 @@ TransformerBeeClient.IntegrationTest/obj TransformerBeeClient.IntegrationTest/bin TransformerBeeClient.UnitTest/obj TransformerBeeClient.UnitTest/bin +ExampleAspNetCoreApplication/obj +ExampleAspNetCoreApplication/bin diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication/ExampleAspNetCoreApplication.csproj b/TransformerBeeClient/ExampleAspNetCoreApplication/ExampleAspNetCoreApplication.csproj new file mode 100644 index 0000000..8713d5e --- /dev/null +++ b/TransformerBeeClient/ExampleAspNetCoreApplication/ExampleAspNetCoreApplication.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs b/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs new file mode 100644 index 0000000..0274856 --- /dev/null +++ b/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs @@ -0,0 +1,11 @@ +using TransformerBeeClient; + +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddHttpClient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +var app = builder.Build(); + +app.MapGet("/", () => "Hello World!"); +app.Run(); diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication/Properties/launchSettings.json b/TransformerBeeClient/ExampleAspNetCoreApplication/Properties/launchSettings.json new file mode 100644 index 0000000..65f3f76 --- /dev/null +++ b/TransformerBeeClient/ExampleAspNetCoreApplication/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:26369", + "sslPort": 44341 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5137", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7030;http://localhost:5137", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication/appsettings.Development.json b/TransformerBeeClient/ExampleAspNetCoreApplication/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/TransformerBeeClient/ExampleAspNetCoreApplication/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication/appsettings.json b/TransformerBeeClient/ExampleAspNetCoreApplication/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/TransformerBeeClient/ExampleAspNetCoreApplication/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} From ca679c0e12bdfe69f73c3d94e5b548ce00dba852 Mon Sep 17 00:00:00 2001 From: konstantin Date: Fri, 2 Feb 2024 07:25:42 +0000 Subject: [PATCH 03/12] better --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b709822..9b479c5 100644 --- a/README.md +++ b/README.md @@ -15,34 +15,38 @@ Ask info@hochfrequenz.de or ping @JoschaMetze on GitHub to get one. You can check if your account is working by logging [into our stage environment](https://transformerstage.utilibee.io/app/). ### Using the client -![Nuget Package](https://badgen.net/nuget/v/TransformerBeeClient) -Install it from nuget [TransformerBeeClient](https://www.nuget.org/packages/TransformerBeeClient): + +Install it from nuget [TransformerBeeClient](https://www.nuget.org/packages/TransformerBeeClient) ![Nuget Package](https://badgen.net/nuget/v/TransformerBeeClient): ```bash dotnet add package TransformerBeeClient ``` ### Authentication + You need to provide something that implements `ITransformerBeeAuthenticator` to the `TransformerBeeClient`. #### No Authentication -If you're hosting transformer.bee in the same network and there is no authentication, you can use the `NoAuthenticator`. + +If you're hosting transformer.bee in the same network or your localhost and there is no authentication, you can use the `NoAuthenticator`. + ```csharp using TransformerBeeClient; var myAuthenticator = new NoAuthenticationProvider(); ``` -This library is thought to be used in ASP.NET Core applications. -That's why it assumes that you have an `IHttpClientFactory` available in your dependency injection container. #### OAuth2 Client and Secret -If, which is more likely, Hochfrequenz provided you with a client ID and secret, you can use the `ClientIdClientSecretAuthenticator` class like this: -Then, setup your dependency injection container like this: +If, which is more likely, Hochfrequenz provided you with a client Id and secret, you can use the `ClientIdClientSecretAuthenticator` class like this: + ```csharp using TransformerBeeClient; var myAuthenticator = new ClientIdClientSecretAuthenticationProvider("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET"); ``` -...todo +### General Setup +This library is primarily thought to be used in ASP.NET Core applications. +That's why it assumes that you have an `IHttpClientFactory` available in your dependency injection container. + ```csharp using TransformerBeeClient; @@ -57,6 +61,7 @@ If you're not using ASP.NET Core, you can still use this library, by using [this ## Development ### Integration Tests + To run the integration test login to your docker to access the transformer.bee image. ```bash @@ -66,6 +71,7 @@ docker login ghcr.io -u YOUR_GITHUB_USERNAME then paste your PAT similarly to described in the [integration test CI pipeline](.github/workflows/integrationtests.yml) ### Release (CI/CD) + To release a new version of this library, [create a new release](https://github.com/Hochfrequenz/transformer.bee_client.net/releases/new) in GitHub. Make sure its tag starts with `v` and the version number, e.g. `v1.2.3`. Tags without a release wont trigger the release workflow; This enforces that you have to write a changelog before releasing. From 33db2f8bf4c62dc81fc0b3722071f197eba8a85c Mon Sep 17 00:00:00 2001 From: konstantin Date: Fri, 2 Feb 2024 07:26:00 +0000 Subject: [PATCH 04/12] Auto stash before merge of "docs-and-tests" and "origin/main" --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 9b479c5..bad6e49 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,13 @@ That's why it assumes that you have an `IHttpClientFactory` available in your de ```csharp +using TransformerBeeClient; +var myAuthenticator = new ClientIdClientSecretAuthenticationProvider("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET"); +``` + +...todo +```csharp + using TransformerBeeClient; // ... builder.Services.AddHttpClient(); From dbf65f75dc036c52019ed7b0878abf3344361b00 Mon Sep 17 00:00:00 2001 From: konstantin Date: Fri, 2 Feb 2024 07:42:49 +0000 Subject: [PATCH 05/12] =?UTF-8?q?bab=C3=A4m?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExampleAspNetCoreApplication/Program.cs | 16 +++++++++++++++- TransformerBeeClient/TransformerBeeClient.sln | 6 ++++++ .../TransformerBeeClient.sln.DotSettings.user | 16 ++++------------ .../TransformerBeeClient/RestClient.cs | 6 ++++-- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs b/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs index 0274856..22c7e4a 100644 --- a/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs +++ b/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs @@ -1,11 +1,25 @@ +using EDILibrary; using TransformerBeeClient; var builder = WebApplication.CreateBuilder(args); builder.Services.AddHttpClient(); + +builder.Services.AddTransient(); // Or you could use ClientIdClientSecretAuthenticator +builder.Services.AddHttpClient("TransformerBee", client => +{ + client.BaseAddress = new Uri("http://localhost:5021/"); // or https://transformerstage.utilibee.io +}); builder.Services.AddTransient(); builder.Services.AddTransient(); var app = builder.Build(); -app.MapGet("/", () => "Hello World!"); +app.MapGet("/", () => "I ❤ BO4E"); +app.MapGet("/talkToTransformerBee", async (ITransformerBeeAuthenticator authenticator, ICanConvertToBo4e transformerBeeRestClient) => +{ + var bo4e = await transformerBeeRestClient.ConvertToBo4e( + "UNA:+,? 'UNB+UNOC:3+9912345789012:500+9909876543210:500+230703:1059+ASDFHGJ'UNH+11223344556678+UTILMD:D:11A:UN:S1.1'BGM+E01+918273746512345678901'DTM+137:202306300558?+00:303'NAD+MS+9912345789012::293'NAD+MR+9909876543210::293'IDE+24+918273746512345678901'IMD++Z36+Z13'DTM+92:202212312300?+00:303'STS+7++E01'LOC+Z16+78889918283'LOC+Z17+DE0000111122223333444455556667778'RFF+Z13:55001'SEQ+Z01'CCI+Z30++Z07'CCI+Z19++11X0-0000-0116-J'CCI+++Z15'CCI+++Z88'CAV+Z74:::Z09'CAV+Z73:::Z11'SEQ+Z12'QTY+Z16:0:P1'SEQ+Z03'CCI+++E13'CAV+Z30:::788811123'SEQ+Z75'CCI+Z61++ZG1'NAD+Z09+++Schaefer:Ulrike:::Frau:Z01'NAD+Z04+++Schaefer:Ulrike:::Frau:Z01+Flughafenstrasse::64+Vilseck++92247+DE'NAD+DP++++Flughafenstrasse::64+Vilseck++92247+DE'NAD+Z05+++Schaefer:Ulrike:::Frau:Z01+Flughafenstrasse::64+Vilseck++92247+DE'UNT+31+11223344556678'UNZ+1+ASDFHGJ'", + EdifactFormatVersion.FV2310); + return bo4e; +}); app.Run(); diff --git a/TransformerBeeClient/TransformerBeeClient.sln b/TransformerBeeClient/TransformerBeeClient.sln index fda50dd..2be9d96 100644 --- a/TransformerBeeClient/TransformerBeeClient.sln +++ b/TransformerBeeClient/TransformerBeeClient.sln @@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransformerBeeClient.UnitTe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransformerBeeClient.IntegrationTest", "TransformerBeeClient.IntegrationTest\TransformerBeeClient.IntegrationTest.csproj", "{77598126-7BB0-4C07-BF06-331033E0DE78}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleAspNetCoreApplication", "ExampleAspNetCoreApplication\ExampleAspNetCoreApplication.csproj", "{E6F6E532-9758-46C0-AC04-42CC054613C7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,5 +26,9 @@ Global {77598126-7BB0-4C07-BF06-331033E0DE78}.Debug|Any CPU.Build.0 = Debug|Any CPU {77598126-7BB0-4C07-BF06-331033E0DE78}.Release|Any CPU.ActiveCfg = Release|Any CPU {77598126-7BB0-4C07-BF06-331033E0DE78}.Release|Any CPU.Build.0 = Release|Any CPU + {E6F6E532-9758-46C0-AC04-42CC054613C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E6F6E532-9758-46C0-AC04-42CC054613C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E6F6E532-9758-46C0-AC04-42CC054613C7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E6F6E532-9758-46C0-AC04-42CC054613C7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/TransformerBeeClient/TransformerBeeClient.sln.DotSettings.user b/TransformerBeeClient/TransformerBeeClient.sln.DotSettings.user index 49d9287..40c3a5d 100644 --- a/TransformerBeeClient/TransformerBeeClient.sln.DotSettings.user +++ b/TransformerBeeClient/TransformerBeeClient.sln.DotSettings.user @@ -1,15 +1,7 @@ - <SessionState ContinuousTestingMode="0" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + + <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> <Solution /> </SessionState> - <SessionState ContinuousTestingMode="0" Name="All tests from Solution #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <Solution /> -</SessionState> - <SessionState ContinuousTestingMode="0" IsActive="True" Name="BOneyComb_Can_Be_Converted_To_Edifact" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <TestAncestor> - <TestId>xUnit::77598126-7BB0-4C07-BF06-331033E0DE78::net8.0::TransformerBeeClient.IntegrationTest.Bo4eToEdifactTests.BOneyComb_Can_Be_Converted_To_Edifact</TestId> - </TestAncestor> -</SessionState> - <SessionState ContinuousTestingMode="0" Name="ConnectionTest" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <Solution /> -</SessionState> \ No newline at end of file + + \ No newline at end of file diff --git a/TransformerBeeClient/TransformerBeeClient/RestClient.cs b/TransformerBeeClient/TransformerBeeClient/RestClient.cs index 3628e2b..4978ecc 100644 --- a/TransformerBeeClient/TransformerBeeClient/RestClient.cs +++ b/TransformerBeeClient/TransformerBeeClient/RestClient.cs @@ -108,12 +108,13 @@ public async Task> ConvertToBo4e(string edifact, EdifactFor var httpResponse = await _httpClient.PostAsync(convertUrl, new StringContent(requestJson, Encoding.UTF8, "application/json")); if (!httpResponse.IsSuccessStatusCode) { + var errorContent = await httpResponse.Content.ReadAsStringAsync(); if (httpResponse.StatusCode == HttpStatusCode.Unauthorized && !_authenticator.UseAuthentication()) { throw new AuthenticationException($"Did you correctly set up the {nameof(ITransformerBeeAuthenticator)}?"); } - throw new HttpRequestException($"Could not convert {edifact} to BO4E. Status code: {httpResponse.StatusCode}"); + throw new HttpRequestException($"Could not convert {edifact} to BO4E. Status code: {httpResponse.StatusCode} / {errorContent}"); } var responseContent = await httpResponse.Content.ReadAsStringAsync(); @@ -149,12 +150,13 @@ public async Task ConvertToEdifact(BOneyComb boneyComb, EdifactFormatVer var httpResponse = await _httpClient.PostAsync(convertUrl, new StringContent(requestJson, Encoding.UTF8, "application/json")); if (!httpResponse.IsSuccessStatusCode) { + var errorContent = await httpResponse.Content.ReadAsStringAsync(); if (httpResponse.StatusCode == HttpStatusCode.Unauthorized && !_authenticator.UseAuthentication()) { throw new AuthenticationException($"Did you correctly set up the {nameof(ITransformerBeeAuthenticator)}?"); } - throw new HttpRequestException($"Could not convert to EDIFACT; Status code: {httpResponse.StatusCode}"); + throw new HttpRequestException($"Could not convert to EDIFACT; Status code: {httpResponse.StatusCode} / {errorContent}"); } var responseContent = await httpResponse.Content.ReadAsStringAsync(); From 5642b8b722f002afe1a9923ccbd7e7b74d4443d2 Mon Sep 17 00:00:00 2001 From: konstantin Date: Fri, 2 Feb 2024 07:54:17 +0000 Subject: [PATCH 06/12] besser --- README.md | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index bad6e49..e04aea2 100644 --- a/README.md +++ b/README.md @@ -43,27 +43,13 @@ using TransformerBeeClient; var myAuthenticator = new ClientIdClientSecretAuthenticationProvider("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET"); ``` -### General Setup +### Use with ASP.NET Core This library is primarily thought to be used in ASP.NET Core applications. That's why it assumes that you have an `IHttpClientFactory` available in your dependency injection container. +See the [`ExampleAspNetCoreApplication/Program.cs`](TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs) for a minimal working example. -```csharp - -using TransformerBeeClient; -var myAuthenticator = new ClientIdClientSecretAuthenticationProvider("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET"); -``` - -...todo -```csharp - -using TransformerBeeClient; -// ... -builder.Services.AddHttpClient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -``` +### Use without ASP.NET Core -If you're not using ASP.NET Core, you can still use this library, by using [this little workaround](https://chat.openai.com/share/fa63110a-646e-4fd1-aacb-3d449c285750). ## Development From f3f9633383a376ec8cbecc0f55b60082d1ef4cce Mon Sep 17 00:00:00 2001 From: konstantin Date: Fri, 2 Feb 2024 08:29:43 +0000 Subject: [PATCH 07/12] est --- .github/workflows/integrationtests.yml | 5 +++ README.md | 5 +-- TransformerBeeClient/.gitignore | 2 ++ .../ApplicationTest.cs | 30 +++++++++++++++++ .../ExampleAspNetCoreApplication.Test.csproj | 31 +++++++++++++++++ .../GlobalUsings.cs | 1 + .../xunit.runner.json | 3 ++ .../ExampleAspNetCoreApplication.csproj | 4 +-- .../ExampleAspNetCoreApplication/Program.cs | 4 +-- .../Properties/launchSettings.json | 2 +- .../MweWithoutAspNetTest.cs | 33 +++++++++++++++++++ TransformerBeeClient/TransformerBeeClient.sln | 6 ++++ 12 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 TransformerBeeClient/ExampleAspNetCoreApplication.Test/ApplicationTest.cs create mode 100644 TransformerBeeClient/ExampleAspNetCoreApplication.Test/ExampleAspNetCoreApplication.Test.csproj create mode 100644 TransformerBeeClient/ExampleAspNetCoreApplication.Test/GlobalUsings.cs create mode 100644 TransformerBeeClient/ExampleAspNetCoreApplication.Test/xunit.runner.json create mode 100644 TransformerBeeClient/TransformerBeeClient.IntegrationTest/MweWithoutAspNetTest.cs diff --git a/.github/workflows/integrationtests.yml b/.github/workflows/integrationtests.yml index 42b38b2..8a4f106 100644 --- a/.github/workflows/integrationtests.yml +++ b/.github/workflows/integrationtests.yml @@ -55,3 +55,8 @@ jobs: CLIENT_SECRET: ${{ secrets.AUTH0_TEST_CLIENT_SECRET }} run: | dotnet test --filter TestCollectionName='authenticated' + - name: Run Integration Tests for Example Application + working-directory: TransformerBeeClient/ExampleAspNetCoreApplication + run: | + dotnet build --no-restore + dotnet test diff --git a/README.md b/README.md index e04aea2..33a96ad 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,13 @@ var myAuthenticator = new ClientIdClientSecretAuthenticationProvider("YOUR_CLIEN ``` ### Use with ASP.NET Core -This library is primarily thought to be used in ASP.NET Core applications. +This library is thought to be primarily used in ASP.NET Core applications. That's why it assumes that you have an `IHttpClientFactory` available in your dependency injection container. See the [`ExampleAspNetCoreApplication/Program.cs`](TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs) for a minimal working example. ### Use without ASP.NET Core - +If you're not using ASP.NET Core, you can still use this library but setting up th `IHttpClientFactory` comes with a bit of boilerplate. +See the [`MweWithoutAspNetTest.cs`](TransformerBeeClient/TransformerBeeClient.IntegrationTest/MweWithoutAspNetTest.cs) for a minimal working example. ## Development diff --git a/TransformerBeeClient/.gitignore b/TransformerBeeClient/.gitignore index 0161f82..c17cef6 100644 --- a/TransformerBeeClient/.gitignore +++ b/TransformerBeeClient/.gitignore @@ -6,3 +6,5 @@ TransformerBeeClient.UnitTest/obj TransformerBeeClient.UnitTest/bin ExampleAspNetCoreApplication/obj ExampleAspNetCoreApplication/bin +ExampleAspNetCoreApplication.Test/obj +ExampleAspNetCoreApplication.Test/bin diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication.Test/ApplicationTest.cs b/TransformerBeeClient/ExampleAspNetCoreApplication.Test/ApplicationTest.cs new file mode 100644 index 0000000..93aaaaf --- /dev/null +++ b/TransformerBeeClient/ExampleAspNetCoreApplication.Test/ApplicationTest.cs @@ -0,0 +1,30 @@ +using System.Net; +using System.Text.Json; +using System.Text.Json.Serialization; +using FluentAssertions; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.VisualStudio.TestPlatform.TestHost; +using TransformerBeeClient.Model; + +namespace ExampleAspNetCoreApplication.Test; + +public class ApplicationTest : IClassFixture> +{ + protected readonly WebApplicationFactory Factory; + + public ApplicationTest(WebApplicationFactory factory) + { + Factory = factory; + } + + [Fact] + public async Task Test_That_Setup_Works_As_Designed() + { + var client = Factory.CreateDefaultClient(); + var response = await client.GetAsync("/talkToTransformerBee"); + response.StatusCode.Should().Be(HttpStatusCode.OK); + var content = await response.Content.ReadAsStringAsync(); + var bo4e = JsonSerializer.Deserialize(content, new JsonSerializerOptions() { Converters = { new JsonStringEnumConverter() } }); + bo4e.Should().NotBeNull(); + } +} diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication.Test/ExampleAspNetCoreApplication.Test.csproj b/TransformerBeeClient/ExampleAspNetCoreApplication.Test/ExampleAspNetCoreApplication.Test.csproj new file mode 100644 index 0000000..337c0e5 --- /dev/null +++ b/TransformerBeeClient/ExampleAspNetCoreApplication.Test/ExampleAspNetCoreApplication.Test.csproj @@ -0,0 +1,31 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication.Test/GlobalUsings.cs b/TransformerBeeClient/ExampleAspNetCoreApplication.Test/GlobalUsings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/TransformerBeeClient/ExampleAspNetCoreApplication.Test/GlobalUsings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication.Test/xunit.runner.json b/TransformerBeeClient/ExampleAspNetCoreApplication.Test/xunit.runner.json new file mode 100644 index 0000000..42db7ef --- /dev/null +++ b/TransformerBeeClient/ExampleAspNetCoreApplication.Test/xunit.runner.json @@ -0,0 +1,3 @@ +{ + "shadowCopy": false +} diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication/ExampleAspNetCoreApplication.csproj b/TransformerBeeClient/ExampleAspNetCoreApplication/ExampleAspNetCoreApplication.csproj index 8713d5e..c2949f6 100644 --- a/TransformerBeeClient/ExampleAspNetCoreApplication/ExampleAspNetCoreApplication.csproj +++ b/TransformerBeeClient/ExampleAspNetCoreApplication/ExampleAspNetCoreApplication.csproj @@ -4,10 +4,10 @@ net8.0 enable enable + true - + - diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs b/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs index 22c7e4a..bb9dfbd 100644 --- a/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs +++ b/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs @@ -15,11 +15,11 @@ var app = builder.Build(); app.MapGet("/", () => "I ❤ BO4E"); -app.MapGet("/talkToTransformerBee", async (ITransformerBeeAuthenticator authenticator, ICanConvertToBo4e transformerBeeRestClient) => +app.MapGet("/talkToTransformerBee", async (ICanConvertToBo4e transformerBeeRestClient) => { var bo4e = await transformerBeeRestClient.ConvertToBo4e( "UNA:+,? 'UNB+UNOC:3+9912345789012:500+9909876543210:500+230703:1059+ASDFHGJ'UNH+11223344556678+UTILMD:D:11A:UN:S1.1'BGM+E01+918273746512345678901'DTM+137:202306300558?+00:303'NAD+MS+9912345789012::293'NAD+MR+9909876543210::293'IDE+24+918273746512345678901'IMD++Z36+Z13'DTM+92:202212312300?+00:303'STS+7++E01'LOC+Z16+78889918283'LOC+Z17+DE0000111122223333444455556667778'RFF+Z13:55001'SEQ+Z01'CCI+Z30++Z07'CCI+Z19++11X0-0000-0116-J'CCI+++Z15'CCI+++Z88'CAV+Z74:::Z09'CAV+Z73:::Z11'SEQ+Z12'QTY+Z16:0:P1'SEQ+Z03'CCI+++E13'CAV+Z30:::788811123'SEQ+Z75'CCI+Z61++ZG1'NAD+Z09+++Schaefer:Ulrike:::Frau:Z01'NAD+Z04+++Schaefer:Ulrike:::Frau:Z01+Flughafenstrasse::64+Vilseck++92247+DE'NAD+DP++++Flughafenstrasse::64+Vilseck++92247+DE'NAD+Z05+++Schaefer:Ulrike:::Frau:Z01+Flughafenstrasse::64+Vilseck++92247+DE'UNT+31+11223344556678'UNZ+1+ASDFHGJ'", EdifactFormatVersion.FV2310); - return bo4e; + return bo4e.Single().Transaktionen.Single(); }); app.Run(); diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication/Properties/launchSettings.json b/TransformerBeeClient/ExampleAspNetCoreApplication/Properties/launchSettings.json index 65f3f76..4f9c37b 100644 --- a/TransformerBeeClient/ExampleAspNetCoreApplication/Properties/launchSettings.json +++ b/TransformerBeeClient/ExampleAspNetCoreApplication/Properties/launchSettings.json @@ -1,4 +1,4 @@ -{ +{ "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, diff --git a/TransformerBeeClient/TransformerBeeClient.IntegrationTest/MweWithoutAspNetTest.cs b/TransformerBeeClient/TransformerBeeClient.IntegrationTest/MweWithoutAspNetTest.cs new file mode 100644 index 0000000..7b00456 --- /dev/null +++ b/TransformerBeeClient/TransformerBeeClient.IntegrationTest/MweWithoutAspNetTest.cs @@ -0,0 +1,33 @@ +using EDILibrary; +using Xunit; + +namespace TransformerBeeClient.IntegrationTest; + +/// +/// A minimal working example on how to use this library without ASP.NET +/// +public class MweWithoutAspNetTest +{ + /// + /// in asp.net applications, there's a service collection that is used to create the http client factory for you + /// + internal class MyHttpClientFactory : IHttpClientFactory + { + public HttpClient CreateClient(string name) + { + return new HttpClient + { + BaseAddress = new Uri("http://localhost:5021") + }; + } + } + + [Fact] + public async Task Test_Transformer_Bee_Communication() + { + IHttpClientFactory myFactory = new MyHttpClientFactory(); + ITransformerBeeAuthenticator myAuthenticator = new NoAuthenticator(); // or use ClientIdClientSecretAuthenticator + var client = new TransformerBeeRestClient(myFactory, myAuthenticator); + await client.ConvertToBo4e("UNA:+,? 'UNB+UNOC:3+9912345789012:500+9909876543210:500+230703:1059+ASDFHGJ'UNH+11223344556678+UTILMD:D:11A:UN:S1.1'BGM+E01+918273746512345678901'DTM+137:202306300558?+00:303'NAD+MS+9912345789012::293'NAD+MR+9909876543210::293'IDE+24+918273746512345678901'IMD++Z36+Z13'DTM+92:202212312300?+00:303'STS+7++E01'LOC+Z16+78889918283'LOC+Z17+DE0000111122223333444455556667778'RFF+Z13:55001'SEQ+Z01'CCI+Z30++Z07'CCI+Z19++11X0-0000-0116-J'CCI+++Z15'CCI+++Z88'CAV+Z74:::Z09'CAV+Z73:::Z11'SEQ+Z12'QTY+Z16:0:P1'SEQ+Z03'CCI+++E13'CAV+Z30:::788811123'SEQ+Z75'CCI+Z61++ZG1'NAD+Z09+++Schaefer:Ulrike:::Frau:Z01'NAD+Z04+++Schaefer:Ulrike:::Frau:Z01+Flughafenstrasse::64+Vilseck++92247+DE'NAD+DP++++Flughafenstrasse::64+Vilseck++92247+DE'NAD+Z05+++Schaefer:Ulrike:::Frau:Z01+Flughafenstrasse::64+Vilseck++92247+DE'UNT+31+11223344556678'UNZ+1+ASDFHGJ'", EdifactFormatVersion.FV2310); + } +} diff --git a/TransformerBeeClient/TransformerBeeClient.sln b/TransformerBeeClient/TransformerBeeClient.sln index 2be9d96..eda3ec5 100644 --- a/TransformerBeeClient/TransformerBeeClient.sln +++ b/TransformerBeeClient/TransformerBeeClient.sln @@ -8,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransformerBeeClient.Integr EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleAspNetCoreApplication", "ExampleAspNetCoreApplication\ExampleAspNetCoreApplication.csproj", "{E6F6E532-9758-46C0-AC04-42CC054613C7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleAspNetCoreApplication.Test", "ExampleAspNetCoreApplication.Test\ExampleAspNetCoreApplication.Test.csproj", "{39992205-201D-445B-A58D-BB098F5EFC1D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -30,5 +32,9 @@ Global {E6F6E532-9758-46C0-AC04-42CC054613C7}.Debug|Any CPU.Build.0 = Debug|Any CPU {E6F6E532-9758-46C0-AC04-42CC054613C7}.Release|Any CPU.ActiveCfg = Release|Any CPU {E6F6E532-9758-46C0-AC04-42CC054613C7}.Release|Any CPU.Build.0 = Release|Any CPU + {39992205-201D-445B-A58D-BB098F5EFC1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {39992205-201D-445B-A58D-BB098F5EFC1D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {39992205-201D-445B-A58D-BB098F5EFC1D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {39992205-201D-445B-A58D-BB098F5EFC1D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal From b0590dea03adb679f3d3616d8d1456264e427924 Mon Sep 17 00:00:00 2001 From: konstantin Date: Fri, 2 Feb 2024 08:30:47 +0000 Subject: [PATCH 08/12] bom --- .../ExampleAspNetCoreApplication.Test/xunit.runner.json | 2 +- .../ExampleAspNetCoreApplication.csproj | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication.Test/xunit.runner.json b/TransformerBeeClient/ExampleAspNetCoreApplication.Test/xunit.runner.json index 42db7ef..1c72a42 100644 --- a/TransformerBeeClient/ExampleAspNetCoreApplication.Test/xunit.runner.json +++ b/TransformerBeeClient/ExampleAspNetCoreApplication.Test/xunit.runner.json @@ -1,3 +1,3 @@ -{ +{ "shadowCopy": false } diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication/ExampleAspNetCoreApplication.csproj b/TransformerBeeClient/ExampleAspNetCoreApplication/ExampleAspNetCoreApplication.csproj index c2949f6..0bc8314 100644 --- a/TransformerBeeClient/ExampleAspNetCoreApplication/ExampleAspNetCoreApplication.csproj +++ b/TransformerBeeClient/ExampleAspNetCoreApplication/ExampleAspNetCoreApplication.csproj @@ -6,7 +6,6 @@ enable true - From 4d6c5045bc064cfa65d0d6021d21292adf6c743d Mon Sep 17 00:00:00 2001 From: konstantin Date: Fri, 2 Feb 2024 08:31:56 +0000 Subject: [PATCH 09/12] fix path --- .github/workflows/integrationtests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integrationtests.yml b/.github/workflows/integrationtests.yml index 8a4f106..91042ed 100644 --- a/.github/workflows/integrationtests.yml +++ b/.github/workflows/integrationtests.yml @@ -56,7 +56,7 @@ jobs: run: | dotnet test --filter TestCollectionName='authenticated' - name: Run Integration Tests for Example Application - working-directory: TransformerBeeClient/ExampleAspNetCoreApplication + working-directory: TransformerBeeClient/ExampleAspNetCoreApplication.IntegrationTest run: | dotnet build --no-restore dotnet test From 17ba8b94775a234029b8f1634e833b7175f4c45f Mon Sep 17 00:00:00 2001 From: konstantin Date: Fri, 2 Feb 2024 08:34:21 +0000 Subject: [PATCH 10/12] add repo and license --- .../TransformerBeeClient/TransformerBeeClient.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TransformerBeeClient/TransformerBeeClient/TransformerBeeClient.csproj b/TransformerBeeClient/TransformerBeeClient/TransformerBeeClient.csproj index 5489d3b..3d5dea4 100644 --- a/TransformerBeeClient/TransformerBeeClient/TransformerBeeClient.csproj +++ b/TransformerBeeClient/TransformerBeeClient/TransformerBeeClient.csproj @@ -4,6 +4,8 @@ enable enable net8.0;net6.0;net7.0 + https://github.com/Hochfrequenz/transformer.bee_client.net + MIT From 05f85b6bc53502482c9a4e30a85d1b63d225ae87 Mon Sep 17 00:00:00 2001 From: konstantin Date: Fri, 2 Feb 2024 08:34:53 +0000 Subject: [PATCH 11/12] fix path, again --- .github/workflows/integrationtests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integrationtests.yml b/.github/workflows/integrationtests.yml index 91042ed..8a24b08 100644 --- a/.github/workflows/integrationtests.yml +++ b/.github/workflows/integrationtests.yml @@ -56,7 +56,7 @@ jobs: run: | dotnet test --filter TestCollectionName='authenticated' - name: Run Integration Tests for Example Application - working-directory: TransformerBeeClient/ExampleAspNetCoreApplication.IntegrationTest + working-directory: TransformerBeeClient/ExampleAspNetCoreApplication.Test run: | dotnet build --no-restore dotnet test From f9a57b37522b8adfc0de443101aec22de82e74ce Mon Sep 17 00:00:00 2001 From: konstantin Date: Fri, 2 Feb 2024 08:43:33 +0000 Subject: [PATCH 12/12] hereeeeere we go --- .../ExampleAspNetCoreApplication.Test/ApplicationTest.cs | 3 +-- TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication.Test/ApplicationTest.cs b/TransformerBeeClient/ExampleAspNetCoreApplication.Test/ApplicationTest.cs index 93aaaaf..df0bb78 100644 --- a/TransformerBeeClient/ExampleAspNetCoreApplication.Test/ApplicationTest.cs +++ b/TransformerBeeClient/ExampleAspNetCoreApplication.Test/ApplicationTest.cs @@ -3,7 +3,6 @@ using System.Text.Json.Serialization; using FluentAssertions; using Microsoft.AspNetCore.Mvc.Testing; -using Microsoft.VisualStudio.TestPlatform.TestHost; using TransformerBeeClient.Model; namespace ExampleAspNetCoreApplication.Test; @@ -24,7 +23,7 @@ public async Task Test_That_Setup_Works_As_Designed() var response = await client.GetAsync("/talkToTransformerBee"); response.StatusCode.Should().Be(HttpStatusCode.OK); var content = await response.Content.ReadAsStringAsync(); - var bo4e = JsonSerializer.Deserialize(content, new JsonSerializerOptions() { Converters = { new JsonStringEnumConverter() } }); + var bo4e = JsonSerializer.Deserialize(content, new JsonSerializerOptions { Converters = { new JsonStringEnumConverter() } }); bo4e.Should().NotBeNull(); } } diff --git a/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs b/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs index bb9dfbd..aedc283 100644 --- a/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs +++ b/TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs @@ -23,3 +23,7 @@ return bo4e.Single().Transaktionen.Single(); }); app.Run(); + +public partial class Program +{ +} // required for integration testing; If you miss this the test will complain, that it cannot find a 'testhost.deps.json'