Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ COSMOS_CONNECTION_STRING=AccountEndpoint=https://localhost:8081/;AccountKey=<loc
COSMOS_DATABASE=personalsharp
COSMOS_CONTAINER=order-events
COSMOS_ALLOW_INSECURE_EMULATOR_CERT=false
POSTAL_LOGISTICS_USE_COSMOS=false
RUN_INTEGRATION_TESTS=false
83 changes: 83 additions & 0 deletions .github/workflows/postal-logistics-center.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Postal Logistics Center

on:
push:
paths:
- ".github/workflows/postal-logistics-center.yml"
- "PersonalSharp.PostalLogisticsCenter/**"
- "PersonalSharp.Tests/PostalLogisticsCenter/**"
- "PersonalSharp.IntegrationTests/Cosmos/PostalLogisticsCosmosIntegrationTests.cs"
- "PersonalSharp.Tests/PersonalSharp.Tests.csproj"
- "PersonalSharp.IntegrationTests/PersonalSharp.IntegrationTests.csproj"
- "PersonalSharp.slnx"
- "topics/examples/postal-logistics-center.md"
pull_request:
paths:
- ".github/workflows/postal-logistics-center.yml"
- "PersonalSharp.PostalLogisticsCenter/**"
- "PersonalSharp.Tests/PostalLogisticsCenter/**"
- "PersonalSharp.IntegrationTests/Cosmos/PostalLogisticsCosmosIntegrationTests.cs"
- "PersonalSharp.Tests/PersonalSharp.Tests.csproj"
- "PersonalSharp.IntegrationTests/PersonalSharp.IntegrationTests.csproj"
- "PersonalSharp.slnx"
- "topics/examples/postal-logistics-center.md"
workflow_dispatch:

env:
DOTNET_CLI_HOME: /tmp
HOME: /tmp
RUN_INTEGRATION_TESTS: "true"
COSMOS_CONNECTION_STRING: "AccountEndpoint=https://127.0.0.1:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEJYtj1b5F7MywVFBJGJEid8CjDzOjyRMKkjcu1iVGK4sR7+QYOlZjqfA==;"
COSMOS_DATABASE: personalsharp-postal-ci
COSMOS_CONTAINER: postal-logistics-events
COSMOS_ALLOW_INSECURE_EMULATOR_CERT: "true"

jobs:
postal-logistics-center:
runs-on: ubuntu-latest

services:
cosmos:
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview
env:
PROTOCOL: https
ENABLE_EXPLORER: "false"
ports:
- 8081:8081

steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.x

- name: Restore
run: dotnet restore PersonalSharp.slnx

- name: Build postal mini app
run: dotnet build PersonalSharp.PostalLogisticsCenter/PersonalSharp.PostalLogisticsCenter.csproj --no-restore /p:UseSharedCompilation=false /m:1

- name: Run postal mini app with in-memory store
run: dotnet run --project PersonalSharp.PostalLogisticsCenter --no-build --no-restore

- name: Postal mini app unit and smoke tests
run: dotnet test PersonalSharp.Tests/PersonalSharp.Tests.csproj --no-restore --filter FullyQualifiedName~PostalLogisticsCenter /p:UseSharedCompilation=false /m:1

- name: Wait for Cosmos emulator
run: |
for attempt in {1..90}; do
if curl -4 -k -fsS https://127.0.0.1:8081/ >/dev/null; then
exit 0
fi
sleep 2
done
exit 1

- name: Run postal mini app with Cosmos emulator
run: dotnet run --project PersonalSharp.PostalLogisticsCenter --no-build --no-restore -- --cosmos

- name: Postal mini app real Cosmos integration test
run: dotnet test PersonalSharp.IntegrationTests/PersonalSharp.IntegrationTests.csproj --no-restore --filter FullyQualifiedName~PostalLogisticsCosmosIntegrationTests /p:UseSharedCompilation=false /m:1
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ CodeCoverage/
project.lock.json
project.fragment.lock.json

# Node frontend
PersonalSharp.PostalLogisticsCenter.Ui/node_modules/
PersonalSharp.PostalLogisticsCenter.Ui/dist/

# Logs and diagnostics
*.log
*.binlog
Expand Down
8 changes: 2 additions & 6 deletions PersonalSharp.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ static void PrintSnippet(SnippetCase snippet)
Console.WriteLine();
Console.WriteLine($"Question: {snippet.Question}");
Console.WriteLine();
Console.WriteLine("Code:");
Console.WriteLine(snippet.Code);
Console.WriteLine();
Console.WriteLine($"Source: {snippet.Source}");
Console.WriteLine($"Expected: {snippet.ExpectedOutput}");
Console.WriteLine($"Actual: {snippet.Run()}");
Console.WriteLine();
Expand All @@ -109,9 +107,7 @@ static void PrintUnsafeSnippet(UnsafeSnippetCase snippet)
Console.WriteLine();
Console.WriteLine($"Question: {snippet.Question}");
Console.WriteLine();
Console.WriteLine("Code:");
Console.WriteLine(snippet.Code);
Console.WriteLine();
Console.WriteLine($"Source: {snippet.Source}");
Console.WriteLine($"Expected: {snippet.ExpectedOutput}");
Console.WriteLine($"Actual: {snippet.Run()}");
Console.WriteLine();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Net;
using System.Net.Http.Json;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
using PersonalSharp.PostalLogisticsCenter.Api;

namespace PersonalSharp.IntegrationTests.Cosmos;

[Collection(RealDatabaseCollection.Name)]
public sealed class PostalLogisticsApiIntegrationTests(CosmosFixture fixture)
{
[Fact]
public async Task PostRuns_ShouldReturnLiveCosmosDashboard()
{
if (!IntegrationTestGate.Enabled)
{
return;
}

await using var factory = new WebApplicationFactory<PostalLogisticsCenterApiMarker>()
.WithWebHostBuilder(builder =>
{
builder.ConfigureAppConfiguration((_, configuration) =>
{
configuration.AddInMemoryCollection(new Dictionary<string, string?>
{
["COSMOS_CONNECTION_STRING"] = IntegrationTestGate.RequiredEnvironment("COSMOS_CONNECTION_STRING"),
["COSMOS_DATABASE"] = fixture.DatabaseName,
["COSMOS_CONTAINER"] = fixture.ContainerName,
["COSMOS_ALLOW_INSECURE_EMULATOR_CERT"] = IntegrationTestGate.OptionalEnvironment("COSMOS_ALLOW_INSECURE_EMULATOR_CERT", "false")
});
});
});
var client = factory.CreateClient();

var response = await client.PostAsync("/api/postal/runs", content: null);
var dashboard = await response.Content.ReadFromJsonAsync<PostalRunDashboardResponse>();

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(dashboard);
Assert.Equal(2, dashboard.Parcels.Count);
Assert.Equal(7, dashboard.Kpis.CosmosEvents);
Assert.Equal(1, dashboard.Kpis.CustomsReleased);
Assert.Equal(1, dashboard.Kpis.CustomsHeld);

var held = Assert.Single(dashboard.Parcels, parcel => parcel.TrackingId == "US987654321US");
Assert.Equal(["VagueGoodsDescription", "MissingTariffCode", "MissingElectronicAdvanceData"], held.Decision.Reasons);
Assert.Contains(held.Events, item => item.Type == "CustomsHeld");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using PersonalSharp.PostalLogisticsCenter;

namespace PersonalSharp.IntegrationTests.Cosmos;

public sealed class PostalLogisticsCosmosIntegrationTests(CosmosFixture fixture) : IClassFixture<CosmosFixture>
{
[Fact]
public async Task CosmosParcelEventStore_ShouldAppendPostalLifecycleEvents()
{
if (!IntegrationTestGate.Enabled)
{
return;
}

var store = new CosmosParcelEventStore(fixture.Container);
var trackingId = IntegrationTestGate.UniqueId("postal-cn22");

await store.AppendAsync(trackingId, "Accepted", "station=acceptance", CancellationToken.None);
await store.AppendAsync(trackingId, "CustomsReleased", "cn22=release; document=Cn22; ead=ITMATT-DE-20260513-0001", CancellationToken.None);
var stream = await store.ReadAsync(trackingId, CancellationToken.None);

Assert.Equal(["Accepted", "CustomsReleased"], stream.Select(item => item.Type));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PersonalSharp.PostalLogisticsCenter.Api\PersonalSharp.PostalLogisticsCenter.Api.csproj" />
<ProjectReference Include="..\PersonalSharp.PostalLogisticsCenter\PersonalSharp.PostalLogisticsCenter.csproj" />
<ProjectReference Include="..\PersonalSharp.WebApiLab\PersonalSharp.WebApiLab.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Npgsql;
using PersonalSharp.WebApiLab;
using PersonalSharp.WebApiLab.Application;
using PersonalSharp.WebApiLab.Infrastructure.Cosmos;
using PersonalSharp.WebApiLab.Infrastructure.Postgres;
Expand All @@ -16,7 +17,7 @@ public sealed class RealDbOrderApiFactory(
string postgresConnectionString,
string sqlServerConnectionString,
ICosmosDocumentContainer cosmosDocumentContainer,
string orderIdPrefix) : WebApplicationFactory<Program>
string orderIdPrefix) : WebApplicationFactory<WebApiLabApiMarker>
{
public CapturingOrderIdGenerator IdGenerator { get; } = new(orderIdPrefix);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<ItemGroup>
<ProjectReference Include="..\PersonalSharp.PostalLogisticsCenter\PersonalSharp.PostalLogisticsCenter.csproj" />
</ItemGroup>

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

</Project>
Loading