-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDigitRepetitionCheckTest.cs
99 lines (86 loc) · 3.35 KB
/
DigitRepetitionCheckTest.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
using EzPasswordValidator.Checks;
using EzPasswordValidator.Validators;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EzPasswordValidator.Tests
{
[TestClass]
public class DigitRepetitionCheckTest
{
private PasswordValidator _validator;
private DigitRepetitionCheck _check;
[TestInitialize]
public void Setup()
{
_validator = new PasswordValidator();
_validator.AddCheck(CheckTypes.DigitRepetition);
_check = new DigitRepetitionCheck();
}
/// <summary>
/// Whens the password contains no numbers then password is valid
/// as no number repetition can occur if there are no numbers.
/// </summary>
[TestMethod]
public void WhenPasswordContainsNoNumbersThenPasswordIsValid()
{
const string psw = "test";
Assert.IsTrue(_check.Execute(psw));
}
/// <summary> This test assumes that the default repetition length is 4. </summary>
[DataRow("test222")]
[DataRow("te222st")]
[DataRow("2224test")]
[DataTestMethod]
public void WhenPasswordContainsTheSameDigitThreeTimesInARowThenPasswordIsValid(string psw) =>
Assert.IsTrue(_check.Execute(psw));
/// <summary> This test assumes that the default repetition length is 4. </summary>
[DataRow("test2222")]
[DataRow("te2222st")]
[DataRow("2222test")]
[DataRow("372222test")]
[DataTestMethod]
public void WhenPasswordContainsTheSameDigitFourTimesInARowThenPasswordIsInvalid(string psw) =>
Assert.IsFalse(_check.Execute(psw));
[DataRow("test33333")]
[DataRow("te11111st")]
[DataRow("6666666test")]
[DataTestMethod]
public void WhenPasswordContainsRepetitionOfFiveOrLongerWhenSetToFiveThenPasswordIsInvalid(string psw)
{
_check.RepetitionLength = 5;
Assert.IsFalse(_check.Execute(psw));
}
[DataRow("test5555")]
[DataRow("te5st")]
[DataRow("5555test")]
[DataTestMethod]
public void WhenPasswordContainsRepetitionOfLessThanFiveDigitsWhenSetToFiveThenPasswordIsValid(string psw)
{
_check.RepetitionLength = 5;
Assert.IsTrue(_check.Execute(psw));
}
[TestMethod]
public void PasswordWithFourRepetitionsAreValidWhenSettingRepetitionLengthToFive()
{
const string pswWithFourRepetitions = "test4444";
_validator.DigitRepetitionLength = 5;
Assert.IsTrue(_validator.Validate(pswWithFourRepetitions));
}
[TestMethod]
public void DigitRepetitionDefaultsToFourWhenUsingTheValidator()
{
Assert.IsTrue(_validator.DigitRepetitionLength == 4);
}
[TestMethod]
public void WhenUsingTheValidatorThenPasswordsWithFourDigitRepetitionsFail()
{
const string pswWithFourRepetitions = "test4444";
Assert.IsFalse(_validator.Validate(pswWithFourRepetitions));
}
[TestMethod]
public void WhenUsingTheDefualtValidatorThenPasswordsWithLessThanFourDigitRepetitionsPass()
{
const string pswWithThreeRepetitions = "test444";
Assert.IsTrue(_validator.Validate(pswWithThreeRepetitions));
}
}
}