Beispiel #1
0
        public async void NetworkImitatorDisconnectedTest()
        {
            var receivedTask  = new TaskCompletionSource <bool>();
            var bytesReceived = new byte[1024];
            var size          = 0;
            var socket2       = new SocketTester();

            bytesReceived = new byte[1024];
            Task.Run(async() =>
            {
                socket2.Connect(new IPAddress(0), 0);
                size = socket2.Receive(bytesReceived);
                receivedTask.SetResult(true);
            });

            await Task.Delay(500);

            socket2.RaiseDisconnected();
            await receivedTask.Task;

            Assert.Equal(0, size);
            Assert.False(socket2.Connected);
        }
Beispiel #2
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);
        }