Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
            }
        }