Exemplo n.º 1
0
        public void Test_ConnectDisconnectWhenRoboDKIsAlreadyRunning()
        {
            var rdk = new RoboDK();

            for (var i = 0; i < 10; i++)
            {
                rdk.Connected().Should().BeFalse();
                rdk.Connect().Should().BeTrue();

                // RoboDK is already running. It is not expected that connect will start a new process
                rdk.Process.Should().BeNull();
                rdk.Connected().Should().BeTrue();

                // Test some properties
                rdk.Version().Should().StartWith("5");
                rdk.ApiVersion.Should().BeGreaterThan(0);
                rdk.RoboDKBuild.Should().BeGreaterThan(0);
                rdk.RoboDKServerPort.Should().BeGreaterThan(0);
                rdk.RoboDKClientPort.Should().BeGreaterThan(0);
                rdk.RoboDKServerIpAddress.Length.Should().BeGreaterThan(0);
                rdk.DefaultSocketTimeoutMilliseconds.Should().BeGreaterThan(1000);

                rdk.Disconnect();
                rdk.Connected().Should().BeFalse();
            }
        }
Exemplo n.º 2
0
        public void Test_WhenConnectingOnUsedActiveSocketThenNoConnectionAndRoboDkNotStarted()
        {
            var port = 56252;

            while (!RoboDK.IsTcpPortFree(port))
            {
                port++;
            }

            using (var s = new SocketHelper())
            {
                s.OpenServerAndClient(port);

                RoboDK.IsTcpPortFree(s.ServerPort).Should().BeFalse();
                RoboDK.IsTcpPortFree(s.ClientPort).Should().BeFalse();

                var rdk = new RoboDK
                {
                    RoboDKServerStartPort = port,
                };

                rdk.Connect().Should().BeFalse();
                rdk.Connected().Should().BeFalse();
                rdk.Process.Should().BeNull();

                rdk.Connect().Should().BeFalse();
                rdk.Connected().Should().BeFalse();
                rdk.Process.Should().BeNull();

                rdk.Invoking(r => r.CloseRoboDK())
                .Should().Throw <RdkException>();
            }
        }
Exemplo n.º 3
0
        public void Test_WhenStartingOnUsedActiveSocketThenNoConnectionAndRoboDkNotStarted()
        {
            var port = 56252;

            while (!RoboDK.IsTcpPortFree(port))
            {
                port++;
            }

            using (var s = new SocketHelper())
            {
                s.OpenServerAndClient(port);

                RoboDK.IsTcpPortFree(s.ServerPort).Should().BeFalse();
                RoboDK.IsTcpPortFree(s.ClientPort).Should().BeFalse();

                var rdk = new RoboDK
                {
                    StartNewInstance      = true,
                    RoboDKServerStartPort = port,
                };

                rdk.Connect().Should().BeFalse();
                rdk.Connected().Should().BeFalse();
                rdk.Process.Should().NotBeNull();
                rdk.Process.HasExited.Should().BeTrue();
                Process.GetProcessesByName("RoboDK").Should().BeEmpty();

                rdk.Connect().Should().BeFalse();
                rdk.Connected().Should().BeFalse();
                rdk.Process.Should().NotBeNull();
                rdk.Process.HasExited.Should().BeTrue();
                Process.GetProcessesByName("RoboDK").Should().BeEmpty();

                rdk.Invoking(r => r.CloseRoboDK())
                .Should().Throw <RdkException>();
            }
        }