Exemplo n.º 1
0
        public void LogInUserAccount_ReturnTrue()
        {
            // arrange
            string email    = context.Object.UsersList[0].Email;
            string password = context.Object.UsersList[0].Password;

            // act
            bool actual = guest.LogIn(email, password);

            // assert
            Assert.AreEqual(true, actual);
        }
        /// <summary>
        /// Choose menu 'LogIn'
        /// </summary>
        public static void ChooseLogIn()
        {
            string name, password;

            GuestLogic = new GuestLogic();

            while (true)
            {
                Console.Clear();
                Print.PrintHeader("LOG IN", ConsoleColor.DarkYellow);

                name     = Print.ReadInput("\nEnter user email: ");
                password = Print.ReadInput("\nEnter password: "******"\nThere is no such user, check name or password!");
                    string input = Print.ReadInput("\n[1] Try again\nor enter any other key to return");
                    if (input != "1")
                    {
                        return;
                    }
                }
                else
                {
                    break;
                }
            }

            Console.Clear();
            if (UserLogic.GetAccountType().Equals("USER"))
            {
                UserActions.UserMode();
            }
            else
            {
                UserActions.AdminMode();
            }

            while (true)
            {
                Print.PrintHeader($"{UserLogic.GetAccountType()}: {UserLogic.GetAccountName()}", ConsoleColor.Green);

                UserActions.GetActions();

                string input = Console.ReadLine();
                Console.Clear();
                Print.PrintHeader($"{UserLogic.GetAccountType()}: {UserLogic.GetAccountName()}", ConsoleColor.Green);
                if (input.ToLower() == "q")
                {
                    UserLogic.LogOut();
                    break;
                }

                UserActions.ChooseAction(input);
            }
        }
Exemplo n.º 3
0
        public void Setup()
        {
            context = new Mock <IDataContext>();

            context.Setup(x => x.UsersList).Returns(
                new List <User>()
            {
                new User()
                {
                    Id           = 1,
                    Name         = "user1",
                    Email        = "*****@*****.**",
                    Password     = "******",
                    ShoppingCart = new ShoppingCart(),
                    OrderList    = new List <Order>()
                }
            });

            context.Setup(x => x.ProductsList).Returns(new List <Product>()
            {
                new Product()
                {
                    Category = Category.Phones,
                    Name     = "Samsung Galaxy A51",
                    Price    = 300,
                    Id       = 1
                },
                new Product()
                {
                    Category = Category.Phones,
                    Name     = "Xiaomi Redmi Note 9 Pro",
                    Price    = 290,
                    Id       = 2
                },
                new Product()
                {
                    Category = Category.Notebooks,
                    Name     = "Lenovo IdeaPad 330",
                    Price    = 350,
                    Id       = 3
                }
            });

            guest = new GuestLogic(context.Object);
            user  = new UserLogic(context.Object);
            guest.LogIn(context.Object.UsersList[0].Email, context.Object.UsersList[0].Password);
        }
        /// <summary>
        /// Choose menu 'Register'
        /// </summary>
        public static void Register()
        {
            GuestLogic = new GuestLogic();
            string name, email, password, input;

            while (true)
            {
                Console.Clear();
                Print.PrintHeader("REGISTER", ConsoleColor.DarkYellow);

                name = Print.ReadInput("\nEnter your name (at least 3 characters): ");
                if (!ParseInput.IsCorrectName(name))
                {
                    Console.WriteLine("\nIncorrect name!");
                    input = Print.ReadInput("\n[1] Try again\nor enter any other key to return");
                    if (input != "1")
                    {
                        return;
                    }
                    else
                    {
                        continue;
                    }
                }

                email = Print.ReadInput("\nEnter user email (*****@***): ");
                if (!ParseInput.IsCorrectEmail(email))
                {
                    Console.WriteLine("\nIncorrect email!");
                    input = Print.ReadInput("\n[1] Try again\nor enter any other key to return");
                    if (input != "1")
                    {
                        return;
                    }
                    else
                    {
                        continue;
                    }
                }

                password = Print.ReadInput("\nEnter password (at least 3 characters): ");
                if (!ParseInput.IsCorrectPassword(password))
                {
                    Console.WriteLine("\nIncorrect password!");
                    input = Print.ReadInput("\n[1] Try again\nor enter any other key to return");
                    if (input != "1")
                    {
                        return;
                    }
                    else
                    {
                        continue;
                    }
                }
                if (!GuestLogic.Register(name, email, password))
                {
                    Console.WriteLine("\nUser with this email already exists!");
                    input = Print.ReadInput("\n[1] Try again\nor enter any other key to return");
                    if (input != "1")
                    {
                        return;
                    }
                }
                else
                {
                    break;
                }
            }

            GuestLogic.LogIn(email, password);

            Console.Clear();
            if (UserLogic.GetAccountType().Equals("USER"))
            {
                UserActions.UserMode();
            }
            else
            {
                UserActions.AdminMode();
            }

            while (true)
            {
                Print.PrintHeader($"{UserLogic.GetAccountType()}: {UserLogic.GetAccountName()}", ConsoleColor.Green);

                UserActions.GetActions();

                input = Console.ReadLine();
                Console.Clear();
                Print.PrintHeader($"{UserLogic.GetAccountType()}: {UserLogic.GetAccountName()}", ConsoleColor.Green);
                if (input.ToLower() == "q")
                {
                    UserLogic.LogOut();
                    break;
                }

                UserActions.ChooseAction(input);
            }
        }