11using System . Diagnostics ;
22using System . Net ;
33using System . Net . Http . Headers ;
4+ using System . Text . Json ;
5+ using System . Text . Json . Serialization ;
6+ using Azure . Storage . Blobs ;
7+ using Azure . Storage . Blobs . Models ;
48
59namespace ServiceLayer . Mesh . Tests ;
610
@@ -12,16 +16,32 @@ public class DockerComposeCollection : ICollectionFixture<DockerComposeFixture>
1216[ Collection ( "DockerComposeCollection" ) ]
1317public class IntegrationTests
1418{
19+ [ Fact ]
20+ public async Task EndToEndTest ( )
21+ {
22+ // Arrange
23+ await WaitForHealthyService ( ) ;
24+
25+ // Act
26+ var fileId = await SendFileToMeshInbox ( "KMK_20250212095121_APPT_87.dat" ) ;
27+
28+ // Wait to allow functions to process file
29+ await Task . Delay ( 10000 ) ;
30+
31+ // Assert
32+ Assert . True ( await WasFileUploadedToBlobContainer ( fileId ) ) ;
33+ }
34+
1535 private static async Task WaitForHealthyService ( )
1636 {
17- bool environmentIsUp = false ;
37+ bool isServiceHealthy = false ;
1838
19- while ( environmentIsUp == false )
39+ while ( isServiceHealthy == false )
2040 {
2141 var response = await HttpHelper . SendHttpRequestAsync ( HttpMethod . Get , "http://localhost:7072/api/health" ) ;
2242 if ( response . IsSuccessStatusCode )
2343 {
24- environmentIsUp = true ;
44+ isServiceHealthy = true ;
2545 }
2646 else
2747 {
@@ -30,18 +50,7 @@ private static async Task WaitForHealthyService()
3050 }
3151 }
3252
33- [ Fact ]
34- public async Task EndToEndTest ( )
35- {
36- // Arrange
37- await WaitForHealthyService ( ) ;
38-
39- await SendFileToMeshInbox ( "KMK_20250212095121_APPT_87.dat" ) ;
40-
41- await Task . Delay ( 5000 ) ;
42- }
43-
44- private static async Task SendFileToMeshInbox ( string fileName )
53+ private static async Task < string > SendFileToMeshInbox ( string fileName )
4554 {
4655 byte [ ] binaryData = await File . ReadAllBytesAsync ( $ "TestData/{ fileName } ") ;
4756 var content = new ByteArrayContent ( binaryData ) ;
@@ -60,12 +69,44 @@ private static async Task SendFileToMeshInbox(string fileName)
6069 headers . Add ( "Mex-Workflowid" , "API-DOCS-TEST" ) ;
6170 }
6271 ) ;
72+
73+ string responseBody = await response . Content . ReadAsStringAsync ( ) ;
74+
75+ var responseObject = JsonSerializer . Deserialize < MeshResponse > ( responseBody ) ;
76+
77+ return responseObject . MessageID ;
78+ }
79+
80+ private static async Task < bool > WasFileUploadedToBlobContainer ( string fileId )
81+ {
82+ var blobConnectionString = "" ;
83+
84+ var containerClient = new BlobContainerClient ( blobConnectionString , "incoming-mesh-files" ) ;
85+
86+ try
87+ {
88+ var blobClient = containerClient . GetBlobClient ( $ "NbssAppointmentEvents/{ fileId } ") ;
89+
90+ BlobProperties properties = await blobClient . GetPropertiesAsync ( ) ;
91+ return true ; // If we get properties, the blob exists
92+ }
93+ catch ( Exception ex )
94+ {
95+ Console . WriteLine ( $ "An error occurred: { ex . Message } ") ;
96+ return false ;
97+ }
98+ }
99+
100+ public class MeshResponse
101+ {
102+ [ JsonPropertyName ( "messageID" ) ]
103+ public required string MessageID { get ; set ; }
63104 }
64105}
65106
66107public static class HttpHelper
67108{
68- private static readonly HttpClient _client = new HttpClient ( ) ;
109+ private static readonly HttpClient _client = new ( ) ;
69110
70111 public static async Task < HttpResponseMessage > SendHttpRequestAsync (
71112 HttpMethod method ,
@@ -78,19 +119,18 @@ public static async Task<HttpResponseMessage> SendHttpRequestAsync(
78119 Content = content
79120 } ;
80121
81- // Customize headers if provided
82122 configureHeaders ? . Invoke ( request . Headers ) ;
83123
84124 try
85125 {
86126 var response = await _client . SendAsync ( request ) ;
87- response . EnsureSuccessStatusCode ( ) ; // Throw if not a success status
127+ response . EnsureSuccessStatusCode ( ) ;
88128 return response ;
89129 }
90130 catch ( HttpRequestException ex )
91131 {
92132 Console . WriteLine ( $ "HTTP Request failed: { ex . Message } ") ;
93- return new HttpResponseMessage ( HttpStatusCode . ServiceUnavailable ) ;
133+ return new HttpResponseMessage ( HttpStatusCode . InternalServerError ) ;
94134 }
95135 }
96136}
@@ -103,7 +143,7 @@ public async Task InitializeAsync()
103143 var startInfo = new ProcessStartInfo
104144 {
105145 FileName = "docker" ,
106- Arguments = "compose up -d mesh-ingest azurite db db-migrations" ,
146+ Arguments = "compose up -d mesh-ingest mesh-sandbox azurite db db-migrations" ,
107147 RedirectStandardOutput = true ,
108148 RedirectStandardError = true ,
109149 UseShellExecute = false ,
0 commit comments