Revize b2594803
Přidáno uživatelem Jakub Schenk před téměř 3 roky(ů)
Backend/BackendTesting/UserManagementTesting.cs | ||
---|---|---|
72 | 72 |
//creation of new user |
73 | 73 |
var output = US.CreateUser(username, name, surname, password, role); |
74 | 74 |
ctx.SaveChanges(); |
75 |
|
|
76 |
|
|
77 |
if (output == null && ((password == null || password == "") || (surname == null || surname == "") || (name == null || name == "") || (username == null || username == ""))) |
|
78 |
{ |
|
79 |
Assert.IsTrue(true, "Invalid registration creditals were input -> null output was expected"); |
|
80 |
return; |
|
81 |
} |
|
82 |
|
|
75 | 83 |
if (output == null && !shouldBeRigh) |
76 | 84 |
{ |
77 | 85 |
//trying to insert user with taken username resolves with refusing |
... | ... | |
100 | 108 |
return; |
101 | 109 |
} |
102 | 110 |
|
111 |
|
|
103 | 112 |
//retrieving all users checking via username |
104 | 113 |
foreach (var user in ctx.Users) |
105 | 114 |
{ |
... | ... | |
208 | 217 |
var oldPassword = changingUser.Password; |
209 | 218 |
|
210 | 219 |
//change password |
211 |
User? changed = US.ChangePassword(changingUser, newPassword); |
|
212 |
//new password is not empty and database returned null for user (user had to be there) |
|
213 |
if(changed == null && (newPassword!="" || newPassword != null)) |
|
220 |
try |
|
214 | 221 |
{ |
215 |
Assert.Fail("user not returned"); |
|
216 |
return; |
|
217 |
} |
|
218 |
//new password is empty |
|
219 |
if((newPassword == "" || newPassword == null) && changed != null) |
|
220 |
{ |
|
221 |
Assert.Fail("empty password was accepted"); |
|
222 |
return; |
|
222 |
User? changed = US.ChangePassword(changingUser, newPassword); |
|
223 |
//new password is not empty and database returned null for user (user had to be there) |
|
224 |
if (changed == null && (newPassword != "" || newPassword != null)) |
|
225 |
{ |
|
226 |
Assert.Fail("user not returned"); |
|
227 |
return; |
|
228 |
} |
|
229 |
//new password is empty |
|
230 |
if ((newPassword == "" || newPassword == null) && changed != null) |
|
231 |
{ |
|
232 |
Assert.Fail("empty password was accepted"); |
|
233 |
return; |
|
234 |
} |
|
235 |
//no user was returned back after ChangePassword |
|
236 |
if (changed == null) |
|
237 |
{ |
|
238 |
Assert.Fail("user not returned or found or there was mistake in password change"); |
|
239 |
return; |
|
240 |
} |
|
241 |
|
|
242 |
//get new password hash |
|
243 |
var renewedPassword = changed.Password; |
|
244 |
|
|
245 |
Assert.AreNotEqual(oldPassword, renewedPassword, "password was not changed or it was changed on same value"); |
|
223 | 246 |
} |
224 |
//no user was returned back after ChangePassword |
|
225 |
if(changed == null) |
|
247 |
catch(Exception ex) |
|
226 | 248 |
{ |
227 |
Assert.Fail("user not returned or found or there was mistake in password change"); |
|
228 |
return; |
|
249 |
if (newPassword == null || newPassword == "") Assert.IsTrue(true,"Try to change password on empty resulted in exception - expected and wanted outcome"); |
|
229 | 250 |
} |
230 |
|
|
231 |
//get new password hash |
|
232 |
var renewedPassword = changed.Password; |
|
233 |
|
|
234 |
Assert.AreNotEqual(oldPassword, renewedPassword, "password was not changed or it was changed on same value"); |
|
251 |
|
|
235 | 252 |
|
236 | 253 |
} |
237 | 254 |
[TestMethod] |
Také k dispozici: Unified diff
User tests corrections
User tests corrected the way bugs were fixed and application was corrected after 1st test report