Skip to content

Commit

Permalink
est
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-kklein committed Feb 2, 2024
1 parent 5642b8b commit f3f9633
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/integrationtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions TransformerBeeClient/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ TransformerBeeClient.UnitTest/obj
TransformerBeeClient.UnitTest/bin
ExampleAspNetCoreApplication/obj
ExampleAspNetCoreApplication/bin
ExampleAspNetCoreApplication.Test/obj
ExampleAspNetCoreApplication.Test/bin
Original file line number Diff line number Diff line change
@@ -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<WebApplicationFactory<Program>>
{
protected readonly WebApplicationFactory<Program> Factory;

public ApplicationTest(WebApplicationFactory<Program> 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<BOneyComb>(content, new JsonSerializerOptions() { Converters = { new JsonStringEnumConverter() } });
bo4e.Should().NotBeNull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ExampleAspNetCoreApplication\ExampleAspNetCoreApplication.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"shadowCopy": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TransformerBeeClient\TransformerBeeClient.csproj" />
<ProjectReference Include="..\TransformerBeeClient\TransformerBeeClient.csproj"/>
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Check warning on line 23 in TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 7.0.100)

Possible null reference argument for parameter 'source' in 'BOneyComb Enumerable.Single<BOneyComb>(IEnumerable<BOneyComb> source)'.

Check warning on line 23 in TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 6.0.201)

Possible null reference argument for parameter 'source' in 'BOneyComb Enumerable.Single<BOneyComb>(IEnumerable<BOneyComb> source)'.

Check warning on line 23 in TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.0.100)

Possible null reference argument for parameter 'source' in 'BOneyComb Enumerable.Single<BOneyComb>(IEnumerable<BOneyComb> source)'.

Check warning on line 23 in TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 6.0.201)

Possible null reference argument for parameter 'source' in 'BOneyComb Enumerable.Single<BOneyComb>(IEnumerable<BOneyComb> source)'.
});
app.Run();
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using EDILibrary;
using Xunit;

namespace TransformerBeeClient.IntegrationTest;

/// <summary>
/// A minimal working example on how to use this library without ASP.NET
/// </summary>
public class MweWithoutAspNetTest
{
/// <summary>
/// in asp.net applications, there's a service collection that is used to create the http client factory for you
/// </summary>
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);
}
}
6 changes: 6 additions & 0 deletions TransformerBeeClient/TransformerBeeClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit f3f9633

Please sign in to comment.