예제 #1
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, VisokiNaponDbContext context)
        {
            app.UseSpaStaticFiles();
            context.Database.Migrate();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");

                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");

                endpoints.MapHub <ChatHub>("/chatHub");
            });

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.Options.StartupTimeout = new TimeSpan(0, 0, 45);
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
예제 #2
0
        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");
            }
        }
예제 #3
0
        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 == "*****@*****.**");
            }
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        public void CRUDTopListTest()
        {
            var options = new DbContextOptionsBuilder <VisokiNaponDbContext>()
                          .UseInMemoryDatabase(databaseName: "FakeDataBase")
                          .Options;
            var context = new VisokiNaponDbContext(options);


            context.PlayersTopList.Add(new TopList()
            {
                Id = 1, Username = "******", MaxAmount = 150000
            });
            context.PlayersTopList.Add(new TopList()
            {
                Id = 2, Username = "******", MaxAmount = 100000
            });
            context.PlayersTopList.Add(new TopList()
            {
                Id = 3, Username = "******", MaxAmount = 75000
            });
            context.PlayersTopList.Add(new TopList()
            {
                Id = 4, Username = "******", MaxAmount = 50000
            });
            context.PlayersTopList.Add(new TopList()
            {
                Id = 5, Username = "******", MaxAmount = 25000
            });
            context.SaveChanges();

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingProfile());
            });
            var mapper = mockMapper.CreateMapper();

            var controller = new PlayersTopListController(context, mapper);

            // MaxAmount of user2 shoud be updated
            var a = new PlayersTopListController.topListObj();

            a.username  = "******";
            a.maxAmount = 120000;
            var    result      = controller.updateTopList(a);
            string requestJson = JsonConvert.SerializeObject(result.Result);

            Assert.True(requestJson.Contains("true") == true);
            var player = context.PlayersTopList.Find(2);

            Assert.True(player.MaxAmount == 120000);

            // User2 is already in top list table, but wont be updated because its sum is less than one in table
            a.username  = "******";
            a.maxAmount = 65000;
            result      = controller.updateTopList(a);
            requestJson = JsonConvert.SerializeObject(result.Result);
            Assert.True(requestJson.Contains("false") == true);
            player = context.PlayersTopList.Find(2);
            Assert.True(player.MaxAmount == 120000);


            // PLAYER WONT BE INSERTED IN TOP LIST TABLE
            var b = new PlayersTopListController.topListObj();

            b.username  = "******";
            b.maxAmount = 15000;
            result      = controller.updateTopList(b);
            requestJson = JsonConvert.SerializeObject(result.Result);
            Assert.True(requestJson.Contains("false") == true);

            // PLAYER WILL BE INSERTED IN TOP LIST TABLE
            b.username  = "******";
            b.maxAmount = 200000;
            result      = controller.updateTopList(b);
            requestJson = JsonConvert.SerializeObject(result.Result);
            Assert.True(requestJson.Contains("true") == true);
        }
예제 #6
0
 /// PlayerHandler Constructor
 public PlayerHandler(VisokiNaponDbContext context)
 {
     this.context = context;
 }
예제 #7
0
        public void AnswerCheckTest()
        {
            var options = new DbContextOptionsBuilder <VisokiNaponDbContext>()
                          .UseInMemoryDatabase(databaseName: "FakeDataBase")
                          .Options;
            var context = new VisokiNaponDbContext(options);


            context.Questions.Add(new Question()
            {
                Id = 1, Text = "1", Answer = "1", Category = 1
            });
            context.Questions.Add(new Question()
            {
                Id = 2, Text = "2", Answer = "1", Category = 1
            });
            context.Questions.Add(new Question()
            {
                Id = 3, Text = "3", Answer = "1", Category = 1
            });
            context.Questions.Add(new Question()
            {
                Id = 4, Text = "4", Answer = "1", Category = 1
            });
            context.Questions.Add(new Question()
            {
                Id = 5, Text = "5", Answer = "1", Category = 1
            });
            context.Questions.Add(new Question()
            {
                Id = 6, Text = "6", Answer = "1", Category = 2
            });
            context.Questions.Add(new Question()
            {
                Id = 7, Text = "7", Answer = "1", Category = 2
            });
            context.Questions.Add(new Question()
            {
                Id = 8, Text = "8", Answer = "1", Category = 2
            });
            context.Questions.Add(new Question()
            {
                Id = 9, Text = "9", Answer = "1", Category = 2
            });
            context.Questions.Add(new Question()
            {
                Id = 10, Text = "10", Answer = "1", Category = 2
            });
            context.Questions.Add(new Question()
            {
                Id = 11, Text = "11", Answer = "1", Category = 3
            });
            context.Questions.Add(new Question()
            {
                Id = 12, Text = "12", Answer = "1", Category = 3
            });
            context.Questions.Add(new Question()
            {
                Id = 13, Text = "13", Answer = "1", Category = 3
            });
            context.Questions.Add(new Question()
            {
                Id = 14, Text = "14", Answer = "1", Category = 3
            });
            context.Questions.Add(new Question()
            {
                Id = 15, Text = "15", Answer = "1", Category = 3
            });
            context.Questions.Add(new Question()
            {
                Id = 16, Text = "16", Answer = "1", Category = 4
            });
            context.Questions.Add(new Question()
            {
                Id = 17, Text = "17", Answer = "1", Category = 1
            });
            context.Questions.Add(new Question()
            {
                Id = 18, Text = "18", Answer = "1", Category = 1
            });
            context.Questions.Add(new Question()
            {
                Id = 19, Text = "19", Answer = "1", Category = 2
            });
            context.Questions.Add(new Question()
            {
                Id = 20, Text = "20", Answer = "1", Category = 2
            });
            context.Questions.Add(new Question()
            {
                Id = 21, Text = "21", Answer = "1", Category = 3
            });
            context.Questions.Add(new Question()
            {
                Id = 22, Text = "22", Answer = "1", Category = 3
            });
            context.SaveChanges();

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingProfile());
            });
            var mapper = mockMapper.CreateMapper();

            var controller = new QuestionsController(context, mapper);

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            // CHECK TRUE ANSWER
            var a = new QuestionsController.obj();

            a.tex = "1";
            a.ans = "1";
            var    result      = controller.TestName(a);
            string requestJson = JsonConvert.SerializeObject(result.Result);

            Assert.True(requestJson.Contains("true") == true);


            // CHECK FALSE ANSWER
            var b = new QuestionsController.obj();

            b.tex = "2";
            b.ans = "22";
            var result1 = controller.TestName(b);

            requestJson = JsonConvert.SerializeObject(result1.Result);
            Assert.True(requestJson.Contains("false") == true);
        }
예제 #8
0
 /// Constructor of QuestionsController
 public QuestionsController(VisokiNaponDbContext context, IMapper mapper)
 {
     this.mapper  = mapper;
     this.context = context;
 }
예제 #9
0
 /// TopList of Players Controller constructor
 public PlayersTopListController(VisokiNaponDbContext context, IMapper mapper)
 {
     this.mapper  = mapper;
     this.context = context;
 }