-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathEncoderTest.cs
110 lines (93 loc) · 3.13 KB
/
EncoderTest.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) Jan-Niklas Schäfer. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ThinkSharp.Licensing.Test
{
[TestClass]
public class EncoderTest
{
[TestMethod]
public void Test_encoded_length()
{
var encoder = new Encoder();
var input = "12345";
var output = encoder.Encode(input);
Assert.AreEqual(input.Length, output.Length);
}
[TestMethod]
public void Test_multiple_encoding_produces_same_result()
{
var encoder = new Encoder();
var input = "12345";
var output1 = encoder.Encode(input);
var output2 = encoder.Encode(input);
Assert.AreEqual(output1, output2);
}
[TestMethod]
public void Test_custom_length_100()
{
var encoder = new Encoder(100);
var input = "12345";
var output = encoder.Encode(input);
Assert.AreEqual(100, output.Length);
}
[TestMethod]
public void Test_custom_length_2()
{
var encoder = new Encoder(2);
var input = "12345";
var output = encoder.Encode(input);
Assert.AreEqual(2, output.Length);
}
[TestMethod]
public void Test_custom_character_set()
{
var encoder = new Encoder("41", 100);
var input = "12345";
var output = encoder.Encode(input);
Assert.AreEqual(100, output.Length);
foreach (var c in output)
Assert.IsTrue("41".Contains(c.ToString()));
}
[TestMethod]
public void Test_default_character_set()
{
var encoder = new Encoder(100);
var input = "12345";
var output = encoder.Encode(input);
foreach (var c in output)
Assert.IsTrue(Constants.ValidCharacters.Contains(c.ToString()));
}
[TestMethod]
public void Test_negative_encoding_length()
{
var encode = new Encoder(-10);
var result = encode.Encode(new byte[0]);
Assert.AreEqual(string.Empty, result);
}
[TestMethod]
public void Test_custom_char_set()
{
var encode = new Encoder("abc");
var result = encode.Encode("qbc");
Assert.AreEqual(3, result.Length);
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void Test_encode_string_null()
{
var encode = new Encoder(-10);
var result = encode.Encode((string)null);
Assert.AreEqual(string.Empty, result);
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void Test_encode_bytes_null()
{
var encode = new Encoder(-10);
var result = encode.Encode((byte[])null);
Assert.AreEqual(string.Empty, result);
}
}
}