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

Commit 562cff1

Browse files
test: Introduced environment variables and readme for integration tests
1 parent 8415f93 commit 562cff1

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

tests/ServiceLayer.IntegrationTests/IntegrationTests.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ public class DockerComposeCollection : ICollectionFixture<DockerComposeFixture>
1818
[Collection("DockerComposeCollection")]
1919
public class IntegrationTests
2020
{
21+
private readonly string _azuriteAccountKey = Environment.GetEnvironmentVariable("AZURITE_ACCOUNT_KEY")
22+
?? throw new InvalidOperationException($"Environment variable 'AZURITE_ACCOUNT_KEY' is not set.");
23+
private readonly string _azuriteAccountName = Environment.GetEnvironmentVariable("AZURITE_ACCOUNT_NAME")
24+
?? throw new InvalidOperationException($"Environment variable 'AZURITE_ACCOUNT_NAME' is not set.");
25+
private readonly string _azuriteBlobPort = Environment.GetEnvironmentVariable("AZURITE_BLOB_PORT")
26+
?? throw new InvalidOperationException($"Environment variable 'AZURITE_BLOB_PORT' is not set.");
27+
private readonly string _meshIngestPort = Environment.GetEnvironmentVariable("MESH_INGEST_PORT")
28+
?? throw new InvalidOperationException($"Environment variable 'MESH_INGEST_PORT' is not set.");
29+
private readonly string _meshSandboxPort = Environment.GetEnvironmentVariable("MESH_SANDBOX_PORT")
30+
?? throw new InvalidOperationException($"Environment variable 'MESH_SANDBOX_PORT' is not set.");
31+
private readonly string _blobContainerName = Environment.GetEnvironmentVariable("BLOB_CONTAINER_NAME")
32+
?? throw new InvalidOperationException($"Environment variable 'BLOB_CONTAINER_NAME' is not set.");
33+
private readonly string _databaseConnectionString = Environment.GetEnvironmentVariable("DATABASE_CONNECTION_STRING")
34+
?? throw new InvalidOperationException($"Environment variable 'DATABASE_CONNECTION_STRING' is not set.");
35+
2136
[Fact]
2237
public async Task FileSentToMeshInbox_FileIsUploadedToBlobContainerAndInsertedIntoDb()
2338
{
@@ -36,13 +51,13 @@ public async Task FileSentToMeshInbox_FileIsUploadedToBlobContainerAndInsertedIn
3651
Assert.True(await WasFileInsertedIntoDatabase(fileId));
3752
}
3853

39-
private static async Task WaitForHealthyService()
54+
private async Task WaitForHealthyService()
4055
{
4156
int attemptCounter = 0;
4257

4358
while (attemptCounter < 10)
4459
{
45-
var response = await HttpHelper.SendHttpRequestAsync(HttpMethod.Get, "http://localhost:7072/api/health");
60+
var response = await HttpHelper.SendHttpRequestAsync(HttpMethod.Get, $"http://localhost:{_meshIngestPort}/api/health");
4661

4762
if (response.IsSuccessStatusCode)
4863
{
@@ -59,15 +74,15 @@ private static async Task WaitForHealthyService()
5974
throw new TimeoutException("Timed out waiting on Mesh Ingest Service health check");
6075
}
6176

62-
private static async Task<string?> SendFileToMeshInbox(string fileName)
77+
private async Task<string?> SendFileToMeshInbox(string fileName)
6378
{
6479
byte[] binaryData = await File.ReadAllBytesAsync($"TestData/{fileName}");
6580
var content = new ByteArrayContent(binaryData);
6681
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
6782

6883
var response = await HttpHelper.SendHttpRequestAsync(
6984
HttpMethod.Post,
70-
"http://localhost:8700/messageexchange/X26ABC1/outbox",
85+
$"http://localhost:{_meshSandboxPort}/messageexchange/X26ABC1/outbox",
7186
content,
7287
headers =>
7388
{
@@ -86,11 +101,11 @@ private static async Task WaitForHealthyService()
86101
return responseObject?.MessageID;
87102
}
88103

89-
private static async Task<bool> WasFileUploadedToBlobContainer(string fileId)
104+
private async Task<bool> WasFileUploadedToBlobContainer(string fileId)
90105
{
91-
var blobConnectionString = "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1";
106+
var blobConnectionString = $"DefaultEndpointsProtocol=http;AccountName={_azuriteAccountName};AccountKey={_azuriteAccountKey};BlobEndpoint=http://localhost:{_azuriteBlobPort}/{_azuriteAccountName}";
92107

93-
var containerClient = new BlobContainerClient(blobConnectionString, "incoming-mesh-files");
108+
var containerClient = new BlobContainerClient(blobConnectionString, _blobContainerName);
94109

95110
try
96111
{
@@ -106,11 +121,10 @@ private static async Task<bool> WasFileUploadedToBlobContainer(string fileId)
106121
}
107122
}
108123

109-
private static async Task<bool> WasFileInsertedIntoDatabase(string fileId)
124+
private async Task<bool> WasFileInsertedIntoDatabase(string fileId)
110125
{
111-
var connectionString = "Server=localhost;Database=ServiceLayer;User Id=SA;Password=YourStrong@Passw0rd;TrustServerCertificate=True";
112126
var options = new DbContextOptionsBuilder<ServiceLayerDbContext>()
113-
.UseSqlServer(connectionString)
127+
.UseSqlServer(_databaseConnectionString)
114128
.Options;
115129

116130
var context = new ServiceLayerDbContext(options);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Provide the values for all environment variables when running the integration tests, e.g.
2+
3+
```sh
4+
dotnet test \
5+
-e AZURITE_ACCOUNT_KEY="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" \
6+
-e AZURITE_ACCOUNT_NAME=devstoreaccount1 \
7+
-e AZURITE_BLOB_PORT=10000 \
8+
-e MESH_INGEST_PORT=7072 \
9+
-e MESH_SANDBOX_PORT=8700 \
10+
-e BLOB_CONTAINER_NAME=incoming-mesh-files \
11+
-e DATABASE_CONNECTION_STRING="Server=localhost;Database=ServiceLayer;User Id=SA;Password=YourStrong@Passw0rd;TrustServerCertificate=True"
12+
```
13+
14+
Also, remember to set the FileDiscoveryTimerExpression to a shorter interval e.g. every 5 seconds (*/5 * * * * *)

0 commit comments

Comments
 (0)