public async Task Old_IsSendRequired_AddedRequestNotConnected_ReturnsTrue() { var port = Ports.GetNext(); using (CreateServer <DicomCEchoProvider>(port)) { var client = CreateOldClient(); client.AddRequest(new DicomCEchoRequest()); Assert.True(client.IsSendRequired); client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); await Task.Delay(100).ConfigureAwait(false); client.AddRequest(new DicomCEchoRequest()); Assert.True(client.IsSendRequired); } }
public void Constructor_EstablishTwoWithSamePort_ShouldYieldAccessibleException() { var port = Ports.GetNext(); var server1 = DicomServer.Create <DicomCEchoProvider>(port); while (!server1.IsListening) { Thread.Sleep(10); } var exception = Record.Exception(() => DicomServer.Create <DicomCEchoProvider>(port)); Assert.IsType <DicomNetworkException>(exception); Assert.True(server1.IsListening); Assert.Null(server1.Exception); }
public async Task ReleaseAsync_AfterAssociation_SendIsCompleted() { int port = Ports.GetNext(); using (DicomServer.Create <MockCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest()); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.WaitForAssociation(); await client.ReleaseAsync(); Thread.Sleep(10); Assert.True(task.IsCompleted); } }
public async Task Old_WaitForAssociationAsync_TooShortTimeout_ReturnsFalse() { var port = Ports.GetNext(); using (CreateServer <MockCEchoProvider>(port)) { var client = CreateOldClient(); client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (rq, rsp) => Thread.Sleep(100) }); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); var actual = await client.WaitForAssociationAsync(1); task.Wait(1000); Assert.False(actual); } }
public async Task Old_Release_AfterAssociation_SendIsCompleted() { int port = Ports.GetNext(); using (CreateServer <MockCEchoProvider>(port)) { var client = CreateOldClient(); client.AddRequest(new DicomCEchoRequest()); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); client.WaitForAssociation(); client.Release(); await Task.Delay(1000).ConfigureAwait(false); Assert.True(task.IsCompleted); } }
public void Old_AssociationRejected_AssociationNotAllowed_IsInvoked() { var port = Ports.GetNext(); using (CreateServer <MockCEchoProvider>(port)) { var client = CreateOldClient(); var reason = DicomRejectReason.NoReasonGiven; client.AssociationRejected += (sender, args) => reason = args.Reason; client.AddRequest(new DicomCEchoRequest()); var exception = Record.Exception(() => client.Send("127.0.0.1", port, false, "SCU", "NOTACCEPTEDSCP")); Assert.Equal(DicomRejectReason.CalledAENotRecognized, reason); Assert.NotNull(exception); } }
public async Task Old_SendAsync_MultipleTimes_AllRecognized(int expected) { var port = Ports.GetNext(); var flag = new ManualResetEventSlim(); var logger = _logger.IncludePrefix("UnitTest"); using (var server = CreateServer <DicomCEchoProvider>(port)) { while (!server.IsListening) { await Task.Delay(50); } var actual = 0; var client = CreateOldClient(); for (var i = 0; i < expected; i++) { client.AddRequest( new DicomCEchoRequest { OnResponseReceived = (req, res) => { Interlocked.Increment(ref actual); logger.Info($"Actual = {actual}"); if (actual == expected) { flag.Set(); } } }); if (client.IsSendRequired) { await client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP").ConfigureAwait(false); } } logger.Info("Waiting for flag to be set"); flag.Wait(10000); logger.Info("Test done"); Assert.Equal(expected, actual); } }
public void BeginSend_SingleRequest_Recognized() { int port = Ports.GetNext(); using (new DicomServer <DicomCEchoProvider>(port)) { var counter = 0; var request = new DicomCEchoRequest { OnResponseReceived = (req, res) => ++ counter }; var client = new DicomClient(); client.AddRequest(request); client.EndSend(client.BeginSend("127.0.0.1", port, false, "SCU", "ANY-SCP", null, null)); Assert.Equal(1, counter); } }
public void Old_Send_MultipleTimes_AllRecognized(int expected) { var port = Ports.GetNext(); var flag = new ManualResetEventSlim(); var logger = _logger.IncludePrefix("UnitTest"); using (var server = CreateServer <DicomCEchoProvider>(port)) { while (!server.IsListening) { Thread.Sleep(50); } var actual = 0; var client = CreateOldClient(); for (var i = 0; i < expected; ++i) { var localIndex = i; client.AddRequest( new DicomCEchoRequest { OnResponseReceived = (req, res) => { logger.Info($"i = {localIndex}, received response for [{req.MessageID}]"); Interlocked.Increment(ref actual); if (actual == expected) { flag.Set(); } } }); if (client.IsSendRequired) { client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); } } flag.Wait(TimeSpan.FromSeconds(10)); Assert.Equal(expected, actual); } }
public void Create_TwiceOnSamePortWithDisposalInBetween_DoesNotThrow() { var port = Ports.GetNext(); using (DicomServer.Create <DicomCEchoProvider>(port)) { } var e = Record.Exception( () => { using (DicomServer.Create <DicomCEchoProvider>(port)) { Assert.NotNull(DicomServer.GetInstance(port)); } }); Assert.Null(e); }
public void Send_Ipv6AnyListenerKnownSOPClass_SendSucceeds() { var port = Ports.GetNext(); using (DicomServer.Create <SimpleCStoreProvider>(NetworkManager.IPv6Any, port)) { DicomStatus status = null; var request = new DicomCStoreRequest(@".\Test Data\CT-MONO2-16-ankle"); request.OnResponseReceived = (req, res) => { status = res.Status; }; var client = new DicomClient(); client.AddRequest(request); client.Send(NetworkManager.IPv6Loopback, port, false, "SCU", "ANY-SCP"); Assert.Equal(DicomStatus.Success, status); } }
public void Send_PrivateNotRegisteredSOPClass_SendFails() { var port = Ports.GetNext(); using (DicomServer.Create <SimpleCStoreProvider>(port)) { DicomStatus status = null; var request = new DicomCStoreRequest(@".\Test Data\GH355.dcm"); request.OnResponseReceived = (req, res) => { status = res.Status; }; var client = new DicomClient(); client.AddRequest(request); client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); Assert.Equal(DicomStatus.SOPClassNotSupported, status); } }
public void AssociationReleased_SuccessfulSend_IsInvoked() { var port = Ports.GetNext(); using (DicomServer.Create <DicomCEchoProvider>(port)) { var client = new DicomClient(); var released = false; var handle = new ManualResetEventSlim(); client.AssociationReleased += (sender, args) => { released = true; handle.Set(); }; client.AddRequest(new DicomCEchoRequest()); client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); handle.Wait(1000); Assert.True(released); } }
public void Send_SingleRequest_Recognized() { int port = Ports.GetNext(); using (DicomServer.Create <DicomCEchoProvider>(port)) { var counter = 0; var request = new DicomCEchoRequest { OnResponseReceived = (req, res) => Interlocked.Increment(ref counter) }; var client = new DicomClient(); client.AddRequest(request); client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); Assert.Equal(1, counter); } }
public void Send_FromDicomClient_DoesNotDeadlock() { var port = Ports.GetNext(); using (var server = DicomServer.Create <DicomCEchoProvider>(port)) { server.Logger = new XUnitDicomLogger(_output).IncludeTimestamps().IncludeThreadId().IncludePrefix("DicomCEchoProvider"); var client = new Network.DicomClient { Logger = new XUnitDicomLogger(_output).IncludeTimestamps().IncludeThreadId().IncludePrefix("DicomClient") }; for (var i = 0; i < 10; i++) { client.AddRequest(new DicomCEchoRequest()); } client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); Assert.False(client.IsSendRequired); } }
public void Constructor_EstablishTwoWithSamePort_ShouldYieldAccessibleException() { var port = Ports.GetNext(); var server1 = new DicomServer <DicomCEchoProvider>(port); while (!server1.IsListening) { Thread.Sleep(10); } var server2 = new DicomServer <DicomCEchoProvider>(port); Thread.Sleep(500); // Allow for server2 to attempt listening Assert.True(server1.IsListening); Assert.Null(server1.Exception); Assert.False(server2.IsListening); Assert.IsType <SocketException>(server2.Exception); }
public void Send_FromDicomClient_DoesNotDeadlock() { LogManager.SetImplementation(new StringLogManager()); int port = Ports.GetNext(); using (new DicomServer <DicomCEchoProvider>(port)) { var client = new DicomClient(); for (var i = 0; i < 10; i++) { client.AddRequest(new DicomCEchoRequest()); } client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); var log = LogManager.GetLogger(null).ToString(); Assert.True(log.Length > 0); } }
public async Task ReleaseAsync_AfterAssociation_SendIsCompleted() { int port = Ports.GetNext(); using (DicomServer.Create <MockCEchoProvider>(port)) { Task task = null; var client = new DicomClient(); client.AssociationAccepted += HandleAssociationAccepted; client.AddRequest(new DicomCEchoRequest()); task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); void HandleAssociationAccepted(object sender, AssociationAcceptedEventArgs e) { (sender as DicomClient).ReleaseAsync().Wait(); Thread.Sleep(10); Assert.True(task.IsCompleted); } } }
public void Send_KnownSOPClass_SendSucceeds() { var port = Ports.GetNext(); using (DicomServer.Create <SimpleCStoreProvider>(port)) { DicomStatus status = null; var request = new DicomCStoreRequest(@".\Test Data\CT-MONO2-16-ankle") { OnResponseReceived = (req, res) => status = res.Status }; var client = new DicomClient(); client.AddRequest(request); client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); Assert.Equal(DicomStatus.Success, status); } }
public async Task SendAsync_SingleRequest_Recognized() { int port = Ports.GetNext(); using (DicomServer.Create <DicomCEchoProvider>(port)) { var counter = 0; var request = new DicomCEchoRequest { OnResponseReceived = (req, res) => Interlocked.Increment(ref counter) }; var client = new DicomClient(); client.AddRequest(request); var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); await Task.WhenAny(task, Task.Delay(10000)); Assert.Equal(1, counter); } }
public void BeginSend_MultipleRequests_AllRecognized(int expected) { int port = Ports.GetNext(); using (new DicomServer <DicomCEchoProvider>(port)) { var actual = 0; var client = new DicomClient(); for (var i = 0; i < expected; ++i) { client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (req, res) => ++ actual }); } client.EndSend(client.BeginSend("127.0.0.1", port, false, "SCU", "ANY-SCP", null, null)); Assert.Equal(expected, actual); } }
public void Send_MultipleTimes_AllRecognized(int expected) { int port = Ports.GetNext(); var @lock = new object(); using (new DicomServer <DicomCEchoProvider>(port)) { var actual = 0; var client = new DicomClient(); for (var i = 0; i < expected; ++i) { client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (req, res) => { lock (@lock) ++actual; } }); client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); } Assert.Equal(expected, actual); } }
public void IsSendRequired_AddedRequestNotConnected_ReturnsTrue() { var port = Ports.GetNext(); using (DicomServer.Create <DicomCEchoProvider>(port)) { var client = new DicomClient(); client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (req, res) => Thread.Sleep(100) }); Assert.True(client.IsSendRequired); client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); Thread.Sleep(100); client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (req, res) => Thread.Sleep(100) }); Assert.True(client.IsSendRequired); } }
public async Task Send_FromDicomClient_DoesNotDeadlock() { var port = Ports.GetNext(); using (var server = DicomServer.Create <DicomCEchoProvider>(port)) { server.Logger = new XUnitDicomLogger(_output).IncludeTimestamps().IncludeThreadId().IncludePrefix("DicomCEchoProvider"); var client = new Network.Client.DicomClient("127.0.0.1", port, false, "SCU", "ANY-SCP") { Logger = new XUnitDicomLogger(_output).IncludeTimestamps().IncludeThreadId().IncludePrefix("DicomClient") }; for (var i = 0; i < 10; i++) { await client.AddRequestAsync(new DicomCEchoRequest()).ConfigureAwait(false); } await client.SendAsync().ConfigureAwait(false); Assert.Empty(client.QueuedRequests); } }
public async Task SendAsync_MultipleRequests_AllRecognized(int expected) { int port = Ports.GetNext(); using (new DicomServer <DicomCEchoProvider>(port)) { var actual = 0; var client = new DicomClient(); for (var i = 0; i < expected; ++i) { client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (req, res) => ++ actual }); } var task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); await Task.WhenAny(task, Task.Delay(10000)); Assert.Equal(expected, actual); } }
public void Send_FromDicomClient_DoesNotDeadlock() { LogManager.SetImplementation(NLogManager.Instance); var target = NLogHelper.AssignMemoryTarget( "Dicom.Network", @"${message}", NLog.LogLevel.Trace); var port = Ports.GetNext(); using (DicomServer.Create <DicomCEchoProvider>(port)) { var client = new DicomClient(); for (var i = 0; i < 10; i++) { client.AddRequest(new DicomCEchoRequest()); } client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); Assert.True(target.Logs.Count > 0); } }
public async Task Old_ReleaseAsync_AfterAssociation_SendIsCompleted() { int port = Ports.GetNext(); using (CreateServer <MockCEchoProvider>(port)) { Task task = null; var client = CreateOldClient(); client.AssociationAccepted += HandleAssociationAccepted; client.AddRequest(new DicomCEchoRequest()); task = client.SendAsync("127.0.0.1", port, false, "SCU", "ANY-SCP"); async void HandleAssociationAccepted(object sender, AssociationAcceptedEventArgs e) { await client.ReleaseAsync().ConfigureAwait(false); await Task.Delay(1000).ConfigureAwait(false); Assert.True(task.IsCompleted); } } }
public void Stop_IsListening_TrueUntilStopRequested() { var port = Ports.GetNext(); var server = DicomServer.Create <DicomCEchoProvider>(port); while (!server.IsListening) { Thread.Sleep(10); } for (var i = 0; i < 10; ++i) { Thread.Sleep(500); Assert.True(server.IsListening); } server.Stop(); Thread.Sleep(500); Assert.False(server.IsListening); }
public void Send_MultipleRequests_AllRecognized(int expected) { int port = Ports.GetNext(); using (DicomServer.Create <DicomCEchoProvider>(port)) { var actual = 0; var client = new DicomClient(); client.NegotiateAsyncOps(expected, 1); for (var i = 0; i < expected; ++i) { client.AddRequest(new DicomCEchoRequest { OnResponseReceived = (req, res) => Interlocked.Increment(ref actual) }); } client.Send("127.0.0.1", port, false, "SCU", "ANY-SCP"); Assert.Equal(expected, actual); } }
public void Create_MultipleInstancesDifferentPorts_AllRegistered() { var ports = new int[20].Select(i => Ports.GetNext()).ToArray(); foreach (var port in ports) { var server = DicomServer.Create <DicomCEchoProvider>(port); while (!server.IsListening) { Thread.Sleep(10); } } foreach (var port in ports) { Assert.Equal(port, DicomServer.GetInstance(port).Port); } foreach (var port in ports) { DicomServer.GetInstance(port).Dispose(); } }