protected override void SetupMocks()
        {
            var sequence = new MockSequence();

            SessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
            SessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is <ChannelEofMessage>(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true);
            SessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
            SessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is <ChannelCloseMessage>(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true);
            SessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(ConnectionInfoMock.Object);
            ConnectionInfoMock.InSequence(sequence).Setup(p => p.ChannelCloseTimeout).Returns(_channelCloseTimeout);
            SessionMock.InSequence(sequence)
            .Setup(p => p.TryWait(It.IsAny <EventWaitHandle>(), _channelCloseTimeout))
            .Callback <WaitHandle, TimeSpan>((waitHandle, channelCloseTimeout) =>
            {
                new Thread(() =>
                {
                    Thread.Sleep(100);
                    // raise ChannelCloseReceived event to set waithandle for receiving
                    // SSH_MSG_CHANNEL_CLOSE message from server which is waited on after
                    // sending the SSH_MSG_CHANNEL_CLOSE message to the server
                    SessionMock.Raise(s => s.ChannelCloseReceived += null,
                                      new MessageEventArgs <ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
                }).Start();
                _closeTimer.Start();
                try
                {
                    waitHandle.WaitOne();
                }
                finally
                {
                    _closeTimer.Stop();
                }
            })
            .Returns(WaitResult.Success);
        }
示例#2
0
        protected override void SetupMocks()
        {
            _sequence = new MockSequence();

            SessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(ConnectionInfoMock.Object);
            ConnectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1);
            SessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore);
            SessionMock.InSequence(_sequence)
            .Setup(
                p =>
                p.SendMessage(
                    It.Is <ChannelOpenMessage>(
                        m =>
                        m.LocalChannelNumber == _localChannelNumber &&
                        m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize &&
                        m.Info is SessionChannelOpenInfo)));
            SessionMock.InSequence(_sequence)
            .Setup(p => p.WaitOnHandle(It.IsNotNull <WaitHandle>()))
            .Callback <WaitHandle>(
                w =>
            {
                SessionMock.Raise(
                    s => s.ChannelOpenConfirmationReceived += null,
                    new MessageEventArgs <ChannelOpenConfirmationMessage>(
                        new ChannelOpenConfirmationMessage(
                            _localChannelNumber,
                            _remoteWindowSize,
                            _remotePacketSize,
                            _remoteChannelNumber)));
                w.WaitOne();
            });
            SessionMock.Setup(p => p.IsConnected).Returns(false);
        }
示例#3
0
        protected override void SetupMocks()
        {
            var sequence = new MockSequence();

            SessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(ConnectionInfoMock.Object);
            ConnectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1);
            SessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore);
            SessionMock.InSequence(sequence)
            .Setup(
                p =>
                p.SendMessage(
                    It.Is <ChannelOpenMessage>(
                        m =>
                        m.LocalChannelNumber == _localChannelNumber &&
                        m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize &&
                        m.Info is SessionChannelOpenInfo)));
            SessionMock.InSequence(sequence)
            .Setup(p => p.WaitOnHandle(It.IsNotNull <WaitHandle>()))
            .Callback <WaitHandle>(
                w =>
            {
                SessionMock.Raise(
                    s => s.ChannelOpenConfirmationReceived += null,
                    new MessageEventArgs <ChannelOpenConfirmationMessage>(
                        new ChannelOpenConfirmationMessage(
                            _localChannelNumber,
                            _remoteWindowSize,
                            _remotePacketSize,
                            _remoteChannelNumber)));
                w.WaitOne();
            });
            SessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
            SessionMock.InSequence(sequence)
            .Setup(
                p => p.TrySendMessage(It.Is <ChannelEofMessage>(m => m.LocalChannelNumber == _remoteChannelNumber)))
            .Returns(true);
            SessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
            SessionMock.InSequence(sequence)
            .Setup(
                p => p.TrySendMessage(It.Is <ChannelCloseMessage>(m => m.LocalChannelNumber == _remoteChannelNumber)))
            .Returns(true);
            SessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(ConnectionInfoMock.Object);
            ConnectionInfoMock.InSequence(sequence).Setup(p => p.ChannelCloseTimeout).Returns(_channelCloseTimeout);
            SessionMock.InSequence(sequence)
            .Setup(p => p.TryWait(It.IsNotNull <WaitHandle>(), _channelCloseTimeout))
            .Callback <WaitHandle, TimeSpan>(
                (waitHandle, channelCloseTimeout) =>
            {
                SessionMock.Raise(
                    s => s.ChannelCloseReceived += null,
                    new MessageEventArgs <ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
                waitHandle.WaitOne();
            })
            .Returns(WaitResult.Success);
        }
示例#4
0
        protected override void Arrange()
        {
            base.Arrange();

            _channel            = new ChannelSession(SessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
            _channel.Closed    += (sender, args) => _channelClosedRegister.Add(args);
            _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
            _channel.Open();

            SessionMock.Raise(
                p => p.ChannelCloseReceived += null,
                new MessageEventArgs <ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
        }
        protected override void Arrange()
        {
            base.Arrange();

            _channel            = new ChannelStub(SessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
            _channel.Closed    += (sender, args) => { _channelClosedRegister.Add(args); };
            _channel.EndOfData += (sender, args) => _channelEndOfDataRegister.Add(args);
            _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
            _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize);
            _channel.SetIsOpen(true);

            SessionMock.Raise(
                s => s.ChannelEofReceived += null,
                new MessageEventArgs <ChannelEofMessage>(new ChannelEofMessage(_localChannelNumber)));
        }
        protected override void SetupMocks()
        {
            var sequence = new MockSequence();

            SessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
            SessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is <ChannelCloseMessage>(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true);
            SessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(ConnectionInfoMock.Object);
            ConnectionInfoMock.InSequence(sequence).Setup(p => p.ChannelCloseTimeout).Returns(_channelCloseTimeout);
            SessionMock.InSequence(sequence)
            .Setup(p => p.TryWait(It.IsAny <EventWaitHandle>(), _channelCloseTimeout))
            .Callback <WaitHandle, TimeSpan>((waitHandle, channelCloseTimeout) =>
            {
                _raiseChannelCloseReceivedThread = new Thread(() =>
                {
                    Thread.Sleep(100);

                    // signal that the ChannelCloseMessage was received; we use this to verify whether we've actually
                    // waited on the EventWaitHandle to be set; this needs to be set before we raise the ChannelCloseReceived
                    // to make sure the waithandle is signaled when the Dispose method completes (or else the assert that
                    // checks whether the handle has been signaled, will sometimes fail)
                    _channelClosedReceived.Set();

                    // raise ChannelCloseReceived event to set waithandle for receiving SSH_MSG_CHANNEL_CLOSE message
                    // from server which is waited on after sending the SSH_MSG_CHANNEL_CLOSE message to the server
                    //
                    // this will cause a new invocation of Close() that will block until the Close() that was invoked
                    // as part of Dispose() has released the lock; as such, this thread cannot be joined until that
                    // lock is released
                    //
                    // we're mocking the wait on the ChannelCloseMessage, but we still want
                    // to get the channel in the state that it would have after actually receiving
                    // the ChannelCloseMessage
                    SessionMock.Raise(s => s.ChannelCloseReceived += null, new MessageEventArgs <ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
                });
                _raiseChannelCloseReceivedThread.Start();
                waitHandle.WaitOne();
            })
            .Returns(WaitResult.Success);
        }
 protected override void Act()
 {
     SessionMock.Raise(
         s => s.ChannelCloseReceived += null,
         new MessageEventArgs <ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
 }
示例#8
0
 protected override void Act()
 {
     SessionMock.Raise(s => s.ChannelRequestReceived += null,
                       new MessageEventArgs <ChannelRequestMessage>(new ChannelRequestMessage(_localChannelNumber, _requestInfo)));
 }
示例#9
0
 protected override void Act()
 {
     SessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty);
 }
 protected override void Act()
 {
     SessionMock.Raise(s => s.ChannelExtendedDataReceived += null,
                       new MessageEventArgs <ChannelExtendedDataMessage>(new ChannelExtendedDataMessage(_localChannelNumber, 5, new byte[0])));
 }
 protected override void Act()
 {
     SessionMock.Raise(s => s.ChannelWindowAdjustReceived += null,
                       new MessageEventArgs <ChannelWindowAdjustMessage>(new ChannelWindowAdjustMessage(_localChannelNumber, _bytesToAdd)));
 }
 protected override void Act()
 {
     SessionMock.Raise(s => s.ErrorOccured += null, new ExceptionEventArgs(_errorOccurredException));
 }