-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLengthCheckTest.cs
87 lines (67 loc) · 2.51 KB
/
LengthCheckTest.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
using EzPasswordValidator.Checks;
using EzPasswordValidator.Validators;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EzPasswordValidator.Tests
{
[TestClass]
public class LengthCheckTest
{
private const int RequiredLen = 8;
private LengthCheck _check;
[TestInitialize]
public void Setup() => _check = new LengthCheck(RequiredLen);
[TestMethod]
public void WhenPasswordIsTooShortThenPasswordIsNotValid()
{
const string invalidPsw = "1234567";
Assert.IsFalse(_check.Execute(invalidPsw));
}
[TestMethod]
public void WhenPasswordIsLongEnoughOnlyDueToTrailingSpaceThenPasswordIsNotValid()
{
const string invalidPsw = "123456 ";
Assert.IsFalse(_check.Execute(invalidPsw));
}
[TestMethod]
public void WhenPasswordIsLongEnoughOnlyDueToLeadingSpaceThenPasswordIsNotValid()
{
const string invalidPsw = " 123456";
Assert.IsFalse(_check.Execute(invalidPsw));
}
[TestMethod]
public void WhenPasswordIsNullThenPasswordIsNotValid()
{
const string invalidPsw = null;
Assert.IsFalse(_check.Execute(invalidPsw));
}
[TestMethod]
public void WhenPasswordIsEmptyThenPasswordIsNotValid()
{
const string invalidPsw = " ";
Assert.IsFalse(_check.Execute(invalidPsw));
}
[TestMethod]
public void WhenPasswordIsExactlyRequiredLengthThenPasswordIsValid()
{
const string validPsw = "12345678";
Assert.IsTrue(_check.Execute(validPsw));
}
[TestMethod]
public void WhenPasswordIsAboveRequiredLengthThenPasswordIsValid()
{
const string validPsw = "123456789123456789";
Assert.IsTrue(_check.Execute(validPsw));
}
[TestMethod]
public void WhenUsingBasicCheckDefaultLengthsShouldApply()
{
const string validPsw = "abc123XYZ/";
const string invalidPsw = "Ab123/"; // Fits all criteria except minimum length.
var validator = new PasswordValidator(CheckTypes.Basic);
Assert.AreEqual(LengthCheck.DefaultMinLength, validator.MinLength);
Assert.AreEqual(LengthCheck.DefaultMaxLength, validator.MaxLength);
Assert.IsTrue(validator.Validate(validPsw));
Assert.IsFalse(validator.Validate(invalidPsw));
}
}
}