Пример #1
0
        // Test deleting a thread as admin
        private static async Task TestDeleteThreadAdmin()
        {
            // Receives user input and retrieves comment
            Console.Write("Enter the ID of the thread to delete\n> ");
            int    id     = int.Parse(Console.ReadLine());
            Result result = await client.AdminDeleteThreadAsync(id);

            if (result.Success)
            {
                Console.WriteLine("Thread deleted");
            }
            else
            {
                DisplayItems.DisplayError(result);
            }
        }
Пример #2
0
        // Tests deleting comments as admin
        private static async Task TestAdminDeleteComment()
        {
            // Receives user input and deletes comment as admin
            Console.Write("Enter the id of the comment to delete\n> ");
            int    id     = int.Parse(Console.ReadLine());
            Result result = await client.AdminDeleteCommentAsync(id);

            // Outputs result
            if (result.Success)
            {
                Console.WriteLine("Comment deleted");
            }
            else
            {
                DisplayItems.DisplayError(result);
            }
        }
Пример #3
0
        // Tests getting comments by ID
        private static async Task TestGetComment()
        {
            // Receives user input and retrieves comment
            Console.Write("Enter the id of the comment to retrieve\n> ");
            int id = int.Parse(Console.ReadLine());
            Result <ApiComment> result = await client.GetCommentAsync(id);

            // Outputs result
            if (result.Success)
            {
                DisplayItems.DisplayComment(result.Value);
            }
            else
            {
                DisplayItems.DisplayError(result);
            }
        }
Пример #4
0
        // Tests deleting user comment
        private static async Task TestDeleteUserComment()
        {
            // Receives user input and deletes UserComment
            Console.Write("Enter user comment ID\n> ");
            int    id     = int.Parse(Console.ReadLine());
            Result result = await client.DeleteUserCommentAsync(id);

            // Outputs result
            if (result.Success)
            {
                Console.WriteLine("Deleted UserComment");
            }
            else
            {
                DisplayItems.DisplayError(result);
            }
        }
Пример #5
0
        // Tests downloading an image
        private static async Task TestProfileImage()
        {
            Console.Write("Enter the ID of the user to download the image for\n> ");
            int ID = int.Parse(Console.ReadLine());

            Result <Stream> result = await client.GetProfileImg(ID);

            if (result.Failure)
            {
                DisplayItems.DisplayError(result);
                return;
            }

            await using FileStream fileStream = File.Create("image.jpg");
            result.Value.Seek(0, SeekOrigin.Begin);
            result.Value.CopyTo(fileStream);
        }
Пример #6
0
        // Tests getting user comments
        private static async Task TestGetUserComments()
        {
            // Retrieves user input and gets user comments
            Console.Write("Enter the user ID\n> ");
            int id = int.Parse(Console.ReadLine());
            Result <List <ApiComment> > result = await client.GetUserCommentsAsync(id);

            // Outputs result
            if (result.Success)
            {
                result.Value.ForEach(DisplayItems.DisplayComment);
            }
            else
            {
                DisplayItems.DisplayError(result);
            }
        }
Пример #7
0
        // Tests receiving threads of a given ID
        private static async Task TestThreads()
        {
            // Retrieves threads and displays result
            Console.Write("Enter the ID of the thread to view\n> ");
            int id = int.Parse(Console.ReadLine());

            Console.Clear();
            Result <ApiThread> response = await client.GetThreadAsync(id);

            // Outputs result
            if (response.Success)
            {
                DisplayItems.DisplayThread(response.Value);
            }
            else
            {
                DisplayItems.DisplayError(response);
            }
        }
Пример #8
0
        // Tests creating a thread
        private static async Task TestCreateThread()
        {
            // Receives user input and creates thread
            Console.Write("Thread title: ");
            string title = Console.ReadLine();

            Console.Write("Thread contents: ");
            string             contents = Console.ReadLine();
            Result <ApiThread> result   = await client.CreateThreadAsync(title, contents);

            // Output result
            if (result.Success)
            {
                DisplayItems.DisplayThread(result.Value);
            }
            else
            {
                DisplayItems.DisplayError(result);
            }
        }
Пример #9
0
        // Tests posting a comment
        private static async Task TestPostComment()
        {
            // Receives user input and posts comment
            Console.Write("Enter the ID of the post to comment on\n> ");
            int id = int.Parse(Console.ReadLine());

            Console.Write("Enter the contents of the comment to post\n> ");
            string content             = Console.ReadLine();
            Result <ApiComment> result = await client.PostCommentAsync(id, content);

            // Outputs result
            if (result.Success)
            {
                DisplayItems.DisplayComment(result.Value);
            }
            else
            {
                DisplayItems.DisplayError(result);
            }
        }
Пример #10
0
        // Tests logging in
        private static async Task TestLogin()
        {
            // User enters username and password
            Console.Write("Username: "******"Password: "******"Token: {loginResponse.Value.Token}");
                Console.WriteLine($"Valid until: {loginResponse.Value.ValidUntil}");
                Console.WriteLine(separator);
            }
        }
Пример #11
0
        // Tests retrieving comments of a thread
        private static async Task TestThreadComments()
        {
            // Receives user input and retrieves comment
            Console.Write("Enter the ID of the thread to retrieve\n> ");
            int id = int.Parse(Console.ReadLine());

            Console.Write("Enter the page of the comments to view\n> ");
            int page = int.Parse(Console.ReadLine());
            Result <List <ApiComment> > result = await client.GetThreadCommentsAsync(id, page);

            // Outputs result
            if (result.Success)
            {
                foreach (ApiComment comment in result.Value)
                {
                    DisplayItems.DisplayComment(comment);
                }
                Console.WriteLine(separator);
            }
            else
            {
                DisplayItems.DisplayError(result);
            }
        }
Пример #12
0
        // Tests retrieving threads from the front page
        private static async Task TestFrontPage()
        {
            // Retrieves list of threads for the given page
            Console.Write("Select a page to view\n> ");
            int page = int.Parse(Console.ReadLine());

            Console.Clear();
            Result <List <ApiThread> > response = await client.GetFrontPageAsync(page);

            // Outputs result
            if (response.Success)
            {
                Console.WriteLine(separator);
                foreach (ApiThread thread in response.Value)
                {
                    DisplayItems.DisplayThread(thread);
                    Console.WriteLine(separator);
                }
            }
            else
            {
                DisplayItems.DisplayError(response);
            }
        }