Skip to content

Commit 4f6e89f

Browse files
authored
docs: Add Example Application (#12)
1 parent 3c1fdba commit 4f6e89f

File tree

17 files changed

+241
-21
lines changed

17 files changed

+241
-21
lines changed

.github/workflows/integrationtests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,8 @@ jobs:
5555
CLIENT_SECRET: ${{ secrets.AUTH0_TEST_CLIENT_SECRET }}
5656
run: |
5757
dotnet test --filter TestCollectionName='authenticated'
58+
- name: Run Integration Tests for Example Application
59+
working-directory: TransformerBeeClient/ExampleAspNetCoreApplication.Test
60+
run: |
61+
dotnet build --no-restore
62+
dotnet test

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,47 @@ Ask info@hochfrequenz.de or ping @JoschaMetze on GitHub to get one.
1515
You can check if your account is working by logging [into our stage environment](https://transformerstage.utilibee.io/app/).
1616

1717
### Using the client
18-
![Nuget Package](https://badgen.net/nuget/v/TransformerBeeClient)
19-
Install it from nuget [TransformerBeeClient](https://www.nuget.org/packages/TransformerBeeClient):
18+
19+
Install it from nuget [TransformerBeeClient](https://www.nuget.org/packages/TransformerBeeClient) ![Nuget Package](https://badgen.net/nuget/v/TransformerBeeClient):
2020

2121
```bash
2222
dotnet add package TransformerBeeClient
2323
```
2424

2525
### Authentication
26+
2627
You need to provide something that implements `ITransformerBeeAuthenticator` to the `TransformerBeeClient`.
2728

2829
#### No Authentication
29-
If you're hosting transformer.bee in the same network and there is no authentication, you can use the `NoAuthenticator`.
30+
31+
If you're hosting transformer.bee in the same network or your localhost and there is no authentication, you can use the `NoAuthenticator`.
32+
3033
```csharp
3134
using TransformerBeeClient;
3235
var myAuthenticator = new NoAuthenticationProvider();
3336
```
3437

3538
#### OAuth2 Client and Secret
36-
If, which is more likely, Hochfrequenz provided you with a client ID and secret, you can use the `ClientIdClientSecretAuthenticator` class like this:
39+
If, which is more likely, Hochfrequenz provided you with a client Id and secret, you can use the `ClientIdClientSecretAuthenticator` class like this:
40+
3741
```csharp
3842
using TransformerBeeClient;
3943
var myAuthenticator = new ClientIdClientSecretAuthenticationProvider("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
4044
```
4145

42-
...todo
43-
```csharp
46+
### Use with ASP.NET Core
47+
This library is thought to be primarily used in ASP.NET Core applications.
48+
That's why it assumes that you have an `IHttpClientFactory` available in your dependency injection container.
49+
See the [`ExampleAspNetCoreApplication/Program.cs`](TransformerBeeClient/ExampleAspNetCoreApplication/Program.cs) for a minimal working example.
4450

45-
```
51+
### Use without ASP.NET Core
52+
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.
53+
See the [`MweWithoutAspNetTest.cs`](TransformerBeeClient/TransformerBeeClient.IntegrationTest/MweWithoutAspNetTest.cs) for a minimal working example.
4654

4755
## Development
4856

4957
### Integration Tests
58+
5059
To run the integration test login to your docker to access the transformer.bee image.
5160

5261
```bash
@@ -56,6 +65,7 @@ docker login ghcr.io -u YOUR_GITHUB_USERNAME
5665
then paste your PAT similarly to described in the [integration test CI pipeline](.github/workflows/integrationtests.yml)
5766

5867
### Release (CI/CD)
68+
5969
To release a new version of this library, [create a new release](https://github.com/Hochfrequenz/transformer.bee_client.net/releases/new) in GitHub.
6070
Make sure its tag starts with `v` and the version number, e.g. `v1.2.3`.
6171
Tags without a release wont trigger the release workflow; This enforces that you have to write a changelog before releasing.

TransformerBeeClient/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ TransformerBeeClient.IntegrationTest/obj
44
TransformerBeeClient.IntegrationTest/bin
55
TransformerBeeClient.UnitTest/obj
66
TransformerBeeClient.UnitTest/bin
7+
ExampleAspNetCoreApplication/obj
8+
ExampleAspNetCoreApplication/bin
9+
ExampleAspNetCoreApplication.Test/obj
10+
ExampleAspNetCoreApplication.Test/bin
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Net;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
using FluentAssertions;
5+
using Microsoft.AspNetCore.Mvc.Testing;
6+
using TransformerBeeClient.Model;
7+
8+
namespace ExampleAspNetCoreApplication.Test;
9+
10+
public class ApplicationTest : IClassFixture<WebApplicationFactory<Program>>
11+
{
12+
protected readonly WebApplicationFactory<Program> Factory;
13+
14+
public ApplicationTest(WebApplicationFactory<Program> factory)
15+
{
16+
Factory = factory;
17+
}
18+
19+
[Fact]
20+
public async Task Test_That_Setup_Works_As_Designed()
21+
{
22+
var client = Factory.CreateDefaultClient();
23+
var response = await client.GetAsync("/talkToTransformerBee");
24+
response.StatusCode.Should().Be(HttpStatusCode.OK);
25+
var content = await response.Content.ReadAsStringAsync();
26+
var bo4e = JsonSerializer.Deserialize<BOneyComb>(content, new JsonSerializerOptions { Converters = { new JsonStringEnumConverter() } });
27+
bo4e.Should().NotBeNull();
28+
}
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
14+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.1" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
16+
<PackageReference Include="xunit" Version="2.4.2"/>
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
<PrivateAssets>all</PrivateAssets>
20+
</PackageReference>
21+
<PackageReference Include="coverlet.collector" Version="6.0.0">
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
<PrivateAssets>all</PrivateAssets>
24+
</PackageReference>
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<ProjectReference Include="..\ExampleAspNetCoreApplication\ExampleAspNetCoreApplication.csproj" />
29+
</ItemGroup>
30+
31+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using Xunit;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"shadowCopy": false
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<PreserveCompilationContext>true</PreserveCompilationContext>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<ProjectReference Include="..\TransformerBeeClient\TransformerBeeClient.csproj"/>
11+
</ItemGroup>
12+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using EDILibrary;
2+
using TransformerBeeClient;
3+
4+
var builder = WebApplication.CreateBuilder(args);
5+
builder.Services.AddHttpClient();
6+
7+
builder.Services.AddTransient<ITransformerBeeAuthenticator, NoAuthenticator>(); // Or you could use ClientIdClientSecretAuthenticator
8+
builder.Services.AddHttpClient("TransformerBee", client =>
9+
{
10+
client.BaseAddress = new Uri("http://localhost:5021/"); // or https://transformerstage.utilibee.io
11+
});
12+
builder.Services.AddTransient<ICanConvertToBo4e, TransformerBeeRestClient>();
13+
builder.Services.AddTransient<ICanConvertToEdifact, TransformerBeeRestClient>();
14+
15+
var app = builder.Build();
16+
17+
app.MapGet("/", () => "I ❤ BO4E");
18+
app.MapGet("/talkToTransformerBee", async (ICanConvertToBo4e transformerBeeRestClient) =>
19+
{
20+
var bo4e = await transformerBeeRestClient.ConvertToBo4e(
21+
"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'",
22+
EdifactFormatVersion.FV2310);
23+
return bo4e.Single().Transaktionen.Single();
24+
});
25+
app.Run();
26+
27+
public partial class Program
28+
{
29+
} // required for integration testing; If you miss this the test will complain, that it cannot find a 'testhost.deps.json'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:26369",
8+
"sslPort": 44341
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"applicationUrl": "http://localhost:5137",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"dotnetRunMessages": true,
24+
"launchBrowser": true,
25+
"applicationUrl": "https://localhost:7030;http://localhost:5137",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
},
30+
"IIS Express": {
31+
"commandName": "IISExpress",
32+
"launchBrowser": true,
33+
"environmentVariables": {
34+
"ASPNETCORE_ENVIRONMENT": "Development"
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)