public void DocEdit() { string Author1 = "ABS"; string Author2 = "BBB"; testdocs.Add(Author1, "test"); testdocs.Edit(0, Author2, "test"); string actual = testdocs.GetInfo(0).Author; Assert.AreEqual(Author2, actual); }
private void Docs() { bool run = true; while (run) { Console.Clear(); Console.WriteLine("\t\tMenu"); Console.WriteLine("1. Add Doc\n2. Remove Doc\n3. Edit Doc\n4. Show Doc info\n5. Show list with all Docs\n6. Sort\n\n0.Exit"); string answer = Console.ReadLine(); Console.Clear(); switch (answer) { case "0": run = false; visitorsList.Save(); docsList.Save(); break; case "1": try { Console.Write("Write Author: "); string n = Console.ReadLine(); Console.Write("Write Title: "); string title = Console.ReadLine(); docsList.Add(n, title); Console.WriteLine(docsList.GetInfo(docsList.Last - 1).ToString()); Console.ReadKey(); } catch (Exception e) { Console.WriteLine($"{e.Message}\nPress any key to continue..."); Console.ReadKey(); } break; case "2": try { Console.Write("Write index of doc what want delete: "); int ind = Convert.ToInt32(Console.ReadLine()) - 1; if (ind < 0 || ind >= docsList.Last) { throw new LibraryException("Index out of range"); } docsList.Remove(ind); Console.WriteLine("Succesfull deleted"); Console.ReadKey(); } catch (Exception e) { Console.WriteLine($"{e.Message}\nPress any key to continue..."); Console.ReadKey(); } break; case "3": try { Console.Write("Write index of Doc: "); int ind = Convert.ToInt32(Console.ReadLine()) - 1; if (ind < 0 || ind >= visitorsList.Last) { throw new LibraryException("Index out of range"); } Console.Write("Write Author: "); string n = Console.ReadLine(); Console.Write("Write Title: "); string sn = Console.ReadLine(); docsList.Edit(ind, n, sn); Console.Write("Succesfull edited!"); Console.ReadKey(); } catch (Exception e) { Console.WriteLine($"{e.Message}\nPress any key to continue..."); Console.ReadKey(); } break; case "4": try { Console.Write("Write index of doc: "); int ind = Convert.ToInt16(Console.ReadLine()) - 1; if (ind < 0 || ind >= docsList.Last) { throw new LibraryException("Index out of range"); } Console.WriteLine(docsList.GetInfo(ind).ToString()); Console.ReadKey(); } catch (Exception e) { Console.WriteLine($"{e.Message}\nPress any key to continue..."); Console.ReadKey(); } break; case "5": try { Console.WriteLine(docsList.GetDocs()); Console.ReadKey(); } catch (Exception e) { Console.WriteLine($"{e.Message}\nPress any key to continue..."); Console.ReadKey(); } break; case "6": try { Console.WriteLine("1. Sort by Author\n2. Sort by Title\n0. Exit"); string ans = Console.ReadLine(); Console.Clear(); switch (ans) { case "0": run = false; visitorsList.Save(); docsList.Save(); break; case "1": try { for (int i = 0; i < docsList.Last; i++) { Console.WriteLine(docsList.SortByAuthor()[i].Author); } Console.WriteLine("Succesfull"); Console.ReadKey(); } catch (Exception e) { Console.WriteLine($"{e.Message}\nPress any key to continue..."); Console.ReadKey(); } break; case "2": try { docsList.SortByTitle(); Console.WriteLine("Succesfull"); Console.ReadKey(); } catch (Exception e) { Console.WriteLine($"{e.Message}\nPress any key to continue..."); Console.ReadKey(); } break; default: Console.WriteLine("Wrong input\nPress any key to continue"); Console.ReadKey(); break; } } catch (Exception e) { Console.WriteLine($"{e.Message}\nPress any key to continue..."); Console.ReadKey(); } break; default: Console.WriteLine("Wrong input\nPress any key to continue"); Console.ReadKey(); break; } } }