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

Commit f4e9ccb

Browse files
committed
extract function configuration
1 parent c609736 commit f4e9ccb

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/ServiceLayer.Mesh/Functions/FileExtractFunction.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.EntityFrameworkCore;
33
using Microsoft.Extensions.Logging;
44
using NHS.MESH.Client.Contracts.Services;
5+
using ServiceLayer.Mesh.Configuration;
56
using ServiceLayer.Mesh.Data;
67
using ServiceLayer.Mesh.Messaging;
78
using ServiceLayer.Mesh.Models;
@@ -10,7 +11,8 @@
1011
namespace ServiceLayer.Mesh.Functions;
1112

1213
public class FileExtractFunction(
13-
ILogger logger,
14+
ILogger<FileExtractFunction> logger,
15+
IFileExtractFunctionConfiguration configuration,
1416
IMeshInboxService meshInboxService,
1517
ServiceLayerDbContext serviceLayerDbContext,
1618
IFileTransformQueueClient fileTransformQueueClient,
@@ -53,10 +55,7 @@ public async Task Run([QueueTrigger("file-extract")] FileExtractQueueMessage mes
5355

5456
try
5557
{
56-
var mailboxId = Environment.GetEnvironmentVariable("NBSSMailBoxId")
57-
?? throw new InvalidOperationException($"Environment variable 'NBSSMailBoxId' is not set or is empty.");
58-
59-
var meshResponse = await meshInboxService.GetMessageByIdAsync(mailboxId, file.FileId);
58+
var meshResponse = await meshInboxService.GetMessageByIdAsync(configuration.NbssMeshMailboxId, file.FileId);
6059
if (!meshResponse.IsSuccessful)
6160
{
6261
// TODO - what to do if unsuccessful?
@@ -65,7 +64,7 @@ public async Task Run([QueueTrigger("file-extract")] FileExtractQueueMessage mes
6564

6665
var blobPath = await meshFileBlobStore.UploadAsync(file, meshResponse.Response.FileAttachment.Content);
6766

68-
var meshAcknowledgementResponse = await meshInboxService.AcknowledgeMessageByIdAsync(mailboxId, message.FileId);
67+
var meshAcknowledgementResponse = await meshInboxService.AcknowledgeMessageByIdAsync(configuration.NbssMeshMailboxId, message.FileId);
6968
if (!meshResponse.IsSuccessful)
7069
{
7170
// TODO - what to do if unsuccessful?

tests/ServiceLayer.Mesh.Tests/Functions/FileExtractFunctionTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Moq;
44
using NHS.MESH.Client.Contracts.Services;
55
using NHS.MESH.Client.Models;
6+
using ServiceLayer.Mesh.Configuration;
67
using ServiceLayer.Mesh.Data;
78
using ServiceLayer.Mesh.Functions;
89
using ServiceLayer.Mesh.Messaging;
@@ -17,6 +18,7 @@ public class FileExtractFunctionTests
1718
private readonly Mock<IMeshInboxService> _meshInboxServiceMock;
1819
private readonly Mock<IFileTransformQueueClient> _fileTransformQueueClientMock;
1920
private readonly Mock<IFileExtractQueueClient> _fileExtractQueueClientMock;
21+
private readonly Mock<IFileExtractFunctionConfiguration> _configurationMock;
2022
private readonly Mock<IMeshFilesBlobStore> _blobStoreMock;
2123
private readonly ServiceLayerDbContext _dbContext;
2224
private readonly FileExtractFunction _function;
@@ -37,10 +39,12 @@ public FileExtractFunctionTests()
3739

3840
_dbContext = new ServiceLayerDbContext(options);
3941

40-
Environment.SetEnvironmentVariable("NBSSMailBoxId", "test-mailbox");
42+
var functionConfiguration = new Mock<IFileExtractFunctionConfiguration>();
43+
functionConfiguration.Setup(c => c.NbssMeshMailboxId).Returns("test-mailbox");
4144

4245
_function = new FileExtractFunction(
4346
_loggerMock.Object,
47+
functionConfiguration.Object,
4448
_meshInboxServiceMock.Object,
4549
_dbContext,
4650
_fileTransformQueueClientMock.Object,

0 commit comments

Comments
 (0)