mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 17:25:51 +00:00
41053cb80f
* Initial plan * Refactor collection assertions to use CollectionAssert.AreEqual Replace Assert.IsTrue(xxx.IsEqualTo(yyy)) and Assert.IsTrue(xxx.SequenceEqual(yyy)) with CollectionAssert.AreEqual(expected, actual) across 55 test files Co-authored-by: Rob-Hague <5132141+Rob-Hague@users.noreply.github.com> * Fix argument order in CollectionAssert.AreEqual and remove unnecessary using directives - Fixed argument order in KeyExchangeDhGroupExchangeReplyTest.cs (expected first, actual second) - Fixed argument order in KeyExchangeInitMessageTest.cs (expected first, actual second) - Removed unnecessary 'using System.Linq' directives from all affected test files Co-authored-by: Rob-Hague <5132141+Rob-Hague@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Rob-Hague <5132141+Rob-Hague@users.noreply.github.com> Co-authored-by: Rob Hague <rob.hague00@gmail.com>
105 lines
3.7 KiB
C#
105 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
using Renci.SshNet.Common;
|
|
using Renci.SshNet.Sftp;
|
|
using Renci.SshNet.Sftp.Requests;
|
|
using Renci.SshNet.Sftp.Responses;
|
|
using Renci.SshNet.Tests.Common;
|
|
|
|
namespace Renci.SshNet.Tests.Classes.Sftp.Requests
|
|
{
|
|
[TestClass]
|
|
public class SftpMkDirRequestTest
|
|
{
|
|
private uint _protocolVersion;
|
|
private uint _requestId;
|
|
private Encoding _encoding;
|
|
private string _path;
|
|
private byte[] _pathBytes;
|
|
private SftpFileAttributes _attributes;
|
|
private byte[] _attributesBytes;
|
|
|
|
[TestInitialize]
|
|
public void Init()
|
|
{
|
|
var random = new Random();
|
|
|
|
_protocolVersion = (uint)random.Next(0, int.MaxValue);
|
|
_requestId = (uint)random.Next(0, int.MaxValue);
|
|
_encoding = Encoding.Unicode;
|
|
_path = random.Next().ToString(CultureInfo.InvariantCulture);
|
|
_pathBytes = _encoding.GetBytes(_path);
|
|
_attributes = SftpFileAttributesBuilder.Empty;
|
|
_attributesBytes = _attributes.GetBytes();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Constructor()
|
|
{
|
|
var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, null);
|
|
|
|
Assert.AreSame(_encoding, request.Encoding);
|
|
Assert.AreEqual(_path, request.Path);
|
|
Assert.AreEqual(_protocolVersion, request.ProtocolVersion);
|
|
Assert.AreEqual(_requestId, request.RequestId);
|
|
Assert.AreEqual(SftpMessageTypes.MkDir, request.SftpMessageType);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Complete_SftpStatusResponse()
|
|
{
|
|
var statusActionInvocations = new List<SftpStatusResponse>();
|
|
|
|
Action<SftpStatusResponse> statusAction = statusActionInvocations.Add;
|
|
var statusResponse = new SftpStatusResponse(_protocolVersion);
|
|
|
|
var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, statusAction);
|
|
|
|
request.Complete(statusResponse);
|
|
|
|
Assert.HasCount(1, statusActionInvocations);
|
|
Assert.AreSame(statusResponse, statusActionInvocations[0]);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetBytes()
|
|
{
|
|
var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, null);
|
|
|
|
var bytes = request.GetBytes();
|
|
|
|
var expectedBytesLength = 0;
|
|
expectedBytesLength += 4; // Length
|
|
expectedBytesLength += 1; // Type
|
|
expectedBytesLength += 4; // RequestId
|
|
expectedBytesLength += 4; // Path length
|
|
expectedBytesLength += _pathBytes.Length; // Path
|
|
expectedBytesLength += _attributesBytes.Length; // Attributes
|
|
|
|
Assert.HasCount(expectedBytesLength, bytes);
|
|
|
|
var sshDataStream = new SshDataStream(bytes);
|
|
|
|
Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32());
|
|
Assert.AreEqual((byte)SftpMessageTypes.MkDir, 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);
|
|
CollectionAssert.AreEqual(_pathBytes, actualPath);
|
|
|
|
var actualAttributes = new byte[_attributesBytes.Length];
|
|
_ = sshDataStream.Read(actualAttributes, 0, actualAttributes.Length);
|
|
CollectionAssert.AreEqual(_attributesBytes, actualAttributes);
|
|
|
|
Assert.IsTrue(sshDataStream.IsEndOfData);
|
|
}
|
|
}
|
|
}
|