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 CreatePlayerTest()
        {
            var options = new DbContextOptionsBuilder <VisokiNaponDbContext>()
                          .UseInMemoryDatabase(databaseName: "FakeDataBase")
                          .Options;

            using (var context = new VisokiNaponDbContext(options))
            {
                context.Players.Add(new Player()
                {
                    Email        = "*****@*****.**",
                    Name         = "Mika",
                    Surname      = "Mikic",
                    UsernameId   = "mikica",
                    PasswordHash = null,
                    PasswordSalt = null,
                    Verified     = "1234",
                    DateAndTime  = new DateTime(2020, 2, 19)
                });
                context.Players.Add(new Player()
                {
                    Email        = "*****@*****.**",
                    Name         = "Zika",
                    Surname      = "Zikic",
                    UsernameId   = "zikica",
                    PasswordHash = null,
                    PasswordSalt = null,
                    Verified     = "1234",
                    DateAndTime  = new DateTime(2020, 2, 19)
                });
                context.SaveChanges();

                var service = new PlayerHandler(context);

                //REGISTER UNCONFIRMED PLAYER 3 MINUTES AFTHER HIS REGISTRATION TRAIL
                Assert.True(service.Create("*****@*****.**", "mikica123", "Mika", "Mikic", "Mika1234", "Mika1234").Result);
                Assert.True(service.Create("*****@*****.**", "zikica", "Mika", "Zikic", "Mika1234", "Mika1234").Result);


                // EMAIL ALREADY TAKEN
                Assert.False(service.Create("*****@*****.**", "ZMiJa", "Mika", "Zikic", "Sifra123", "Sifra123").Result);

                // USERNAME ALREADY TAKEN
                Assert.False(service.Create("*****@*****.**", "zikica", "Zikica", "Gojkovic", "Sifra123", "Sifra123").Result);

                // NOT VALID EMAIL
                Assert.False(service.Create("gorge", "george", "George", "Brant", "Sifra123", "Sifra123").Result);

                // NOT VALID USERNAME
                Assert.False(service.Create("*****@*****.**", "gb", "George", "Brant", "Sifra123", "Sifra123").Result);

                // NOT VALID PASSWORD
                Assert.False(service.Create("gorge@hotmailcom", "george", "George", "Brant", "sifra123", "sifra123").Result);

                // PASSWORDS NOT MATCHING
                Assert.False(service.Create("gorge@hotmailcom", "george", "George", "Brant", "Sifra123", "Sifra143").Result);

                // UNEXPECTED NULL
                Assert.False(service.Create(null, "george", "George", "Brant", "Sifra123", "Sifra143").Result);
                Assert.False(service.Create("gorge@hotmailcom", null, "George", "Brant", "Sifra123", "Sifra143").Result);
                Assert.False(service.Create("gorge@hotmailcom", "george", "George", "Brant", null, "Sifra143").Result);
                Assert.False(service.Create("gorge@hotmailcom", "george", "George", "Brant", "Sifra123", null).Result);


                // EVERYTHING IS OK
                Assert.True(service.Create("*****@*****.**", "jovica", "Jova", "Jovic", "Jova1234", "Jova1234").Result);
                var player = context.Players.Find("jovica");
                Assert.True(player.Email == "*****@*****.**");
            }
        }
        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);
            }
        }