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>
61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Security.Cryptography;
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
using Renci.SshNet.Abstractions;
|
|
|
|
namespace Renci.SshNet.Tests.Classes
|
|
{
|
|
[TestClass]
|
|
public class AbstractionsTest
|
|
{
|
|
[TestMethod]
|
|
public void CryptoAbstraction_GenerateRandom_ShouldPerformNoOpWhenDataIsZeroLength()
|
|
{
|
|
Assert.IsEmpty(RandomNumberGenerator.GetBytes(0));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CryptoAbstraction_GenerateRandom_ShouldGenerateRandomSequenceOfValues()
|
|
{
|
|
var dataLength = new Random().Next(1, 100);
|
|
|
|
var dataA = RandomNumberGenerator.GetBytes(dataLength);
|
|
var dataB = RandomNumberGenerator.GetBytes(dataLength);
|
|
|
|
Assert.HasCount(dataLength, dataA);
|
|
Assert.HasCount(dataLength, dataB);
|
|
|
|
CollectionAssert.AreNotEqual(dataA, dataB);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ThreadAbstraction_ExecuteThread_ShouldThrowArgumentNullExceptionWhenActionIsNull()
|
|
{
|
|
var ex = Assert.ThrowsExactly<ArgumentNullException>(() => ThreadAbstraction.ExecuteThread(null));
|
|
|
|
Assert.IsNull(ex.InnerException);
|
|
Assert.AreEqual("action", ex.ParamName);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ThreadAbstraction_ExecuteThread_ShouldExecuteActionOnSeparateThread()
|
|
{
|
|
int threadId = 0;
|
|
using var waitHandle = new ManualResetEventSlim();
|
|
|
|
ThreadAbstraction.ExecuteThread(() =>
|
|
{
|
|
threadId = Environment.CurrentManagedThreadId;
|
|
waitHandle.Set();
|
|
});
|
|
|
|
Assert.IsTrue(waitHandle.Wait(1000));
|
|
Assert.AreNotEqual(0, threadId);
|
|
Assert.AreNotEqual(Environment.CurrentManagedThreadId, threadId);
|
|
}
|
|
}
|
|
}
|