@@ -108,4 +108,53 @@ public async Task Run_DoesNotAddDuplicateMessageOrQueueIt()
108108
109109 _queueClientMock . Verify ( q => q . SendMessage ( It . IsAny < string > ( ) ) , Times . Never ) ;
110110 }
111+
112+ [ Fact ]
113+ public async Task Run_NoMessagesInInbox_DoesNothing ( )
114+ {
115+ // Arrange
116+ _meshInboxServiceMock . Setup ( s => s . GetMessagesAsync ( "test-mailbox" ) )
117+ . ReturnsAsync ( new MeshResponse < CheckInboxResponse >
118+ {
119+ Response = new CheckInboxResponse { Messages = Array . Empty < string > ( ) }
120+ } ) ;
121+
122+ // Act
123+ await _function . Run ( null ) ;
124+
125+ // Assert
126+ Assert . Empty ( _dbContext . MeshFiles ) ;
127+ _queueClientMock . Verify ( q => q . SendMessage ( It . IsAny < string > ( ) ) , Times . Never ) ;
128+ }
129+
130+ [ Fact ]
131+ public async Task Run_MultipleMessagesInInbox_AllAreProcessed ( )
132+ {
133+ // Arrange
134+ var messageIds = new [ ] { "msg-1" , "msg-2" , "msg-3" } ;
135+
136+ _meshInboxServiceMock . Setup ( s => s . GetMessagesAsync ( "test-mailbox" ) )
137+ . ReturnsAsync ( new MeshResponse < CheckInboxResponse >
138+ {
139+ Response = new CheckInboxResponse { Messages = messageIds }
140+ } ) ;
141+
142+ _queueClientMock
143+ . Setup ( q => q . SendMessage ( It . IsAny < string > ( ) , null , null , It . IsAny < CancellationToken > ( ) ) )
144+ . Returns ( Response . FromValue < SendReceipt > ( null , Mock . Of < Response > ( ) ) ) ;
145+
146+ // Act
147+ await _function . Run ( null ) ;
148+
149+ // Assert
150+ foreach ( var id in messageIds )
151+ {
152+ var meshFile = _dbContext . MeshFiles . FirstOrDefault ( f => f . FileId == id ) ;
153+ Assert . NotNull ( meshFile ) ;
154+ Assert . Equal ( MeshFileStatus . Discovered , meshFile . Status ) ;
155+ Assert . Equal ( "test-mailbox" , meshFile . MailboxId ) ;
156+ }
157+
158+ _queueClientMock . Verify ( q => q . SendMessage ( It . IsAny < string > ( ) ) , Times . Exactly ( messageIds . Length ) ) ;
159+ }
111160}
0 commit comments