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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }