-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathTestUtilities.cs
72 lines (58 loc) · 1.54 KB
/
TestUtilities.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;
namespace EncryptionTests
{
[TestClass]
internal static class TestUtilities
{
private static Random rand;
private static Random Rand
{
get
{
if (rand == null)
{
rand = new Random();
}
return rand;
}
}
public static string GeneratePassPhrase()
{
return GenerateRandomString(Rand.Next(8, (256 + 1)));
}
public static byte[] GeneratePayload()
{
return GenerateRandomBytes(Rand.Next(16, (512 + 1)));
}
private static string GenerateRandomString(int length)
{
byte[] bytes = new byte[length];
for (int i = 0; i < bytes.Length; i++)
{
int min;
int max;
if (Rand.Next(0, 2) > 0)
{
min = 65;
max = 90;
}
else
{
min = 97;
max = 122;
}
int num = Rand.Next(min, max);
bytes[i] = (byte)num;
}
return Encoding.UTF8.GetString(bytes);
}
private static byte[] GenerateRandomBytes(int length)
{
byte[] bytes = new byte[length];
Rand.NextBytes(bytes);
return bytes;
}
}
}