Exemple #1
0
        public async Task Create_SubclassedServer_SufficientlyCreated()
        {
            var port = Ports.GetNext();

            using var server = DicomServerFactory.Create <DicomCEchoProvider, DicomCEchoProviderServer>(null, port, logger: _logger.IncludePrefix("DicomServer"));

            Assert.IsType <DicomCEchoProviderServer>(server);
            Assert.Equal(DicomServerRegistry.Get(port)?.DicomServer, server);

            var status = DicomStatus.UnrecognizedOperation;
            var handle = new ManualResetEventSlim();

            var client = DicomClientFactory.Create("127.0.0.1", port, false, "SCU", "ANY-SCP");

            client.Logger = _logger.IncludePrefix("DicomClient");
            await client.AddRequestAsync(new DicomCEchoRequest
            {
                OnResponseReceived = (req, rsp) =>
                {
                    status = rsp.Status;
                    handle.Set();
                }
            });

            await client.SendAsync();

            handle.Wait(1000);
            Assert.Equal(DicomStatus.Success, status);
        }
Exemple #2
0
        public void IsListening_DicomServerNotInitializedOnPort_ReturnsFalse()
        {
            var port = Ports.GetNext();

            using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer")))
            {
                Assert.False(DicomServerRegistry.Get(Ports.GetNext())?.DicomServer?.IsListening ?? false);
            }
        }
Exemple #3
0
        public void Create_GetInstanceSamePortAfterDisposal_ReturnsNull()
        {
            var port = Ports.GetNext();

            using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"))) { /* do nothing here */ }

            var server = DicomServerRegistry.Get(port)?.DicomServer;

            Assert.Null(server);
        }
Exemple #4
0
        public void Create_GetInstanceSamePort_ReturnsInstance()
        {
            var port = Ports.GetNext();

            using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer")))
            {
                var server = DicomServerRegistry.Get(port)?.DicomServer;
                Assert.Equal(port, server.Port);
            }
        }
Exemple #5
0
        public void Create_GetInstanceDifferentPort_ReturnsNull()
        {
            var port = Ports.GetNext();

            using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer")))
            {
                var server = DicomServerRegistry.Get(Ports.GetNext());
                Assert.Null(server);
            }
        }
Exemple #6
0
        public void IsListening_DicomServerRunningOnPort_ReturnsTrue()
        {
            var port = Ports.GetNext();

            using var server = DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"));
            while (!server.IsListening)
            {
                Thread.Sleep(10);
            }
            Assert.True(DicomServerRegistry.Get(port).DicomServer.IsListening);
        }
Exemple #7
0
        public void Create_TwiceOnSamePortWithDisposalInBetween_DoesNotThrow()
        {
            var port = Ports.GetNext();

            using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer")))
            {
                /* do nothing here */
            }

            var e = Record.Exception(
                () =>
            {
                using (DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer")))
                {
                    Assert.NotNull(DicomServerRegistry.Get(port)?.DicomServer);
                }
            });

            Assert.Null(e);
        }
Exemple #8
0
        public void IsListening_DicomServerStoppedOnPort_ReturnsFalse()
        {
            var port = Ports.GetNext();

            using var server = DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"));
            while (!server.IsListening)
            {
                Thread.Sleep(10);
            }
            server.Stop();
            while (server.IsListening)
            {
                Thread.Sleep(10);
            }

            var dicomServer = DicomServerRegistry.Get(port)?.DicomServer;

            Assert.NotNull(dicomServer);
            Assert.False(dicomServer.IsListening);
        }
Exemple #9
0
        public void Create_MultipleInstancesDifferentPorts_AllRegistered()
        {
            var ports = new int[20].Select(i => Ports.GetNext()).ToArray();

            foreach (var port in ports)
            {
                var server = DicomServerFactory.Create <DicomCEchoProvider>(port, logger: _logger.IncludePrefix("DicomServer"));
                while (!server.IsListening)
                {
                    Thread.Sleep(10);
                }
            }

            foreach (var port in ports)
            {
                Assert.Equal(port, DicomServerRegistry.Get(port)?.DicomServer.Port);
            }

            foreach (var port in ports)
            {
                DicomServerRegistry.Get(port)?.DicomServer.Dispose();
            }
        }