Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 7ba9b0d

Browse files
test: Created an end-to-end test with Playwright
1 parent 2cd2fee commit 7ba9b0d

File tree

13 files changed

+295
-0
lines changed

13 files changed

+295
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,6 @@ __queuestorage__
288288

289289
# Gitleaks report
290290
gitleaks-report.json
291+
292+
# Playwright
293+
test-results/

scripts/tests/e2e.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# Start the Service Layer in background
4+
cd src/ServiceLayer.API/
5+
func start &
6+
cd ../..
7+
8+
# Start the LocalEventgridEmulator in detached mode
9+
cd tests/LocalEventgridEmulator
10+
docker-compose up -d
11+
cd ../..
12+
13+
# Start the TestEventGridSubscriber in background
14+
cd tests/e2e/TestEventGridSubscriber
15+
func start &
16+
cd ..
17+
18+
# Optional: Wait a few seconds to let services start
19+
sleep 15
20+
21+
# Run the Playwright test
22+
npm test
23+
24+
echo "Killing all background jobs"
25+
kill $(jobs -p)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
services:
2+
azureventgridsimulator:
3+
image: acrukshubdevparman.azurecr.io/azureeventgridsimulator:latest
4+
container_name: azureeventgridsimulator-dev
5+
ports:
6+
# add a port mapping for each topic in the settings file
7+
- "60201:60201"
8+
volumes:
9+
# map a local folder './docker' to a read-only folder '/aegs' in the container
10+
# this allows us to access files (e.g. settings or certificates) from within the container
11+
- ./docker:/aegs:ro
12+
environment:
13+
- ASPNETCORE_ENVIRONMENT=Development
14+
# specify cert details note: can be generated like so:
15+
# dotnet dev-certs https --export-path ./docker/azureEventGridSimulator.pfx --password Y0urSup3rCrypt1cPa55w0rd! --trust
16+
- ASPNETCORE_Kestrel__Certificates__Default__Path=/aegs/azureEventGridSimulator.pfx
17+
- ASPNETCORE_Kestrel__Certificates__Default__Password=Y0urSup3rCrypt1cPa55w0rd!
18+
19+
# logging configuration
20+
- AEGS_Serilog__MinimumLevel__Default=Verbose
21+
22+
# you could also define topics/subscribers via via a configfile
23+
- AEGS_ConfigFile=/aegs/topics.config.json
24+
25+
#env_file:
26+
# you can also define environment variables via a file
27+
#- ./my.env
28+
29+
volumes:
30+
docker:
31+
cosmosdb-data:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"topics": [
3+
{
4+
"name": "test-topic",
5+
"type": "CloudEvent",
6+
"port": 60201,
7+
"key": "TheLocal+DevelopmentKey=",
8+
"subscribers": {
9+
"http": [
10+
{
11+
"name": "TestEventGridSubscriber",
12+
"endpoint": "http://host.docker.internal:7010/runtime/webhooks/EventGrid?functionName=EventHandler",
13+
"disableValidation": true
14+
}
15+
]
16+
}
17+
}
18+
]
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Azure.Identity;
2+
using Azure.Messaging.EventGrid;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Hosting;
5+
6+
var host = new HostBuilder()
7+
.ConfigureFunctionsWebApplication()
8+
.Build();
9+
10+
await host.RunAsync();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"profiles": {
3+
"TestEventGridSubscriber": {
4+
"commandName": "Project",
5+
"commandLineArgs": "--port 7010",
6+
"launchBrowser": false
7+
}
8+
}
9+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Azure.Messaging;
2+
using Azure.Messaging.EventGrid;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Azure.Functions.Worker;
5+
using Microsoft.Azure.Functions.Worker.Http;
6+
7+
namespace TestEventGridSubscriber;
8+
9+
public class TestEventGridSubscriber
10+
{
11+
public static List<CloudEvent> EventStore { get; } = [];
12+
13+
[Function("EventHandler")]
14+
public static void Run([EventGridTrigger] CloudEvent cloudEvent)
15+
{
16+
EventStore.Add(cloudEvent);
17+
}
18+
19+
[Function("ClearEventsStore")]
20+
public static IActionResult ClearEventsStore(
21+
[HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "events")] HttpRequestData req)
22+
{
23+
EventStore.Clear();
24+
return new NoContentResult();
25+
}
26+
27+
[Function("GetEvents")]
28+
public static IActionResult GetEvents(
29+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "events")] HttpRequestData req)
30+
{
31+
return new OkObjectResult(EventStore);
32+
}
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net9.0</TargetFramework>
4+
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
5+
<OutputType>Exe</OutputType>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
11+
<PackageReference Include="Azure.Identity" Version="1.13.2" />
12+
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
13+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.EventGrid" Version="3.5.0" />
14+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" />
15+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.1" />
16+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.2" />
17+
</ItemGroup>
18+
<ItemGroup>
19+
<None Update="host.json">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</None>
22+
<None Update="local.settings.json">
23+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24+
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
25+
</None>
26+
</ItemGroup>
27+
<ItemGroup>
28+
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
29+
</ItemGroup>
30+
</Project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "2.0"
3+
}

tests/e2e/package-lock.json

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)