Exemplo n.º 1
0
        public void ButtonClicked(UserViewModel userViewModel, bool isRegister)
        {

            var authRepo = new AuthorisationRepository();

            if (isRegister)
            {
                var user = authRepo.Register(userViewModel);

                if (user != null)
                {
                    ShowMainForm(user);
                }
                else
                {
                    MessageBox.Show("Email already in use. Try login instead");
                }
            }
            else
            {
                var user = authRepo.Login(userViewModel);

                if (user != null)
                {
                    ShowMainForm(user);
                }
                else
                {
                    MessageBox.Show("Login failed. Incorrect credentials");
                }
            }

        }
Exemplo n.º 2
0
Arquivo: DBTest.cs Projeto: Rep2/Life
        public void UserHasEnaughResourcesForResearchFalse()
        {
            Program.SetSessionFactory(true);
            Program.CreateData();

            var authRepo = new AuthorisationRepository();

            var user = authRepo.CreateUser(Create());

            Assert.NotNull(user);

            var resorceRepository = new Repository<Resource>();
            var metal = resorceRepository.Get(new Dictionary<string, string>() { { "Name", "Metal" } }).First();
            var carbon = resorceRepository.Get(new Dictionary<string, string>() { { "Name", "Carbon" } }).First();


            var researchLevel = new ResearchLevel()
            {
                Level = 1,
                ResearchCosts = new List<ResearchCost>(){
                    new ResearchCost(){
                        Resource = metal,
                        Value = 500
                    },
                    new ResearchCost(){
                        Resource = carbon,
                        Value = 200
                    }
                }
            };

            Assert.False(user.UserHasResourcesForResearch(researchLevel));
        }
Exemplo n.º 3
0
Arquivo: DBTest.cs Projeto: Rep2/Life
        public void UserBuildingCreateTrue()
        {
            Program.SetSessionFactory(true);
            Program.CreateData();

            var authRepo = new AuthorisationRepository();

            var user = authRepo.CreateUser(Create());

            Assert.NotNull(user);

            var resorceRepository = new Repository<Resource>();
            var metal = resorceRepository.Get(new Dictionary<string, string>() { { "Name", "Metal" } }).First();
            var carbon = resorceRepository.Get(new Dictionary<string, string>() { { "Name", "Carbon" } }).First();


            var buildingLevel = new BuildingLevel()
            {
                Level = 1,
                BuildingCosts = new List<BuildingCost>(){
                    new BuildingCost(){
                        Resource = metal,
                        Value = 100
                    },
                    new BuildingCost(){
                        Resource = carbon,
                        Value = 200
                    }
                }
            };

            Assert.True(user.UserHasReseourceForBuild(buildingLevel));
        }
Exemplo n.º 4
0
Arquivo: DBTest.cs Projeto: Rep2/Life
        public void CreateUser()
        {
            var authRepo = new AuthorisationRepository();

            var user = authRepo.CreateUser(Create());

            Assert.NotNull(user);
        }
Exemplo n.º 5
0
Arquivo: DBTest.cs Projeto: Rep2/Life
        public void LoginTest()
        {
            // Setups container and session factory
            Program.SetSessionFactory(true);

            var authorizationRepo = new AuthorisationRepository();

            var userViewModel = Create();

            // Creates new user
            Assert.NotNull(authorizationRepo.Register(userViewModel));

            // Logs in the user
            var logedUser = authorizationRepo.Login(userViewModel);

            Assert.NotNull(logedUser);
        }
Exemplo n.º 6
0
Arquivo: DBTest.cs Projeto: Rep2/Life
        public void DoubleRegisterTest()
        {
            // Setups container and session factory
            Program.SetSessionFactory(true);

            var authorizationRepo = new AuthorisationRepository();

            var userViewModel = Create();
            // Creates new user
            Assert.NotNull(authorizationRepo.Register(userViewModel));

            // Tries to register same user twice
            Assert.Null(authorizationRepo.Register(userViewModel));
        }