Esempio n. 1
0
        /// <summary>
        /// Runs the logout functionality page
        /// </summary>
        /// <param name="userId"></param>
        public void Run(int userId)
        {
            if (userId != 0)
            {
                WebbShopAPI api = new WebbShopAPI();
                api.Logout(userId);
            }

            AccountViews.LogoutUser();
        }
Esempio n. 2
0
        /// <summary>
        /// Logs the user out from the database by user ID input in the parameters.
        /// </summary>
        /// <param name="userId"></param>
        /// <returns>True if successful, else false</returns>
        internal bool LogOutUser(int userId)
        {
            webAPI.Logout(userId);
            string check = webAPI.Ping(userId);

            if (check != "Pong")
            {
                return(true);
            }
            else
            {
                Debug.WriteLine("User still active when logout is called");
                return(false);
            }
        }
        /// <summary>
        /// Runs the scenario
        /// </summary>
        public static void Run()
        {
            var api = new WebbShopAPI();

            Console.Write("Logged in as: ");
            int userId = api.Login("Administrator", "CodicRulez");

            Console.WriteLine(userId);

            //-------------------------------------------------------------------------

            Console.WriteLine("Adding new book... ");
            bool success = api.AddBook(userId, "Sagan om ringen", "J.R.R Tolkien", 300, 5);

            if (success)
            {
                Console.WriteLine("Added book: Sagan om ringen by J.R.R Tolkien");
            }

            //-------------------------------------------------------------------------

            Console.WriteLine("Setting amount... ");
            success = api.SetAmount(userId, 2, 4);
            if (success)
            {
                Console.WriteLine("Successfully added new amount.");
            }

            //-------------------------------------------------------------------------
            Console.WriteLine("Searching for all users...");
            var list = api.ListUsers(userId);

            foreach (var user in list)
            {
                Console.WriteLine(user.Name);
            }

            //-------------------------------------------------------------------------

            Console.WriteLine("Searching for all users matching keyword \"te\"... ");
            list = api.FindUser(userId, "te");
            foreach (var user in list)
            {
                Console.WriteLine(user.Name);
            }

            //-------------------------------------------------------------------------

            var book = Helper.GetBookObject("Sagan om ringen");

            if (book != null)
            {
                Console.WriteLine($"Updating {book.Title} with new price 350...");
                success = api.UpdateBook(userId, book.ID, book.Title, book.Author, 350);
                if (success)
                {
                    Console.WriteLine("Sucessfully updated book");
                }
            }

            //-------------------------------------------------------------------------

            Console.WriteLine("Adding new category... ");
            success = api.AddCategory(userId, "Fantasy");
            if (success)
            {
                Console.WriteLine("Added category: Fantasy");
            }

            Console.WriteLine("Adding new category... ");
            success = api.AddCategory(userId, "Action");
            if (success)
            {
                Console.WriteLine("Added category: Action");
            }

            //-------------------------------------------------------------------------

            Console.WriteLine("Adding book to category... ");
            var bookId     = Helper.GetBookID("Sagan om ringen");
            var categoryId = Helper.GetCategoryId("Fantasy");

            success = api.AddBookToCategory(userId, bookId, categoryId);
            if (success)
            {
                Console.WriteLine("Successfully added book Sagan om ringen to category Fantasy");
            }

            //-------------------------------------------------------------------------

            Console.WriteLine("Updating category... ");
            categoryId = Helper.GetCategoryId("Action");
            success    = api.UpdateCategory(userId, categoryId, "ActionPower");
            if (success)
            {
                Console.WriteLine("Successfully updated category genere Action to ActionPower.");
            }

            //-------------------------------------------------------------------------

            Console.WriteLine("Adding new user... ");
            success = api.AddUser(userId, "Legolas", "L3mb4sBr34d");
            if (success)
            {
                Console.WriteLine("Successfully added user: Legolas");
            }

            //-------------------------------------------------------------------------

            Console.WriteLine("Promoting \"Legolas\"... ");
            var customerId = Helper.GetUserID("Legolas");

            success = api.Promote(userId, customerId);
            if (success)
            {
                Console.WriteLine("Sucessfully promoted Legolas to Admin");
            }

            api.Logout(userId);

            //-------------------------------------------------------------------------

            Console.Write("Logged in as: ");
            userId = api.Login("Legolas", "L3mb4sBr34d");
            Console.WriteLine(userId);

            Console.WriteLine("Purchasing \"Sagan om ringen\"... ");
            bookId  = Helper.GetBookID("Sagan om ringen");
            success = api.BuyBook(userId, bookId);
            if (success)
            {
                Console.WriteLine("Purchase successful.");
            }

            Console.WriteLine("Purchasing \"Sagan om ringen\"... ");
            success = api.BuyBook(userId, bookId);
            if (success)
            {
                Console.WriteLine("Purchase successful.");
            }

            Console.WriteLine("Purchasing \"Sagan om ringen\"... ");
            success = api.BuyBook(userId, bookId);
            if (success)
            {
                Console.WriteLine("Purchase successful.");
            }

            api.Logout(userId);

            //-------------------------------------------------------------------------

            Console.Write("Logged in as: ");
            userId = api.Login("Administrator", "CodicRulez");
            Console.WriteLine(userId);

            Console.WriteLine("Searching for all sold items...");
            var soldBooks = api.SoldItems(userId);

            if (soldBooks.Count > 0)
            {
                foreach (var item in soldBooks)
                {
                    Console.WriteLine($"{item.Title} - {item.Author}");
                }
            }

            Console.WriteLine("Searching for total price of all sold items... ");
            int moneyEarned = api.MoneyEarned(userId);

            if (moneyEarned > 0)
            {
                Console.WriteLine($"Money earned: {moneyEarned}");
            }

            Console.WriteLine("Searching \"Best customer\"... ");
            int bestCustomer = api.BestCustomer(userId);

            if (bestCustomer > 0)
            {
                Console.WriteLine($"Best customer's ID: {bestCustomer}");
            }

            Console.WriteLine("Deleting book \"I Robot\"... ");
            bookId  = Helper.GetBookID("I Robot");
            success = api.DeleteBook(userId, bookId);
            if (success)
            {
                Console.WriteLine("Successfully deleted book");
            }

            Console.WriteLine("Deleting category \"Romance\"... ");
            categoryId = Helper.GetCategoryId("Romance");
            success    = api.DeleteCategory(userId, categoryId);
            if (success)
            {
                Console.WriteLine("Successfully deleted category");
            }

            Console.WriteLine("Deleting category \"Fantasy\"... ");
            categoryId = Helper.GetCategoryId("Fantasy");
            success    = api.DeleteCategory(userId, categoryId);
            if (success)
            {
                Console.WriteLine("Successfully deleted category");
            }

            api.Logout(userId);
        }
        /// <summary>
        /// Runs a test-scenario
        /// </summary>
        public static void Run()
        {
            var api = new WebbShopAPI();

            Console.Write("Logged in as: ");
            int userId = api.Login("TestCustomer", "Codic2021");

            Console.WriteLine(userId);

            //---------------------------------------------------

            Console.WriteLine("Searching all categories: ");
            var listOfCategories = api.GetCategories();

            if (listOfCategories.Count > 0)
            {
                foreach (var category in listOfCategories)
                {
                    Console.WriteLine(category.Genere);
                }
            }

            //---------------------------------------------------

            Console.WriteLine("Searching all categories with \"or\"-keyword: ");
            listOfCategories = api.GetCategories("or");
            if (listOfCategories.Count > 0)
            {
                foreach (var category in listOfCategories)
                {
                    Console.WriteLine(category.Genere);
                }
            }

            //---------------------------------------------------

            Console.WriteLine("Searching for all books with category \"Horror\": ");
            var listOfBooks = api.GetCategories(2);

            if (listOfBooks.Count > 0)
            {
                foreach (var book in listOfBooks)
                {
                    Console.WriteLine(book.Title);
                }
            }

            var respons = api.Ping(userId);

            if (respons.Length > 0)
            {
                Console.WriteLine(respons);
            }

            //---------------------------------------------------

            Console.WriteLine("Searching for all available books with category \"Horror\": ");
            var listOfAvailableBooks = api.GetAvailableBooks(2);

            foreach (var book in listOfAvailableBooks)
            {
                Console.WriteLine($"{book.Title}, Amount: {book.Amount}");
            }

            //---------------------------------------------------

            Console.WriteLine("Information around all books with genere \"Horror\"");
            var description = api.GetBook(4);

            Console.WriteLine(description);

            //---------------------------------------------------

            Console.WriteLine("Searching for books matching search word \"shi\"");
            listOfBooks = api.GetBooks("shi");
            foreach (var book in listOfBooks)
            {
                Console.WriteLine(book.Title);
            }

            respons = api.Ping(userId);
            if (respons.Length > 0)
            {
                Console.WriteLine(respons);
            }

            //---------------------------------------------------

            Console.WriteLine("Searching for books matching Author \"Stephen King\"");
            listOfBooks = api.GetAuthor("Stephen King");
            foreach (var book in listOfBooks)
            {
                Console.WriteLine(book.Title);
            }

            //---------------------------------------------------

            Console.WriteLine("Selected book to purchase: \"Doctor Sleep\"");
            var succeed = api.BuyBook(userId, 2);

            if (succeed)
            {
                Console.WriteLine("Purchase made");
            }

            //---------------------------------------------------

            api.Logout(userId);
        }