// 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); }
// 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); } }
// 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); } }
// 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); } }
// 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); } }
// 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); } }
// 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); } }
// 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); } }