|
8 | 8 | using System.Net; |
9 | 9 | using System.Net.Http; |
10 | 10 | using System.Text; |
| 11 | +using System.Text.RegularExpressions; |
11 | 12 | using System.Threading; |
12 | 13 | using System.Threading.Tasks; |
13 | 14 | using Xunit; |
@@ -207,27 +208,28 @@ public async Task TryInvokeAsync_ThrowsInvocationExceptionIfHttpResponseHasAnUne |
207 | 208 |
|
208 | 209 | [Theory] |
209 | 210 | [MemberData(nameof(OnConnectionEstablishedMessageReceived_ExtractsEndPoint_Data))] |
210 | | - public void OnConnectionEstablishedMessageReceived_ExtractsEndPoint(string dummyIP, string dummyPort, string expectedResult) |
| 211 | + public void OnConnectionEstablishedMessageReceived_ExtractsEndPoint(string dummyHttpVersion, string dummyIP, string dummyPort, string expectedResult) |
211 | 212 | { |
212 | 213 | // Arrange |
213 | 214 | var loggerStringBuilder = new StringBuilder(); |
214 | | - string dummyConnectionEstablishedMessage = $"[Jering.Javascript.NodeJS: HttpVersion - HTTP/1.1 Listening on IP - {dummyIP} Port - {dummyPort}]"; |
| 215 | + string dummyConnectionEstablishedMessage = $"[Jering.Javascript.NodeJS: HttpVersion - {dummyHttpVersion} Listening on IP - {dummyIP} Port - {dummyPort}]"; |
215 | 216 | ExposedHttpNodeJSService testSubject = CreateHttpNodeJSService(loggerStringBuilder: loggerStringBuilder); |
216 | 217 |
|
217 | 218 | // Act |
218 | | - testSubject.ExposedOnConnectionEstablishedMessageReceived(dummyConnectionEstablishedMessage); |
| 219 | + testSubject.ExposedOnConnectionEstablishedMessageReceived(testSubject.ExposedConnectionEstablishedMessageRegex.Match(dummyConnectionEstablishedMessage)); |
219 | 220 |
|
220 | 221 | // Assert |
221 | 222 | Assert.Equal(expectedResult, testSubject._endpoint?.AbsoluteUri); |
222 | | - Assert.Contains(string.Format(Strings.LogInformation_HttpEndpoint, "HTTP/1.1", expectedResult), loggerStringBuilder.ToString()); |
| 223 | + Assert.Contains(string.Format(Strings.LogInformation_HttpEndpoint, dummyHttpVersion, expectedResult), loggerStringBuilder.ToString()); |
223 | 224 | } |
224 | 225 |
|
225 | 226 | public static IEnumerable<object[]> OnConnectionEstablishedMessageReceived_ExtractsEndPoint_Data() |
226 | 227 | { |
227 | 228 | return new object[][] |
228 | 229 | { |
229 | | - new object[]{"127.0.0.1", "12345", "http://127.0.0.1:12345/"}, // IPv4, arbitrary port |
230 | | - new object[]{"::1", "543", "http://[::1]:543/"} // IPv6, arbitrary port |
| 230 | + new object[]{ "HTTP/1.1", "127.0.0.1", "12345", "http://127.0.0.1:12345/"}, // Http 1.1, IPv4, arbitrary port |
| 231 | + new object[]{ "HTTP/1.1", "::1", "543", "http://[::1]:543/"}, // Http 1.1, IPv6, arbitrary port |
| 232 | + new object[]{ "HTTP/2.0", "127.0.0.1", "12345", "http://127.0.0.1:12345/"} // Http 2.0, IPv4, arbitrary port |
231 | 233 | }; |
232 | 234 | } |
233 | 235 |
|
@@ -326,14 +328,16 @@ public ExposedHttpNodeJSService(IOptions<OutOfProcessNodeJSServiceOptions> outOf |
326 | 328 | { |
327 | 329 | } |
328 | 330 |
|
| 331 | + public Regex ExposedConnectionEstablishedMessageRegex => ConnectionEstablishedMessageRegex; |
| 332 | + |
329 | 333 | public Task<(bool, T?)> ExposedTryInvokeAsync<T>(InvocationRequest invocationRequest, CancellationToken cancellationToken) |
330 | 334 | { |
331 | 335 | return TryInvokeAsync<T>(invocationRequest, cancellationToken); |
332 | 336 | } |
333 | 337 |
|
334 | | - public void ExposedOnConnectionEstablishedMessageReceived(string connectionEstablishedMessage) |
| 338 | + public void ExposedOnConnectionEstablishedMessageReceived(System.Text.RegularExpressions.Match connectionEstablishedMessageMatch) |
335 | 339 | { |
336 | | - OnConnectionEstablishedMessageReceived(connectionEstablishedMessage); |
| 340 | + OnConnectionEstablishedMessageReceived(connectionEstablishedMessageMatch); |
337 | 341 | } |
338 | 342 | } |
339 | 343 | } |
|
0 commit comments