55using System . Text . Json . Serialization ;
66using Azure . Storage . Blobs ;
77using Azure . Storage . Blobs . Models ;
8+ using Microsoft . EntityFrameworkCore ;
9+ using ServiceLayer . Data ;
810
911namespace ServiceLayer . Mesh . Tests ;
1012
@@ -17,19 +19,21 @@ public class DockerComposeCollection : ICollectionFixture<DockerComposeFixture>
1719public class IntegrationTests
1820{
1921 [ Fact ]
20- public async Task EndToEndTest ( )
22+ public async Task FileUploadedToMesh_FileIsUploadedToBlobContainerAndInsertedIntoDb ( )
2123 {
2224 // Arrange
2325 await WaitForHealthyService ( ) ;
2426
2527 // Act
2628 var fileId = await SendFileToMeshInbox ( "KMK_20250212095121_APPT_87.dat" ) ;
2729
28- // Wait to allow functions to process file
29- await Task . Delay ( 10000 ) ;
30+ // Wait to allow functions to ingest the file. The CRON timer trigger for the FileDiscovery function must be considered.
31+ await Task . Delay ( 45000 ) ;
3032
3133 // Assert
34+ Assert . NotNull ( fileId ) ;
3235 Assert . True ( await WasFileUploadedToBlobContainer ( fileId ) ) ;
36+ Assert . True ( await WasFileInsertedIntoDatabase ( fileId ) ) ;
3337 }
3438
3539 private static async Task WaitForHealthyService ( )
@@ -45,12 +49,14 @@ private static async Task WaitForHealthyService()
4549 }
4650 else
4751 {
48- await Task . Delay ( 1000 ) ;
52+ await Task . Delay ( 5000 ) ;
4953 }
5054 }
55+
56+ Console . WriteLine ( "Mesh Ingest Service is healthy and ready to start ingesting files" ) ;
5157 }
5258
53- private static async Task < string > SendFileToMeshInbox ( string fileName )
59+ private static async Task < string ? > SendFileToMeshInbox ( string fileName )
5460 {
5561 byte [ ] binaryData = await File . ReadAllBytesAsync ( $ "TestData/{ fileName } ") ;
5662 var content = new ByteArrayContent ( binaryData ) ;
@@ -74,7 +80,7 @@ private static async Task<string> SendFileToMeshInbox(string fileName)
7480
7581 var responseObject = JsonSerializer . Deserialize < MeshResponse > ( responseBody ) ;
7682
77- return responseObject . MessageID ;
83+ return responseObject ? . MessageID ;
7884 }
7985
8086 private static async Task < bool > WasFileUploadedToBlobContainer ( string fileId )
@@ -97,6 +103,18 @@ private static async Task<bool> WasFileUploadedToBlobContainer(string fileId)
97103 }
98104 }
99105
106+ private static async Task < bool > WasFileInsertedIntoDatabase ( string fileId )
107+ {
108+ var connectionString = "" ;
109+ var options = new DbContextOptionsBuilder < ServiceLayerDbContext > ( )
110+ . UseSqlServer ( connectionString )
111+ . Options ;
112+
113+ var context = new ServiceLayerDbContext ( options ) ;
114+
115+ return await context . MeshFiles . AnyAsync ( x => x . FileId == fileId ) ;
116+ }
117+
100118 public class MeshResponse
101119 {
102120 [ JsonPropertyName ( "messageID" ) ]
@@ -151,11 +169,17 @@ public async Task InitializeAsync()
151169 } ;
152170
153171 using var process = Process . Start ( startInfo ) ;
172+
173+ if ( process == null )
174+ {
175+ throw new Exception ( "Failed to start the Docker process." ) ;
176+ }
177+
154178 await process . WaitForExitAsync ( ) ;
155179
156180 if ( process . ExitCode != 0 )
157181 {
158- throw new Exception ( $ "docker compose up failed, error: { process . StandardError . ReadToEnd ( ) } ") ;
182+ throw new Exception ( $ "Docker process started but failed, error: { process . StandardError . ReadToEnd ( ) } ") ;
159183 }
160184 }
161185
@@ -173,6 +197,17 @@ public async Task DisposeAsync()
173197 } ;
174198
175199 using var process = Process . Start ( stopInfo ) ;
200+
201+ if ( process == null )
202+ {
203+ throw new Exception ( "Failed to start the Docker process." ) ;
204+ }
205+
176206 await process . WaitForExitAsync ( ) ;
207+
208+ if ( process . ExitCode != 0 )
209+ {
210+ throw new Exception ( $ "Docker process started but failed, error: { process . StandardError . ReadToEnd ( ) } ") ;
211+ }
177212 }
178213}
0 commit comments