Exemplo n.º 1
0
        public static User Login()
        {
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
            User Me = new User();

            trials = 3;
            do
            {
                #region Username and Password Entry
                Console.WriteLine("USER LOGIN");
                Console.Write("Username: "******"Password: "******"authentication");
                    continue;
                }
                #endregion

                #region Authentication
                Me = AuthorizedUser;
                bool success = false;
                switch (Me.SessionLive)
                {
                //ALREADY LOGGED IN
                case 1:
                /*
                 * Error("session");
                 * break;
                 */

                //NOT LOGGED IN
                case 0:
                    Console.WriteLine("Login successful\n");
                    Me.SessionLive = 1;
                    pizzaboxRepository.UpdateUser(Me);
                    success = true;
                    break;
                }

                if (success)
                {
                    break;
                }
                #endregion
            } while (trials > 0);

            return(Me);
        }
        }   //!!! Marked for refinement

        public void Logout()
        {
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
            Console.Write("Signing you out ");

            #region Loading Animation
            Loading('.', 3, 2);
            #endregion

            CurrentUser.SessionLive = 0;
            pizzaboxRepository.UpdateUser(CurrentUser);
        }
        public void Check_UpdateUser()
        {
            // ARRANGE
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
            User U1 = new User()
            {
                Username    = "******",
                Pass        = "******",
                FullName    = "That Way",
                SessionLive = 1
            };
            User Expected = U1;

            // ACT
            pizzaboxRepository.UpdateUser(U1);
            User Actual = pizzaboxRepository.GetUserById("Uname23");

            // ASSERT
            Assert.Equal(Expected, Actual);
        }