301 |
301 |
}
|
302 |
302 |
}
|
303 |
303 |
[TestMethod]
|
304 |
|
[DataRow(10)]//expected number of users in database
|
305 |
|
public void GetUsers_Test(int expected)
|
|
304 |
public void GetUsers_Test()
|
306 |
305 |
{
|
307 |
306 |
var userList = US.GetUsers();
|
308 |
|
Assert.AreEqual(expected, userList.Users.Count, "I counted poorly probably");
|
|
307 |
Assert.AreEqual(ctx.Users.Count(), userList.Users.Count, "I dont know if this is even test");
|
|
308 |
}
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
[TestMethod]
|
|
313 |
//correct
|
|
314 |
[DataRow("aaa", "aaa", ERole.ANNOTATOR)]//anotator
|
|
315 |
[DataRow("fff", "fff", ERole.ANNOTATOR)]//anotator
|
|
316 |
[DataRow("iii", "iii", ERole.ADMINISTRATOR)]//admin
|
|
317 |
public void AuthService_Login_Correct(string username, string password, ERole role)
|
|
318 |
{
|
|
319 |
var jwt = TestingJwtUtils.GetJwtUtils();
|
|
320 |
var AS = new AuthService(US, jwt);
|
|
321 |
// var AS = new AuthServiceEF(this.ctx, TestingLogger.GetLogger(), TestingMapper.GetMapper());
|
|
322 |
var loginResults = AS.Login(username, password);
|
|
323 |
Assert.IsNotNull(loginResults);
|
|
324 |
Assert.IsTrue(loginResults.Ok);
|
|
325 |
Assert.IsNotNull(loginResults.Token);
|
|
326 |
DateTime exp = loginResults.Expiration;
|
|
327 |
var now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
|
|
328 |
Assert.IsTrue(exp.CompareTo(now) > 0);//if compare is >0 -> exp is in the future
|
|
329 |
Assert.AreEqual(role, loginResults.Role);
|
|
330 |
}
|
|
331 |
|
|
332 |
//incorrect
|
|
333 |
[TestMethod]
|
|
334 |
[DataRow("aaa", "bbb")]//changedPassword?
|
|
335 |
[DataRow("fff", "fgh")]//anotator
|
|
336 |
[DataRow("iii", "123")]//admin
|
|
337 |
public void AuthService_Login_Incorrect(string username, string password)
|
|
338 |
{
|
|
339 |
var jwt = TestingJwtUtils.GetJwtUtils();
|
|
340 |
var AS = new AuthService(US, jwt);
|
|
341 |
// var AS = new AuthServiceEF(this.ctx, TestingLogger.GetLogger(), TestingMapper.GetMapper());
|
|
342 |
var loginResults = AS.Login(username, password);
|
|
343 |
if (loginResults != null)
|
|
344 |
{
|
|
345 |
Assert.IsFalse(loginResults.Ok);
|
|
346 |
Assert.IsNull(loginResults.Token);
|
|
347 |
}
|
|
348 |
else
|
|
349 |
{
|
|
350 |
Assert.IsNull(loginResults);
|
|
351 |
}
|
309 |
352 |
}
|
310 |
353 |
}
|
311 |
354 |
}
|
backend login
login on backend tested (JwtUtils in Utils inicialization)