public void ConfirmPlayerTest() { var options = new DbContextOptionsBuilder <VisokiNaponDbContext>() .UseInMemoryDatabase(databaseName: "FakeDataBase") .Options; using (var context = new VisokiNaponDbContext(options)) { var service = new PlayerHandler(context); // UNEXPECTED NULL Assert.False(service.Confirm(null, "1234").Result); Assert.False(service.Confirm("username", null).Result); // UNREGISTRATED USERNAME Assert.False(service.Confirm("username", "1234").Result); /* SENDING WRONG CONFIRMATION EMAIL * ############################### NOTE ################################## * CONFIRMING EARLIER REGISTRATED PLAYER WITH EMAIL [email protected], * THAT MAIL IS NOT VALID, AND SENDGRID WON'T SEND CONFIRMATION EMAIL, * BUT FOR THIS TEST WE ASSUME THAT EMAIL WAS SENT * ######################################################################*/ var q = service.Create("*****@*****.**", "maraM", "Mara", "Maric", "Mara1234", "Mara1234").Result; var player = context.Players.Find("maraM"); Assert.False(service.Confirm(player.UsernameId, "0").Result); player = context.Players.Find("maraM"); Assert.True(player == null); // CHECK COMPLETELY VALID CONFIRMATION /* email: "*****@*****.**", username : "******" */ Assert.True(service.Create("*****@*****.**", "pjero", "Pera", "Petrovic", "Pera1234", "Pera1234").Result); player = context.Players.Find("pjero"); Assert.True(player.Verified != null); Assert.True(service.Confirm(player.UsernameId, player.Verified).Result); player = context.Players.Find("pjero"); Assert.True(player.Verified == "1"); } }
public void AuthenticatePlayerTest() { var options = new DbContextOptionsBuilder <VisokiNaponDbContext>() .UseInMemoryDatabase(databaseName: "FakeDataBase") .Options; using (var context = new VisokiNaponDbContext(options)) { var service = new PlayerHandler(context); // UNEXPECTED NULL Assert.False(service.Authenticate(null, "Password123").Result); Assert.False(service.Authenticate("username", null).Result); // UNREGISTRATED USERNAME Assert.False(service.Confirm("username", "Password1234").Result); context.Players.Add(new Player() { Email = "*****@*****.**", Name = "Jovana", Surname = "Jovanovic", UsernameId = "jovana", PasswordHash = null, PasswordSalt = null, Verified = "1234", DateAndTime = new DateTime(2020, 2, 19) }); context.Players.Add(new Player() { Email = "*****@*****.**", Name = "Ana", Surname = "Anic", UsernameId = "anica", PasswordHash = null, PasswordSalt = null, Verified = "1234", DateAndTime = DateTime.Now }); context.SaveChanges(); // UNCONFIRMED PLAYER Email : "*****@*****.**", username : "******" var player = context.Players.Find("jovana"); Assert.False(service.Authenticate(player.UsernameId, "Password").Result); player = context.Players.Find("jovana"); Assert.True(player == null); // UNCONFIRMED PLAYER, BUT YET HAVE TIME TO CONFIM IT Email : "*****@*****.**", username : "******" player = context.Players.Find("anica"); Assert.False(service.Authenticate(player.UsernameId, "Password").Result); // CHECK COMPLETELY VALID CONFIRMATION //email: "*****@*****.**", username : "******" password : "******" var q = service.Create("*****@*****.**", "milos", "Milos", "Milosevic", "Milos1234", "Milos1234").Result; player = context.Players.Find("milos"); player.Verified = "1"; context.Players.Update(player); player = context.Players.Find("milos"); Assert.True(player.PasswordHash != null && player.PasswordSalt != null); Assert.True(player.Verified == "1"); Assert.True(service.Authenticate(player.UsernameId, "Milos1234").Result); //CHECK CONFIRMED PLAYER WITH WRONG PASSWORD SUBMITTED Assert.False(service.Authenticate(player.UsernameId, "Milos4321").Result); } }