public void Complete_SftpNameResponse() { var statusActionInvocations = new List<SftpStatusResponse>(); var nameActionInvocations = new List<SftpNameResponse>(); Action<SftpStatusResponse> statusAction = statusActionInvocations.Add; Action<SftpNameResponse> nameAction = nameActionInvocations.Add; var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); var request = new SftpRealPathRequest(_protocolVersion, _requestId, _path, _encoding, nameAction, statusAction); request.Complete(nameResponse); Assert.AreEqual(0, statusActionInvocations.Count); Assert.AreEqual(1, nameActionInvocations.Count); Assert.AreSame(nameResponse, nameActionInvocations[0]); }
public void Constructor() { var statusActionInvocations = new List<SftpStatusResponse>(); var nameActionInvocations = new List<SftpNameResponse>(); Action<SftpStatusResponse> statusAction = statusActionInvocations.Add; Action<SftpNameResponse> nameAction = nameActionInvocations.Add; var request = new SftpRealPathRequest( _protocolVersion, _requestId, _path, _encoding, nameAction, statusAction); Assert.AreSame(_encoding, request.Encoding); Assert.AreEqual(_path, request.Path); Assert.AreEqual(_protocolVersion, request.ProtocolVersion); Assert.AreEqual(_requestId, request.RequestId); Assert.AreEqual(SftpMessageTypes.RealPath, request.SftpMessageType); }
/// <summary> /// Performs SSH_FXP_REALPATH request /// </summary> /// <param name="path">The path.</param> /// <param name="nullOnError">if set to <c>true</c> returns null instead of throwing an exception.</param> /// <returns></returns> internal KeyValuePair<string, SftpFileAttributes>[] RequestRealPath(string path, bool nullOnError = false) { SshException exception = null; KeyValuePair<string, SftpFileAttributes>[] result = null; using (var wait = new AutoResetEvent(false)) { var request = new SftpRealPathRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding, (response) => { result = response.Files; wait.Set(); }, (response) => { exception = this.GetSftpException(response); wait.Set(); }); this.SendRequest(request); this.WaitHandle(wait, this._operationTimeout); } if (!nullOnError && exception != null) { throw exception; } return result; }
/// <summary> /// Performs SSH_FXP_REALPATH request /// </summary> /// <param name="path">The path.</param> /// <param name="nullOnError">if set to <c>true</c> returns null instead of throwing an exception.</param> /// <returns></returns> internal IDictionary<string, SftpFileAttributes> RequestRealPath(string path, bool nullOnError = false) { IDictionary<string, SftpFileAttributes> result = null; using (var wait = new AutoResetEvent(false)) { var request = new SftpRealPathRequest(this.NextRequestId, path, (response) => { result = response.Files; wait.Set(); }, (response) => { if (nullOnError) { wait.Set(); } else { this.ThrowSftpException(response); } }); this.SendRequest(request); this.WaitHandle(wait, this._operationTimeout); } return result; }
public void GetBytes() { var statusActionInvocations = new List<SftpStatusResponse>(); var nameActionInvocations = new List<SftpNameResponse>(); Action<SftpStatusResponse> statusAction = statusActionInvocations.Add; Action<SftpNameResponse> nameAction = nameActionInvocations.Add; var request = new SftpRealPathRequest( _protocolVersion, _requestId, _path, _encoding, nameAction, statusAction); var bytes = request.GetBytes(); var expectedBytesLength = 0; #if TUNING expectedBytesLength += 4; // Length #endif expectedBytesLength += 1; // Type expectedBytesLength += 4; // RequestId expectedBytesLength += 4; // Path length expectedBytesLength += _pathBytes.Length; // Path Assert.AreEqual(expectedBytesLength, bytes.Length); var sshDataStream = new SshDataStream(bytes); #if TUNING Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); #endif Assert.AreEqual((byte)SftpMessageTypes.RealPath, sshDataStream.ReadByte()); Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); var actualPath = new byte[_pathBytes.Length]; sshDataStream.Read(actualPath, 0, actualPath.Length); Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); Assert.IsTrue(sshDataStream.IsEndOfData); }