Repository navigation
Expand file tree
/
Copy pathQuick.Core.Identity.Tests.pas
More file actions
225 lines (201 loc) · 5.91 KB
/
Copy pathQuick.Core.Identity.Tests.pas
File metadata and controls
225 lines (201 loc) · 5.91 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
unit Quick.Core.Identity.Tests;
{ Tests: T-ID-01..12
T-ID-01 TClaimsIdentityOptions RoleClaimType default is empty
T-ID-02 TClaimsIdentityOptions RoleClaimType is writable
T-ID-03 TClaimsIdentityOptions UserNameClaimType is writable
T-ID-04 TClaimsIdentityOptions UserIdClaimType is writable
T-ID-05 TLockOutOptions AllowedForNewUsers default is False
T-ID-06 TLockOutOptions MaxFailedAccessAttempts default is 0
T-ID-07 TLockOutOptions MaxFailedAccessAttempts is writable
T-ID-08 TPasswordOptions RequireDigit default is False
T-ID-09 TPasswordOptions RequiredLength default is 0
T-ID-10 TPasswordOptions RequiredLength is writable
T-ID-11 TPasswordOptions RequireUppercase is writable
T-ID-12 TPasswordOptions RequireLowercase is writable
}
interface
uses
DUnitX.TestFramework,
System.SysUtils,
Quick.Core.Identity;
type
[TestFixture]
TIdentityTests = class
public
[Test]
procedure T_ID_01_ClaimsIdentityOptions_RoleClaimType_DefaultEmpty;
[Test]
procedure T_ID_02_ClaimsIdentityOptions_RoleClaimType_Writable;
[Test]
procedure T_ID_03_ClaimsIdentityOptions_UserNameClaimType_Writable;
[Test]
procedure T_ID_04_ClaimsIdentityOptions_UserIdClaimType_Writable;
[Test]
procedure T_ID_05_LockOutOptions_AllowedForNewUsers_DefaultFalse;
[Test]
procedure T_ID_06_LockOutOptions_MaxFailed_DefaultZero;
[Test]
procedure T_ID_07_LockOutOptions_MaxFailed_Writable;
[Test]
procedure T_ID_08_PasswordOptions_RequireDigit_DefaultFalse;
[Test]
procedure T_ID_09_PasswordOptions_RequiredLength_DefaultZero;
[Test]
procedure T_ID_10_PasswordOptions_RequiredLength_Writable;
[Test]
procedure T_ID_11_PasswordOptions_RequireUppercase_Writable;
[Test]
procedure T_ID_12_PasswordOptions_RequireLowercase_Writable;
end;
implementation
{ TIdentityTests }
// ─── TClaimsIdentityOptions ───────────────────────────────────────────────────
procedure TIdentityTests.T_ID_01_ClaimsIdentityOptions_RoleClaimType_DefaultEmpty;
var
opts : TClaimsIdentityOptions;
begin
opts := TClaimsIdentityOptions.Create;
try
Assert.AreEqual('', opts.RoleClaimType,
'RoleClaimType should be empty string by default');
finally
opts.Free;
end;
end;
procedure TIdentityTests.T_ID_02_ClaimsIdentityOptions_RoleClaimType_Writable;
var
opts : TClaimsIdentityOptions;
begin
opts := TClaimsIdentityOptions.Create;
try
opts.RoleClaimType := 'http://schemas.microsoft.com/ws/2008/06/identity/claims/role';
Assert.IsNotEmpty(opts.RoleClaimType);
finally
opts.Free;
end;
end;
procedure TIdentityTests.T_ID_03_ClaimsIdentityOptions_UserNameClaimType_Writable;
var
opts : TClaimsIdentityOptions;
begin
opts := TClaimsIdentityOptions.Create;
try
opts.UserNameClaimType := 'name';
Assert.AreEqual('name', opts.UserNameClaimType);
finally
opts.Free;
end;
end;
procedure TIdentityTests.T_ID_04_ClaimsIdentityOptions_UserIdClaimType_Writable;
var
opts : TClaimsIdentityOptions;
begin
opts := TClaimsIdentityOptions.Create;
try
opts.UserIdClaimType := 'sub';
Assert.AreEqual('sub', opts.UserIdClaimType);
finally
opts.Free;
end;
end;
// ─── TLockOutOptions ──────────────────────────────────────────────────────────
procedure TIdentityTests.T_ID_05_LockOutOptions_AllowedForNewUsers_DefaultFalse;
var
opts : TLockOutOptions;
begin
opts := TLockOutOptions.Create;
try
Assert.IsFalse(opts.AllowedForNewUsers,
'AllowedForNewUsers should default to False');
finally
opts.Free;
end;
end;
procedure TIdentityTests.T_ID_06_LockOutOptions_MaxFailed_DefaultZero;
var
opts : TLockOutOptions;
begin
opts := TLockOutOptions.Create;
try
Assert.AreEqual(0, opts.MaxFailedAccessAttempts,
'MaxFailedAccessAttempts should default to 0');
finally
opts.Free;
end;
end;
procedure TIdentityTests.T_ID_07_LockOutOptions_MaxFailed_Writable;
var
opts : TLockOutOptions;
begin
opts := TLockOutOptions.Create;
try
opts.MaxFailedAccessAttempts := 5;
Assert.AreEqual(5, opts.MaxFailedAccessAttempts);
finally
opts.Free;
end;
end;
// ─── TPasswordOptions ─────────────────────────────────────────────────────────
procedure TIdentityTests.T_ID_08_PasswordOptions_RequireDigit_DefaultFalse;
var
opts : TPasswordOptions;
begin
opts := TPasswordOptions.Create;
try
Assert.IsFalse(opts.RequireDigit,
'RequireDigit should default to False');
finally
opts.Free;
end;
end;
procedure TIdentityTests.T_ID_09_PasswordOptions_RequiredLength_DefaultZero;
var
opts : TPasswordOptions;
begin
opts := TPasswordOptions.Create;
try
Assert.AreEqual(0, opts.RequiredLength,
'RequiredLength should default to 0');
finally
opts.Free;
end;
end;
procedure TIdentityTests.T_ID_10_PasswordOptions_RequiredLength_Writable;
var
opts : TPasswordOptions;
begin
opts := TPasswordOptions.Create;
try
opts.RequiredLength := 8;
Assert.AreEqual(8, opts.RequiredLength);
finally
opts.Free;
end;
end;
procedure TIdentityTests.T_ID_11_PasswordOptions_RequireUppercase_Writable;
var
opts : TPasswordOptions;
begin
opts := TPasswordOptions.Create;
try
opts.RequireUppercase := True;
Assert.IsTrue(opts.RequireUppercase);
finally
opts.Free;
end;
end;
procedure TIdentityTests.T_ID_12_PasswordOptions_RequireLowercase_Writable;
var
opts : TPasswordOptions;
begin
opts := TPasswordOptions.Create;
try
opts.RequireLowercase := True;
Assert.IsTrue(opts.RequireLowercase);
finally
opts.Free;
end;
end;
initialization
TDUnitX.RegisterTestFixture(TIdentityTests);
end.