public async Task WhenSendingMultipleSequentialMessageInNonStrictModeThenGetsAckForAll() { IMessageControlIdGenerator generator = DefaultMessageControlIdGenerator.Instance; await using var client = await MllpClient.Create( IPAddress.Loopback.ToString(), Port, strict : false).ConfigureAwait(false); var tasks = Enumerable.Repeat(false, 300) .Select( async _ => { var request = new QBP_Q11(); request.MSH.MessageControlID.Value = generator.NextId(); var response = // ReSharper disable once AccessToDisposedClosure await client.Send(request).ConfigureAwait(false); return(response.Message is ACK); }); var results = await Task.WhenAll(tasks).ConfigureAwait(false); Assert.All(results, Assert.True); }
public void MllpClient_Receives_Correct_Server_Certificate() { // arrange using (MllpServer server = this.StartupMllpServer(useSsl: true)) { byte[] receivedServerCertificateSerialNumber = null; var securityDetails = new ClientSecurityDetails( (sender, certificate, chain, sslPolicyErrors) => { receivedServerCertificateSerialNumber = certificate.GetSerialNumber(); return(true); }); var connectionDetails = new ClientConnectionDetails(server.EndPoint.Address.ToString(), server.EndPoint.Port, Encoding.ASCII, null, securityDetails); // act using (MllpClient testee = (MllpClient)MllpClient.Create(connectionDetails).Result) { // assert Assert.IsNotNull(receivedServerCertificateSerialNumber, "no server certificate was received by client."); CollectionAssert.AreEqual(this.serverCertificate.GetSerialNumber(), receivedServerCertificateSerialNumber, "wrong server certificate received."); } } }
public async Task WhenSendingMessageThenGetsAck() { IMessageControlIdGenerator generator = DefaultMessageControlIdGenerator.Instance; var client = await MllpClient.Create(IPAddress.Loopback.ToString(), Port); var request = new QBP_Q11(); request.MSH.MessageControlID.Value = generator.NextId(); var response = await client.Send(request).ConfigureAwait(false); Assert.NotNull(response); }
public async Task WhenSendingMessageThenGetsAck() { var client = await MllpClient.Create( IPAddress.Loopback.ToString(), _port, clientCertificates : _cert, userCertificateValidationCallback : UserCertificateValidationCallback); var request = new QBP_Q11(); request.MSH.MessageControlID.Value = "test"; var response = await client.Send(request).ConfigureAwait(false); Assert.NotNull(response); }
public async Task WhenSendingUpdateMessageThenIncludesObserver() { IMessageControlIdGenerator generator = DefaultMessageControlIdGenerator.Instance; var client = await MllpClient.Create(IPAddress.Loopback.ToString(), Port); var request = new SSU_U03(); request.MSH.MessageControlID.Value = generator.NextId(); var container = request.AddSPECIMEN_CONTAINER(); var obx = container.AddOBX(); var observer = obx.GetResponsibleObserver(0); observer.IDNumber.Value = "operatorId"; var response = await client.Send(request).ConfigureAwait(false); Assert.NotNull(response); }
public async Task WhenClientSendsMessageToServerThenReceivesResponse() { var address = IPAddress.IPv6Loopback.ToString(); await using var client = await MllpClient.Create( address, 2575) .ConfigureAwait(false); var adt = new ADT_A01(); adt.MSH.MessageControlID.Value = DefaultMessageControlIdGenerator.Instance.NextId(); var response = await client.Send(adt).ConfigureAwait(false); Assert.NotNull(response.Message); }
public void MllpClient_Sends_Client_Certificate_Successfully() { // arrange byte[] receivedClientCertificateSerialNumber = null; RemoteCertificateValidationCallback clientCertificateValidationCallbackOnServer = (sender, certificate, chain, errors) => { receivedClientCertificateSerialNumber = certificate.GetSerialNumber(); // the framework validation of the client cert on the server will result in errors. // accept the client cert anyhow. return(true); }; using (MllpServer server = this.StartupMllpServer(true, true, clientCertificateValidationCallbackOnServer)) { // accept any server certificate var serverCertificateValidator = new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => true); // client certification has issuer-issues. force sending the one we have. var clientCertificateCollection = new X509CertificateCollection { this.clientCertificate }; var clientCertificateSelector = new LocalCertificateSelectionCallback((sender, host, certificates, certificate, issuers) => certificates[0]); var securityDetails = new ClientSecurityDetails(serverCertificateValidator, clientCertificateCollection, clientCertificateSelector); var connectionDetails = new ClientConnectionDetails(server.EndPoint.Address.ToString(), server.EndPoint.Port, Encoding.ASCII, null, securityDetails); // act using (MllpClient testee = (MllpClient)MllpClient.Create(connectionDetails).Result) { } } // assert Assert.IsNotNull(receivedClientCertificateSerialNumber, "no client certificate was received by server."); CollectionAssert.AreEqual(this.clientCertificate.GetSerialNumber(), receivedClientCertificateSerialNumber, "wrong server certificate received."); }
public async Task WhenSendingMultipleParallelMessageThenGetsAckForAll() { IMessageControlIdGenerator generator = DefaultMessageControlIdGenerator.Instance; var tasks = Enumerable.Repeat(false, 5) .Select( async _ => { await using var client = await MllpClient.Create( IPAddress.Loopback.ToString(), Port).ConfigureAwait(false); var request = new QBP_Q11(); request.MSH.MessageControlID.Value = generator.NextId(); var response = await client.Send(request).ConfigureAwait(false); return(response?.Message is ACK); }); var results = await Task.WhenAll(tasks).ConfigureAwait(false); Assert.All(results, Assert.True); }
public void MllpClient_Receives_Server_Certificate_And_Certificate_Rejection_Is_Respected() { // arrange using (MllpServer server = this.StartupMllpServer(useSsl: true)) { var securityDetails = new ClientSecurityDetails((sender, certificate, chain, sslPolicyErrors) => false); // reject server certificate. var connectionDetails = new ClientConnectionDetails(server.EndPoint.Address.ToString(), server.EndPoint.Port, Encoding.ASCII, null, securityDetails); try { // act using (MllpClient testee = (MllpClient)MllpClient.Create(connectionDetails).Result) { // assert Assert.Fail("method should result in error since certificate was rejected."); } } catch (AggregateException aggregateException) { Assert.AreEqual(typeof(AuthenticationException), aggregateException.InnerException.GetType()); } } }
public void MllpServer_Receives_Message_OML_O33_And_Delegates_It_To_A_Message_Handler_Which_Returns_A_Valid_ORL_O34_Message() { // Arrange OML_O33 omlO33 = this.CreateValidOmlO33Message(); ORL_O34 orlO34 = this.CreateValidOrlO34Message(); CancellationTokenSource source = new CancellationTokenSource(); this.testee.Start(); // Act ClientConnectionDetails connectionDetails = new ClientConnectionDetails(IPAddress.Loopback.ToString(), 8013); var client = (MllpClient)MllpClient.Create(connectionDetails).Result; var task = client.Send(omlO33.ToString(), source.Token); task.Wait(5000, source.Token); string returnedValue = task.Result.Message; // Assert task.Status.Should().Be(TaskStatus.RanToCompletion); returnedValue.Should().NotBeNull("we must receive a ORL^O34^ORL_O34 message as response."); returnedValue.Should().Be(orlO34.ToString(), "this is the expected content of the response."); }
public void MllpHost_Receives_Message_QBP_WOS_Q11_And_Successfully_Replies_With_RSP_WOS_RSP_K11() { //Arrange using (MllpServer server = this.StartupMllpServer()) { var connectionDetails = new ClientConnectionDetails(server.EndPoint.Address.ToString(), server.EndPoint.Port); using (MllpClient testee = (MllpClient)MllpClient.Create(connectionDetails).Result) { StringBuilder messageToSendBuilder = new StringBuilder(); messageToSendBuilder.AppendLine($@"MSH|^~\&|cobas PRIME|LaboratoryName|Host||{DateTime.Now:yyyyMMddHHmmss}||QBP^WOS^QBP_Q11|{Guid.NewGuid()}|P|2.5.1||||||UNICODE UTF-8"); messageToSendBuilder.AppendLine(@"SFT|Roche Diagnostics|2.5.36|cobas PRIME|358742.3"); messageToSendBuilder.AppendLine(@"SFT|Roche Diagnostics Ltd.|1.1.12|cobas PRIME|554784.2.3"); messageToSendBuilder.AppendLine(@"QPD|WOS^Work Order Step^HL70487||$123546|Loaded^sample loaded^99ROC|12345|2A|5^Green^99ROC|200|660|210|100|400|NoSwab^No swab^99ROC|NoSpot^No spot detected^99ROC"); messageToSendBuilder.AppendLine(@"RCP|I||R"); messageToSendBuilder.AppendLine(@"DSC|156|I"); StringBuilder messageToReturnBuilder = new StringBuilder(); messageToReturnBuilder.AppendLine($@"MSH|^~\&|Host|LaboratoryName|cobas PRIME|LaboratoryName|{DateTime.Now:yyyyMMddHHmmss}||RSP^WOS^RSP_K11|{Guid.NewGuid()}|P|2.5.1||||||UNICODE UTF-8"); messageToReturnBuilder.AppendLine(@"MSA|AA|123456789"); messageToReturnBuilder.AppendLine(@"QAK|12|OK|WOS^Work Order Step^IHE_LABTF"); messageToReturnBuilder.AppendLine(@"QPD|WOS^Work Order Step^IHE_LABTF"); messageToReturnBuilder.AppendLine(@"SPM||$S123456||SER^Serum^HL70487"); messageToReturnBuilder.AppendLine(@"OBX|1|CE|TestCode^TestName^LN||74856-6^MPX^LN||||||F"); messageToReturnBuilder.AppendLine(@"OBX|2|CE|TestCode^TestName^LN||74857-4^WNV^LN||||||F"); messageToReturnBuilder.AppendLine(@"SAC|||$S123456"); messageToReturnBuilder.AppendLine(@"ORC|NW|1"); //Act var result = testee.Send(messageToSendBuilder.ToString()).GetAwaiter().GetResult(); //Assert result.Should().NotBeNull("a message must be returned from the server."); result.Should().Be(messageToReturnBuilder.ToString(), "the receive message must have the expected content"); } } }