Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
        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);
            }
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
            }
        }
Пример #12
0
        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);
            }
        }
Пример #13
0
        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);
            }
        }
Пример #14
0
        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);
            }
        }
Пример #15
0
        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);
            }
        }
Пример #16
0
        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);
        }
Пример #17
0
        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);
            }
        }
Пример #18
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);
                }
            }
        }
Пример #19
0
        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);
            }
        }
Пример #20
0
        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);
            }
        }
Пример #21
0
        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);
            }
        }
Пример #22
0
        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);
            }
        }
Пример #23
0
        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);
            }
        }
Пример #24
0
        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);
            }
        }
Пример #25
0
        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);
            }
        }
Пример #27
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);
                }
            }
        }
Пример #28
0
        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);
        }
Пример #29
0
        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);
            }
        }
Пример #30
0
        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();
            }
        }