Files
Copilot 41053cb80f Replace Assert.IsTrue with CollectionAssert.AreEqual for collection comparisons (#1730)
* 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>
2026-06-26 17:44:36 +02:00

125 lines
4.5 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 SftpSymLinkRequestTest : TestBase
{
private uint _protocolVersion;
private uint _requestId;
private Encoding _encoding;
private string _newLinkPath;
private byte[] _newLinkPathBytes;
private string _existingPath;
private byte[] _existingPathBytes;
protected override void OnInit()
{
var random = new Random();
_protocolVersion = (uint)random.Next(0, int.MaxValue);
_requestId = (uint)random.Next(0, int.MaxValue);
_encoding = Encoding.Unicode;
_newLinkPath = random.Next().ToString(CultureInfo.InvariantCulture);
_newLinkPathBytes = _encoding.GetBytes(_newLinkPath);
_existingPath = random.Next().ToString(CultureInfo.InvariantCulture);
_existingPathBytes = _encoding.GetBytes(_existingPath);
}
[TestMethod]
public void Constructor()
{
var request = new SftpSymLinkRequest(
_protocolVersion,
_requestId,
_newLinkPath,
_existingPath,
_encoding,
null);
Assert.AreSame(_encoding, request.Encoding);
Assert.AreEqual(_existingPath, request.ExistingPath);
Assert.AreEqual(_newLinkPath, request.NewLinkPath);
Assert.AreEqual(_protocolVersion, request.ProtocolVersion);
Assert.AreEqual(_requestId, request.RequestId);
Assert.AreEqual(SftpMessageTypes.SymLink, 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 SftpSymLinkRequest(
_protocolVersion,
_requestId,
_newLinkPath,
_existingPath,
_encoding,
statusAction);
request.Complete(statusResponse);
Assert.HasCount(1, statusActionInvocations);
Assert.AreSame(statusResponse, statusActionInvocations[0]);
}
[TestMethod]
public void GetBytes()
{
var request = new SftpSymLinkRequest(
_protocolVersion,
_requestId,
_newLinkPath,
_existingPath,
_encoding,
null);
var bytes = request.GetBytes();
var expectedBytesLength = 0;
expectedBytesLength += 4; // Length
expectedBytesLength += 1; // Type
expectedBytesLength += 4; // RequestId
expectedBytesLength += 4; // NewLinkPath length
expectedBytesLength += _newLinkPathBytes.Length; // NewLinkPath
expectedBytesLength += 4; // ExistingPath length
expectedBytesLength += _existingPathBytes.Length; // ExistingPath
Assert.HasCount(expectedBytesLength, bytes);
var sshDataStream = new SshDataStream(bytes);
Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32());
Assert.AreEqual((byte)SftpMessageTypes.SymLink, sshDataStream.ReadByte());
Assert.AreEqual(_requestId, sshDataStream.ReadUInt32());
Assert.AreEqual((uint)_newLinkPathBytes.Length, sshDataStream.ReadUInt32());
var actualNewLinkPath = new byte[_newLinkPathBytes.Length];
_ = sshDataStream.Read(actualNewLinkPath, 0, actualNewLinkPath.Length);
CollectionAssert.AreEqual(_newLinkPathBytes, actualNewLinkPath);
Assert.AreEqual((uint)_existingPathBytes.Length, sshDataStream.ReadUInt32());
var actualExistingPath = new byte[_existingPathBytes.Length];
_ = sshDataStream.Read(actualExistingPath, 0, actualExistingPath.Length);
CollectionAssert.AreEqual(_existingPathBytes, actualExistingPath);
Assert.IsTrue(sshDataStream.IsEndOfData);
}
}
}