1- using Microsoft . Extensions . Logging ;
1+ using Microsoft . EntityFrameworkCore ;
2+ using Microsoft . Extensions . Logging ;
23using Moq ;
3- using ServiceLayer . Mesh . Functions ;
4- using ServiceLayer . Mesh . Models ;
5- using ServiceLayer . Mesh . Data ;
6- using Microsoft . EntityFrameworkCore ;
74using NHS . MESH . Client . Contracts . Services ;
85using NHS . MESH . Client . Models ;
9- using Azure . Storage . Queues ;
6+ using ServiceLayer . Mesh . Data ;
7+ using ServiceLayer . Mesh . Functions ;
8+ using ServiceLayer . Mesh . Messaging ;
9+ using ServiceLayer . Mesh . Models ;
10+
11+ namespace ServiceLayer . Mesh . Tests . Functions ;
1012
1113public class FileDiscoveryFunctionTests
1214{
13- private readonly Mock < ILogger < DiscoveryFunction > > _loggerMock ;
15+ private readonly Mock < ILogger < FileDiscoveryFunction > > _loggerMock ;
1416 private readonly Mock < IMeshInboxService > _meshInboxServiceMock ;
1517 private readonly ServiceLayerDbContext _dbContext ;
16- private readonly Mock < QueueClient > _queueClientMock ;
17- private readonly DiscoveryFunction _function ;
18+ private readonly Mock < IFileExtractQueueClient > _queueClientMock ;
19+ private readonly FileDiscoveryFunction _function ;
1820
1921 public FileDiscoveryFunctionTests ( )
2022 {
21- _loggerMock = new Mock < ILogger < DiscoveryFunction > > ( ) ;
23+ _loggerMock = new Mock < ILogger < FileDiscoveryFunction > > ( ) ;
2224 _meshInboxServiceMock = new Mock < IMeshInboxService > ( ) ;
23- _queueClientMock = new Mock < QueueClient > ( ) ;
25+ _queueClientMock = new Mock < IFileExtractQueueClient > ( ) ;
2426
2527 var options = new DbContextOptionsBuilder < ServiceLayerDbContext > ( )
2628 . UseInMemoryDatabase ( databaseName : Guid . NewGuid ( ) . ToString ( ) )
@@ -33,7 +35,7 @@ public FileDiscoveryFunctionTests()
3335 Environment . SetEnvironmentVariable ( "MailboxId" , "test-mailbox" ) ;
3436 Environment . SetEnvironmentVariable ( "QueueUrl" , "https://fakestorageaccount.queue.core.windows.net/testqueue" ) ;
3537
36- _function = new DiscoveryFunction (
38+ _function = new FileDiscoveryFunction (
3739 _loggerMock . Object ,
3840 _meshInboxServiceMock . Object ,
3941 _dbContext ,
@@ -62,7 +64,8 @@ public async Task Run_AddsNewMessageToDbAndQueue()
6264 Assert . Equal ( MeshFileStatus . Discovered , meshFile . Status ) ;
6365 Assert . Equal ( "test-mailbox" , meshFile . MailboxId ) ;
6466
65- _queueClientMock . Verify ( q => q . SendMessage ( It . IsAny < string > ( ) ) , Times . Once ) ;
67+ // TODO - replace the It.IsAny with a more specific matcher, or use a callback
68+ _queueClientMock . Verify ( q => q . EnqueueFileExtractAsync ( It . IsAny < MeshFile > ( ) ) , Times . Once ) ;
6669 }
6770
6871 [ Fact ]
@@ -94,7 +97,7 @@ public async Task Run_DoesNotAddDuplicateMessageOrQueueIt()
9497 var count = _dbContext . MeshFiles . Count ( f => f . FileId == duplicateMessageId ) ;
9598 Assert . Equal ( 1 , count ) ;
9699
97- _queueClientMock . Verify ( q => q . SendMessage ( It . IsAny < string > ( ) ) , Times . Never ) ;
100+ _queueClientMock . Verify ( q => q . EnqueueFileExtractAsync ( It . IsAny < MeshFile > ( ) ) , Times . Never ) ;
98101 }
99102
100103 [ Fact ]
@@ -104,15 +107,15 @@ public async Task Run_NoMessagesInInbox_DoesNothing()
104107 _meshInboxServiceMock . Setup ( s => s . GetMessagesAsync ( "test-mailbox" ) )
105108 . ReturnsAsync ( new MeshResponse < CheckInboxResponse >
106109 {
107- Response = new CheckInboxResponse { Messages = Array . Empty < string > ( ) }
110+ Response = new CheckInboxResponse { Messages = [ ] }
108111 } ) ;
109112
110113 // Act
111114 await _function . Run ( null ) ;
112115
113116 // Assert
114117 Assert . Empty ( _dbContext . MeshFiles ) ;
115- _queueClientMock . Verify ( q => q . SendMessage ( It . IsAny < string > ( ) ) , Times . Never ) ;
118+ _queueClientMock . Verify ( q => q . EnqueueFileExtractAsync ( It . IsAny < MeshFile > ( ) ) , Times . Never ) ;
116119 }
117120
118121 [ Fact ]
@@ -139,6 +142,7 @@ public async Task Run_MultipleMessagesInInbox_AllAreProcessed()
139142 Assert . Equal ( "test-mailbox" , meshFile . MailboxId ) ;
140143 }
141144
142- _queueClientMock . Verify ( q => q . SendMessage ( It . IsAny < string > ( ) ) , Times . Exactly ( messageIds . Length ) ) ;
145+ // TODO - replace the It.IsAny with more specific matcher, or use a callback to capture the arguments and check the file IDs
146+ _queueClientMock . Verify ( q => q . EnqueueFileExtractAsync ( It . IsAny < MeshFile > ( ) ) , Times . Exactly ( messageIds . Length ) ) ;
143147 }
144148}
0 commit comments