-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSymbolRepetitionCheckTest.cs
89 lines (77 loc) · 3.01 KB
/
SymbolRepetitionCheckTest.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
using EzPasswordValidator.Checks;
using EzPasswordValidator.Validators;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EzPasswordValidator.Tests
{
[TestClass]
public class SymbolRepetitionCheckTest
{
private PasswordValidator _validator;
private SymbolRepetitionCheck _check;
[TestInitialize]
public void Setup()
{
_validator = new PasswordValidator();
_validator.AddCheck(CheckTypes.SymbolRepetition);
_check = new SymbolRepetitionCheck();
}
[TestMethod]
public void WhenPasswordContainsNoSymbolsThenPasswordIsValid()
{
const string psw = "test";
Assert.IsTrue(_check.Execute(psw));
}
/// <summary> This test assumes that the default repetition length is 4. </summary>
[DataRow("test///")]
[DataRow("///test")]
[DataRow("te///st")]
[DataTestMethod]
public void WhenPasswordContainsSymbolRepetitionOfLengthThreeThenPasswordIsValid(string psw) =>
Assert.IsTrue(_check.Execute(psw));
/// <summary> This test assumes that the default repetition length is 4. </summary>
[DataRow("test$////")]
[DataRow("$////test")]
[DataRow("te////st")]
[DataRow("test#####")]
[DataRow("#####test")]
[DataRow("te#####st")]
[DataTestMethod]
public void WhenPasswordContainsSymbolRepetitionOfLengthFourOrLongerThenPasswordIsInvalid(string psw) =>
Assert.IsFalse(_check.Execute(psw));
/// <summary>
/// This test assumes that the default repetition length is 4.
/// The goal of this test is to simply verify that the test does not
/// wrongly compare symbols.
/// </summary>
[TestMethod]
public void WhenPasswordContainsThreeDifferentSymbolsInSequenceThenPasswordIsValid()
{
const string psw = "test@#$";
Assert.IsTrue(_check.Execute(psw));
}
[TestMethod]
public void SymbolRepetitionDefaultsToFourWhenUsingTheValidator()
{
Assert.IsTrue(_validator.LetterRepetitionLength == 4);
}
[TestMethod]
public void WhenUsingTheValidatorThenPasswordsWithFourSymbolRepetitionsFail()
{
const string pswWithFourRepetitions = "test;;;;";
Assert.IsFalse(_validator.Validate(pswWithFourRepetitions));
}
[TestMethod]
public void WhenUsingTheValidatorThenPasswordsWithLessThanFourSymbolRepetitionsPass()
{
const string pswWithThreeRepetitions = "test;;;";
Assert.IsTrue(_validator.Validate(pswWithThreeRepetitions));
}
[TestMethod]
public void PasswordWithFourRepetitionsAreValidWhenSettingRepetitionLengthToFive()
{
const string pswWithFourRepetitions = "test;;;;";
_validator.SymbolRepetitionLength = 5;
Assert.IsTrue(_validator.Validate(pswWithFourRepetitions));
}
}
}