public void Constructor() { var target = new SftpHandleResponse(_protocolVersion); Assert.IsNull(target.Handle); Assert.AreEqual(_protocolVersion, target.ProtocolVersion); Assert.AreEqual((uint) 0, target.ResponseId); Assert.AreEqual(SftpMessageTypes.Handle, target.SftpMessageType); }
public void Complete_SftpHandleResponse() { var statusActionInvocations = new List<SftpStatusResponse>(); var handleActionInvocations = new List<SftpHandleResponse>(); Action<SftpStatusResponse> statusAction = statusActionInvocations.Add; Action<SftpHandleResponse> handleAction = handleActionInvocations.Add; var handleResponse = new SftpHandleResponse(_protocolVersion); var request = new SftpOpenDirRequest(_protocolVersion, _requestId, _path, _encoding, handleAction, statusAction); request.Complete(handleResponse); Assert.AreEqual(0, statusActionInvocations.Count); Assert.AreEqual(1, handleActionInvocations.Count); Assert.AreSame(handleResponse, handleActionInvocations[0]); }
public void Load() { var target = new SftpHandleResponse(_protocolVersion); var sshDataStream = new SshDataStream(4 + _handle.Length); sshDataStream.Write(_responseId); sshDataStream.Write((uint) _handle.Length); sshDataStream.Write(_handle, 0, _handle.Length); target.Load(sshDataStream.ToArray()); Assert.IsNotNull(target.Handle); Assert.IsTrue(target.Handle.SequenceEqual(_handle)); Assert.AreEqual(_protocolVersion, target.ProtocolVersion); Assert.AreEqual(_responseId, target.ResponseId); Assert.AreEqual(SftpMessageTypes.Handle, target.SftpMessageType); }
public void Load() { var target = new SftpHandleResponse(_protocolVersion); #if TUNING var sshDataStream = new SshDataStream(4 + 1 + 4 + _handle.Length); sshDataStream.Position = 4; // skip 4 bytes for SSH packet length #else var sshDataStream = new SshDataStream(1 + 4 + _handle.Length); #endif sshDataStream.WriteByte((byte) SftpMessageTypes.Handle); sshDataStream.Write(_responseId); sshDataStream.Write((uint) _handle.Length); sshDataStream.Write(_handle, 0, _handle.Length); target.Load(sshDataStream.ToArray()); Assert.IsNotNull(target.Handle); Assert.IsTrue(target.Handle.SequenceEqual(_handle)); Assert.AreEqual(_protocolVersion, target.ProtocolVersion); Assert.AreEqual(_responseId, target.ResponseId); Assert.AreEqual(SftpMessageTypes.Handle, target.SftpMessageType); }
private static SftpMessage Load(uint protocolVersion, byte[] data, SftpMessageTypes messageType, Encoding encoding) { SftpMessage message; switch (messageType) { case SftpMessageTypes.Version: message = new SftpVersionResponse(); break; case SftpMessageTypes.Status: message = new SftpStatusResponse(protocolVersion); break; case SftpMessageTypes.Data: message = new SftpDataResponse(protocolVersion); break; case SftpMessageTypes.Handle: message = new SftpHandleResponse(protocolVersion); break; case SftpMessageTypes.Name: message = new SftpNameResponse(protocolVersion, encoding); break; case SftpMessageTypes.Attrs: message = new SftpAttrsResponse(protocolVersion); break; case SftpMessageTypes.ExtendedReply: message = new SftpExtendedReplyResponse(protocolVersion); break; default: throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Message type '{0}' is not supported.", messageType)); } message.LoadBytes(data); message.ResetReader(); message.LoadData(); return message; }