Exemple #1
0
        public async void Operator_DisconnectCommand_ShouldDisconnect()
        {
            // Arrange
            var apiOperator = IntegrationTestsHelpers.ArrangeLocalOperatorTestWrapperRealSockets("127.0.0.1:9111");
            var remote      = IntegrationTestsHelpers.ArrangeRemoteApiMapTestWrapperWithRealSockets("127.0.0.1:9222");
            await apiOperator.MessageDisplayed;

            await apiOperator.RaiseCommandReceived("connect 127.0.0.1:9222");

            await apiOperator.MessageDisplayed;
            await remote.ConnectedComplete;

            apiOperator.Recorder.ClearCache();

            // Act
            await apiOperator.RaiseCommandReceived("disconnect");

            await apiOperator.MessageDisplayed;

            //Assert
            Assert.False(apiOperator.Sockets[2].Connected);
            Assert.Equal(1, apiOperator.Sockets[2].DisposeCalledTimes);
            Assert.True(apiOperator.Sockets[5].Connected);
            Assert.Equal(2, apiOperator.Sockets[5].ReceiveCalledTimes);
            Assert.False(remote.Sockets[1].Connected);

            // Log
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, apiOperator.Recorder);
            _output.WriteLine("-----------------------------");
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, remote.Recorder);
        }
Exemple #2
0
        public async void Operator_CommandAndConnectAndDisconnect_ShouldDisplayMessages()
        {
            // Arrange
            var apiOperator = IntegrationTestsHelpers.ArrangeLocalOperatorTestWrapperRealSockets("127.0.0.1:9333");
            var remote      = IntegrationTestsHelpers.ArrangeRemoteApiMapTestWrapperWithRealSockets("127.0.0.1:9444");
            await apiOperator.MessageDisplayed;
            await apiOperator.RaiseCommandReceived("hi");

            await apiOperator.MessageDisplayed;

            await apiOperator.RaiseCommandReceived("connect 127.0.0.1:9444");

            await apiOperator.MessageDisplayed;
            await remote.ConnectedComplete;

            // Act
            await apiOperator.RaiseCommandReceived("disconnect");

            await apiOperator.MessageDisplayed;

            //Assert
            Assert.Equal(4, apiOperator.Recorder.DisplayMessagesCalledTimes);

            // Log
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, apiOperator.Recorder);
        }
Exemple #3
0
        public async void Operator_WhenRemoteSocketDisconnected_ShouldConnectAgain()
        {
            var wrongCommandCalledTimes = 0;
            var wrongCommandCalledTimesIntermediateState = 0;
            var apiOperator = IntegrationTestsHelpers.ArrangeLocalOperatorTestWrapperRealSockets("127.0.0.1:11112");
            var remote      = IntegrationTestsHelpers.ArrangeRemoteApiMapTestWrapperWithRealSockets("127.0.0.1:22223");

            remote.ApiMap.RegisterWrongCommandHandler(() => wrongCommandCalledTimes++);
            await apiOperator.MessageDisplayed;
            await apiOperator.RaiseCommandReceived("connect 127.0.0.1:22223");

            await remote.ConnectedComplete;

            remote.Sockets[1].Close();
            wrongCommandCalledTimesIntermediateState = wrongCommandCalledTimes;
            await apiOperator.Sockets[2].Disposed;

            apiOperator.Recorder.ClearCache();
            remote.Recorder.ClearCache();

            await apiOperator.RaiseCommandReceived("hello");

            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, apiOperator.Recorder);
            _output.WriteLine("-----------------------------");
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, remote.Recorder);
            Assert.Equal(1, apiOperator.Sockets[1].CloseCalledTimes);
            Assert.Equal(1, wrongCommandCalledTimes);
            Assert.Equal(0, wrongCommandCalledTimesIntermediateState);
        }
Exemple #4
0
        public async void Operator_WhenRemoteSocketDisconnectedAndLost_ShouldTryConnectAndShowMessage()
        {
            var apiOperator = IntegrationTestsHelpers.ArrangeLocalOperatorTestWrapperRealSockets("127.0.0.1:11111");
            var remote      = IntegrationTestsHelpers.ArrangeRemoteApiMapTestWrapperWithRealSockets("127.0.0.1:22222");

            remote.ApiMap.RegisterWrongCommandHandler(() =>
                                                      ((IApplicationRecorder)remote.Recorder).RecordInfo("wrong", "wrong"));
            await apiOperator.MessageDisplayed;
            await apiOperator.RaiseCommandReceived("connect 127.0.0.1:22222");

            await remote.ConnectedComplete;

            remote.Sockets[1].Close();
            remote.Sockets[0].Close();
            await apiOperator.Sockets[2].Disposed;

            apiOperator.Recorder.ClearCache();
            remote.Recorder.ClearCache();

            await apiOperator.RaiseCommandReceived("hello");

            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, apiOperator.Recorder);
            _output.WriteLine("-----------------------------");
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, remote.Recorder);
            Assert.Equal(1, apiOperator.Sockets[1].CloseCalledTimes);
            Assert.Equal(1, apiOperator.Sockets[1].DisposeCalledTimes);
            Assert.Equal(2, apiOperator.Recorder.SystemErrorCalledTimes);
        }
Exemple #5
0
        public async void Operator_WhenSendWrongCommandToRemote_ShouldCallWrongCommand()
        {
            bool wrongCommandWasCalled = false;
            var  socket = new SocketTester("remote");

            socket.SetLocalEndPoint(IPAddress.Parse("111.111.111.111"), 11111);
            var local = ArrangeLocalOperatorTestWrapper(
                new [] { socket },
                "111.111.111.111:11111");

            var remote = ArrangeRemoteApiMapWithSocketsAndRecorders(socket, "222.222.222.222:2222");

            remote.ApiMap.RegisterWrongCommandHandler(() => wrongCommandWasCalled = true);
            await local.Initialized;
            await local.RaiseCommandReceived("connect 222.222.222.222:2222");

            local.Recorder.ClearCache();
            remote.Recorder.ClearCache();

            await local.RaiseCommandReceived("hello");

            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, local.Recorder);
            _output.WriteLine("-----------------------------");
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, remote.Recorder);
            Assert.True(wrongCommandWasCalled);
        }
Exemple #6
0
        public async void Operator_WhenCalledConnectWithIncorrectParameters_ShouldCatchError()
        {
            var local = ArrangeLocalOperatorTestWrapper();
            await local.Initialized;

            await local.RaiseCommandReceived("connect 123.3324234");

            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, local.Recorder);
            Assert.Equal(1, local.Recorder.SystemErrorCalledTimes);
        }
Exemple #7
0
        public async void Operator_WhenCalledConnectWithNotExistingAddress_ShouldCatchError()
        {
            var socket = new SocketTester();

            socket.ConnectAction = (address, i) => throw new Exception("Connect exception");
            var local = ArrangeLocalOperatorTestWrapper(new [] { socket });
            await local.Initialized;

            await local.RaiseCommandReceived("connect 123.0.0.2:2334");

            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, local.Recorder);
            Assert.Equal(1, socket.ConnectCalledTimes);
        }
Exemple #8
0
        public async void Operator_WhenConnectToRemoteSocket_ShouldDisconnectLocal()
        {
            var apiOperator = IntegrationTestsHelpers.ArrangeLocalOperatorTestWrapperRealSockets("127.0.0.1:11113");
            var remote      = IntegrationTestsHelpers.ArrangeRemoteApiMapTestWrapperWithRealSockets("127.0.0.1:22224");
            await apiOperator.MessageDisplayed;

            await apiOperator.RaiseCommandReceived("connect 127.0.0.1:22224");

            await remote.ConnectedComplete;

            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, apiOperator.Recorder);
            _output.WriteLine("-----------------------------");
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, remote.Recorder);
            Assert.Equal(1, apiOperator.Sockets[1].CloseCalledTimes);
        }
Exemple #9
0
        public async void Operator_WhenCalledConnectWithExistingAddress_ShouldConnect()
        {
            var socket      = new SocketTester("remote");
            var operatorApi = ArrangeLocalOperatorTestWrapper(
                new [] { socket },
                "111.111.111.111:11111");

            var remote = ArrangeRemoteApiMapWithSocketsAndRecorders(socket, "222.222.222.222:2222");
            await operatorApi.Initialized;

            operatorApi.Recorder.ClearCache();

            await operatorApi.RaiseCommandReceived("connect 222.222.222.222:2222");

            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, operatorApi.Recorder);
            _output.WriteLine("-----------------------------");
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, remote.Recorder);
            Assert.Equal(1, socket.ConnectCalledTimes);
        }
Exemple #10
0
        public async void Operator_WhenCommandWithParametersSend_ShouldGetParameters(
            int sendCommandTimes,
            int allReceivedParamsCountExpected,
            string sentParameter,
            string localPort,
            string remotePort)
        {
            var allReceivedParamsCountActual = 0;
            var apiOperator = IntegrationTestsHelpers.ArrangeLocalOperatorTestWrapperRealSockets($"127.0.0.1:{localPort}");
            var remote      = IntegrationTestsHelpers.ArrangeRemoteApiMapTestWrapperWithRealSockets($"127.0.0.1:{remotePort}");

            remote.ApiMap.RegisterCommandWithParameters("commandWithParam", parameter =>
            {
                foreach (var one in parameter)
                {
                    allReceivedParamsCountActual += one.Length;
                }
                ((IApplicationRecorder)remote.Recorder).RecordInfo("", "executed");
            });

            await apiOperator.MessageDisplayed;
            await apiOperator.RaiseCommandReceived($"connect 127.0.0.1:{remotePort}");

            await remote.ConnectedComplete;

            apiOperator.Recorder.ClearCache();
            remote.Recorder.ClearCache();

            for (int i = 0; i < sendCommandTimes; i++)
            {
                await apiOperator.RaiseCommandReceived($"commandWithParam {sentParameter}");

                await apiOperator.MessageDisplayed;
            }

            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, apiOperator.Recorder);
            _output.WriteLine("-----------------------------");
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, remote.Recorder);
            Assert.Equal(allReceivedParamsCountActual, allReceivedParamsCountExpected);
        }
Exemple #11
0
        public async void Operator_ConnectAndCommandAndDisconnectAndConnect_ShouldDisplayMessages()
        {
            // Arrange
            var apiOperator = IntegrationTestsHelpers.ArrangeLocalOperatorTestWrapperRealSockets("127.0.0.1:9555");
            var remote      = IntegrationTestsHelpers.ArrangeRemoteApiMapTestWrapperWithRealSockets("127.0.0.1:9666");

            remote.ApiMap.RegisterCommand("example", () =>
            {
                ((IApplicationRecorder)remote.Recorder).RecordInfo("cmd", "executed");
            });

            await apiOperator.MessageDisplayed;
            await apiOperator.RaiseCommandReceived("connect 127.0.0.1:9666");

            await apiOperator.MessageDisplayed;
            await remote.ConnectedComplete;
            await apiOperator.RaiseCommandReceived("example");

            await apiOperator.MessageDisplayed;

            // Act
            await apiOperator.RaiseCommandReceived("disconnect");

            await apiOperator.MessageDisplayed;

            await apiOperator.RaiseCommandReceived("connect 127.0.0.1:9666");

            await apiOperator.MessageDisplayed;
            await remote.ConnectedComplete;

            //Assert
            Assert.Equal(5, apiOperator.Recorder.DisplayMessagesCalledTimes);
            Assert.Equal(1, remote.Recorder.AppInfoCalledTimes);

            // Log
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, apiOperator.Recorder);
            _output.WriteLine("-----------------------------");
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, remote.Recorder);
        }
Exemple #12
0
        public async void Operator_WhenCommandSend_ShouldDisplayInMonitor2(
            int expectedMessageDisplays,
            int sendCommandTimes,
            int expectedWrongCommandCalled,
            string localPort,
            string remotePort)
        {
            var actualCommandCalledTimes = 0;
            var apiOperator = IntegrationTestsHelpers.ArrangeLocalOperatorTestWrapperRealSockets($"127.0.0.1:{localPort}");
            var remote      = IntegrationTestsHelpers.ArrangeRemoteApiMapTestWrapperWithRealSockets($"127.0.0.1:{remotePort}");

            remote.ApiMap.RegisterCommand("someCommand", () =>
            {
                actualCommandCalledTimes++;
                ((IApplicationRecorder)remote.Recorder).RecordInfo("", "some command executed");
            });

            await apiOperator.MessageDisplayed;
            await apiOperator.RaiseCommandReceived($"connect 127.0.0.1:{remotePort}");

            await remote.ConnectedComplete;

            apiOperator.Recorder.ClearCache();
            remote.Recorder.ClearCache();

            for (int i = 0; i < sendCommandTimes; i++)
            {
                await apiOperator.RaiseCommandReceived("someCommand");

                await apiOperator.MessageDisplayed;
            }

            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, apiOperator.Recorder);
            _output.WriteLine("-----------------------------");
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, remote.Recorder);
            Assert.Equal(expectedWrongCommandCalled, actualCommandCalledTimes);
            Assert.Equal(expectedMessageDisplays, apiOperator.Recorder.DisplayMessagesCalledTimes);
        }
Exemple #13
0
        public async void Operator_WhenRemoteSocketDisconnected_ShouldDisposeSocket()
        {
            var socket = new SocketTester("remote");
            var local  = ArrangeLocalOperatorTestWrapper(
                new [] { socket },
                "111.111.111.111:11111");

            var remote = ArrangeRemoteApiMapWithSocketsAndRecorders(socket, "222.222.222.222:2222");
            await local.Initialized;
            await local.RaiseCommandReceived("connect 222.222.222.222:2222");

            await remote.Connected;

            local.Recorder.ClearCache();
            remote.Recorder.ClearCache();

            socket.RaiseDisconnected();

            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, local.Recorder);
            _output.WriteLine("-----------------------------");
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, remote.Recorder);
            Assert.Equal(1, remote.Sockets["connecter"].DisposeCalledTimes);
        }
Exemple #14
0
        public async void Operator_ConnectCommandDisconnectSeveral_ShouldShowMessagesCorrect()
        {
            // Arrange
            var apiOperator = IntegrationTestsHelpers.ArrangeLocalOperatorTestWrapperRealSockets("127.0.0.1:9777");
            var remote      = IntegrationTestsHelpers.ArrangeRemoteApiMapTestWrapperWithRealSockets("127.0.0.1:29888");
            await apiOperator.MessageDisplayed;

            remote.ApiMap.RegisterCommand("execute", () =>
            {
                ((IApplicationRecorder)remote.Recorder).RecordInfo("cmd", "executed");
            });

            for (int i = 0; i < 2; i++)
            {
                await apiOperator.RaiseCommandReceived("connect 127.0.0.1:29888");

                await apiOperator.MessageDisplayed;
                await remote.ConnectedComplete;

                await apiOperator.RaiseCommandReceived("execute");

                await apiOperator.MessageDisplayed;

                await apiOperator.RaiseCommandReceived("disconnect");

                await apiOperator.MessageDisplayed;
            }

            //Assert
            Assert.False(false);

            // Log
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, apiOperator.Recorder);
            _output.WriteLine("-----------------------------");
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, remote.Recorder);
        }
Exemple #15
0
        public async void Operator_WhenSendCommandToRemote_ShouldReceiveCommand()
        {
            int command1ReceivedTimes = 0;
            int command2ReceivedTimes = 0;
            int command3ReceivedTimes = 0;
            var socket = new SocketTester("remote");
            var local  = ArrangeLocalOperatorTestWrapper(
                new [] { socket },
                "111.111.111.111:11111");

            var remote = ArrangeRemoteApiMapWithSocketsAndRecorders(socket, "222.222.222.222:2222");

            remote.ApiMap.RegisterCommand("command1", () => command1ReceivedTimes++);
            remote.ApiMap.RegisterCommand("command2", () => command2ReceivedTimes++);
            remote.ApiMap.RegisterCommand("command3", () => command3ReceivedTimes++);
            await local.Initialized;
            await local.RaiseCommandReceived("connect 222.222.222.222:2222");

            local.Recorder.ClearCache();
            remote.Recorder.ClearCache();

            await local.RaiseCommandReceived("command1");

            await local.RaiseCommandReceived("command2");

            await local.RaiseCommandReceived("command2");

            await local.RaiseCommandReceived("command3");

            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, local.Recorder);
            _output.WriteLine("-----------------------------");
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, remote.Recorder);
            Assert.Equal(1, command1ReceivedTimes);
            Assert.Equal(2, command2ReceivedTimes);
            Assert.Equal(1, command3ReceivedTimes);
        }
Exemple #16
0
        public async void Operator_ConnectCommandDisconnectSeveralDifferent_ShouldShowMessagesCorrect()
        {
            // Arrange
            var apiOperator = IntegrationTestsHelpers.ArrangeLocalOperatorTestWrapperRealSockets("127.0.0.1:12121");
            var remote1     = IntegrationTestsHelpers.ArrangeRemoteApiMapTestWrapperWithRealSockets("127.0.0.1:10101");

            remote1.ApiMap.RegisterCommand("execute1", () =>
            {
                ((IApplicationRecorder)remote1.Recorder).RecordInfo("cmd", "executed1");
            });
            var remote2 = IntegrationTestsHelpers.ArrangeRemoteApiMapTestWrapperWithRealSockets("127.0.0.1:20202");

            remote2.ApiMap.RegisterCommand("execute2", () =>
            {
                ((IApplicationRecorder)remote2.Recorder).RecordInfo("cmd", "executed2");
            });
            var remote3 = IntegrationTestsHelpers.ArrangeRemoteApiMapTestWrapperWithRealSockets("127.0.0.1:30303");

            remote3.ApiMap.RegisterCommand("execute3", () =>
            {
                ((IApplicationRecorder)remote3.Recorder).RecordInfo("cmd", "executed3");
            });

            await apiOperator.MessageDisplayed;

            await apiOperator.RaiseCommandReceived("connect 127.0.0.1:10101");

            await apiOperator.MessageDisplayed;
            await remote1.ConnectedComplete;
            await apiOperator.RaiseCommandReceived("execute1");

            await apiOperator.MessageDisplayed;
            await apiOperator.RaiseCommandReceived("disconnect");

            await apiOperator.MessageDisplayed;

            await apiOperator.RaiseCommandReceived("connect 127.0.0.1:20202");

            await apiOperator.MessageDisplayed;
            await remote1.ConnectedComplete;
            await apiOperator.RaiseCommandReceived("execute2");

            await apiOperator.MessageDisplayed;
            await apiOperator.RaiseCommandReceived("disconnect");

            await apiOperator.MessageDisplayed;

            await apiOperator.RaiseCommandReceived("connect 127.0.0.1:30303");

            await apiOperator.MessageDisplayed;
            await remote1.ConnectedComplete;
            await apiOperator.RaiseCommandReceived("execute3");

            await apiOperator.MessageDisplayed;
            await apiOperator.RaiseCommandReceived("disconnect");

            await apiOperator.MessageDisplayed;

            await apiOperator.RaiseCommandReceived("connect 127.0.0.1:10101");

            await apiOperator.MessageDisplayed;
            await remote1.ConnectedComplete;

            //Assert
            Assert.False(false);

            // Log
            IntegrationTestsHelpers.LogCacheRecorderTestInfo(_output, apiOperator.Recorder);
        }