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

Commit beec96e

Browse files
test: Included mesh sandbox in integration test setup
1 parent 4a7213e commit beec96e

File tree

2 files changed

+92
-24
lines changed

2 files changed

+92
-24
lines changed

compose.yaml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ services:
4848
FileExtractQueueName: "${FileExtractQueueName}"
4949
FileTransformQueueName: "${FileTransformQueueName}"
5050
StaleHours: "${StaleHours}"
51-
MeshApiBaseUrl: "http://mesh_sandbox:80/messageexchange"
51+
MeshApiBaseUrl: "http://mesh-sandbox/messageexchange"
5252
NbssMailboxId: "${NbssMailboxId}"
5353
MeshPassword: "${MeshPassword}"
5454
MeshSharedKey: "${MeshSharedKey}"
@@ -70,6 +70,8 @@ services:
7070
condition: service_healthy
7171
db:
7272
condition: service_healthy
73+
mesh-sandbox:
74+
condition: service_started
7375
networks:
7476
- backend
7577

@@ -103,10 +105,14 @@ services:
103105
ports:
104106
- "1433:1433"
105107
user: "root"
106-
volumes:
107-
- db-data:/var/opt/mssql
108+
# volumes:
109+
# - db-data:/var/opt/mssql
108110
healthcheck:
109-
test: ["CMD-SHELL", "pgrep -f sqlservr || exit 1"]
111+
test:
112+
[
113+
"CMD-SHELL",
114+
"grep -q 'SQL Server is now ready for client connections' /var/opt/mssql/log/errorlog || exit 1",
115+
]
110116
interval: 20s
111117
timeout: 10s
112118
retries: 6
@@ -131,6 +137,28 @@ services:
131137
networks:
132138
- backend
133139

140+
141+
mesh-sandbox:
142+
container_name: mesh-sandbox
143+
build: ../mesh-sandbox/
144+
ports:
145+
- "8700:80"
146+
deploy:
147+
restart_policy:
148+
condition: on-failure
149+
max_attempts: 3
150+
environment:
151+
- SHARED_KEY=TestKey
152+
- SSL=no
153+
volumes:
154+
# mount a different mailboxes.jsonl to pre created mailboxes
155+
- ../mesh-sandbox/src/mesh_sandbox/store/data/mailboxes.jsonl:/app/mesh_sandbox/store/data/mailboxes.jsonl:ro
156+
- ../mesh-sandbox/src/mesh_sandbox/test_plugin:/app/mesh_sandbox/plugins:ro
157+
# you can mount a directory if you want access the stored messages
158+
- ../mesh-sandbox/messages:/tmp/mesh_store
159+
networks:
160+
- backend
161+
134162
networks:
135163
backend:
136164
name: backend-network

tests/ServiceLayer.Mesh.Tests/IntegrationTests.cs

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
using System.Diagnostics;
22
using System.Net;
33
using System.Net.Http.Headers;
4+
using System.Text.Json;
5+
using System.Text.Json.Serialization;
6+
using Azure.Storage.Blobs;
7+
using Azure.Storage.Blobs.Models;
48

59
namespace ServiceLayer.Mesh.Tests;
610

@@ -12,16 +16,32 @@ public class DockerComposeCollection : ICollectionFixture<DockerComposeFixture>
1216
[Collection("DockerComposeCollection")]
1317
public class IntegrationTests
1418
{
19+
[Fact]
20+
public async Task EndToEndTest()
21+
{
22+
// Arrange
23+
await WaitForHealthyService();
24+
25+
// Act
26+
var fileId = await SendFileToMeshInbox("KMK_20250212095121_APPT_87.dat");
27+
28+
// Wait to allow functions to process file
29+
await Task.Delay(10000);
30+
31+
// Assert
32+
Assert.True(await WasFileUploadedToBlobContainer(fileId));
33+
}
34+
1535
private static async Task WaitForHealthyService()
1636
{
17-
bool environmentIsUp = false;
37+
bool isServiceHealthy = false;
1838

19-
while (environmentIsUp == false)
39+
while (isServiceHealthy == false)
2040
{
2141
var response = await HttpHelper.SendHttpRequestAsync(HttpMethod.Get, "http://localhost:7072/api/health");
2242
if (response.IsSuccessStatusCode)
2343
{
24-
environmentIsUp = true;
44+
isServiceHealthy = true;
2545
}
2646
else
2747
{
@@ -30,18 +50,7 @@ private static async Task WaitForHealthyService()
3050
}
3151
}
3252

33-
[Fact]
34-
public async Task EndToEndTest()
35-
{
36-
// Arrange
37-
await WaitForHealthyService();
38-
39-
await SendFileToMeshInbox("KMK_20250212095121_APPT_87.dat");
40-
41-
await Task.Delay(5000);
42-
}
43-
44-
private static async Task SendFileToMeshInbox(string fileName)
53+
private static async Task<string> SendFileToMeshInbox(string fileName)
4554
{
4655
byte[] binaryData = await File.ReadAllBytesAsync($"TestData/{fileName}");
4756
var content = new ByteArrayContent(binaryData);
@@ -60,12 +69,44 @@ private static async Task SendFileToMeshInbox(string fileName)
6069
headers.Add("Mex-Workflowid", "API-DOCS-TEST");
6170
}
6271
);
72+
73+
string responseBody = await response.Content.ReadAsStringAsync();
74+
75+
var responseObject = JsonSerializer.Deserialize<MeshResponse>(responseBody);
76+
77+
return responseObject.MessageID;
78+
}
79+
80+
private static async Task<bool> WasFileUploadedToBlobContainer(string fileId)
81+
{
82+
var blobConnectionString = "";
83+
84+
var containerClient = new BlobContainerClient(blobConnectionString, "incoming-mesh-files");
85+
86+
try
87+
{
88+
var blobClient = containerClient.GetBlobClient($"NbssAppointmentEvents/{fileId}");
89+
90+
BlobProperties properties = await blobClient.GetPropertiesAsync();
91+
return true; // If we get properties, the blob exists
92+
}
93+
catch (Exception ex)
94+
{
95+
Console.WriteLine($"An error occurred: {ex.Message}");
96+
return false;
97+
}
98+
}
99+
100+
public class MeshResponse
101+
{
102+
[JsonPropertyName("messageID")]
103+
public required string MessageID { get; set; }
63104
}
64105
}
65106

66107
public static class HttpHelper
67108
{
68-
private static readonly HttpClient _client = new HttpClient();
109+
private static readonly HttpClient _client = new();
69110

70111
public static async Task<HttpResponseMessage> SendHttpRequestAsync(
71112
HttpMethod method,
@@ -78,19 +119,18 @@ public static async Task<HttpResponseMessage> SendHttpRequestAsync(
78119
Content = content
79120
};
80121

81-
// Customize headers if provided
82122
configureHeaders?.Invoke(request.Headers);
83123

84124
try
85125
{
86126
var response = await _client.SendAsync(request);
87-
response.EnsureSuccessStatusCode(); // Throw if not a success status
127+
response.EnsureSuccessStatusCode();
88128
return response;
89129
}
90130
catch (HttpRequestException ex)
91131
{
92132
Console.WriteLine($"HTTP Request failed: {ex.Message}");
93-
return new HttpResponseMessage(HttpStatusCode.ServiceUnavailable);
133+
return new HttpResponseMessage(HttpStatusCode.InternalServerError);
94134
}
95135
}
96136
}
@@ -103,7 +143,7 @@ public async Task InitializeAsync()
103143
var startInfo = new ProcessStartInfo
104144
{
105145
FileName = "docker",
106-
Arguments = "compose up -d mesh-ingest azurite db db-migrations",
146+
Arguments = "compose up -d mesh-ingest mesh-sandbox azurite db db-migrations",
107147
RedirectStandardOutput = true,
108148
RedirectStandardError = true,
109149
UseShellExecute = false,

0 commit comments

Comments
 (0)