-
-
Notifications
You must be signed in to change notification settings - Fork 979
Expand file tree
/
Copy pathAbstractionsTest.cs
More file actions
60 lines (48 loc) · 1.83 KB
/
AbstractionsTest.cs
File metadata and controls
60 lines (48 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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);
}
}
}