public void DeleteVisitor() { string Name1 = "name1"; string Name2 = "name2"; testvisit.Add(Name1, "test", 222, new DocOffers()); testvisit.Add(Name2, "test", 222, new DocOffers()); testvisit.Remove(0); string actual = testvisit.GetInfo(0).Name; Assert.AreEqual(Name2, actual); }
private void Visitor() { bool run = true; while (run) { Console.Clear(); Console.WriteLine("\t\tMenu"); Console.WriteLine("1. Add Visitor\n2. Remove Visitor\n3. Edit Visitor\n4. Show Visitor info\n5. Show list with all Visiors\n6. Sort\n7. Offers taked by this Visitor\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 Name: "); string n = Console.ReadLine(); Console.Write("Write Surname: "); string sn = Console.ReadLine(); Console.Write("Write Academ Group: "); int group = Convert.ToInt32(Console.ReadLine()); DocOffers b = new DocOffers(); visitorsList.Add(n, sn, group, b); Console.WriteLine(visitorsList.GetInfo(visitorsList.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 client who want delete: "); int ind = Convert.ToInt32(Console.ReadLine()) - 1; if (ind < 0 || ind >= visitorsList.Last) { throw new LibraryException("Index out of range"); } visitorsList.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 Visitor: "); int ind = Convert.ToInt32(Console.ReadLine()) - 1; if (ind < 0 || ind >= visitorsList.Last) { throw new LibraryException("Index out of range"); } Console.Write("Write Name: "); string n = Console.ReadLine(); Console.Write("Write Surname: "); string sn = Console.ReadLine(); Console.Write("Write Academ Group: "); int group = Convert.ToInt32(Console.ReadLine()); visitorsList.Edit(ind, n, sn, group); 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 client: "); int ind = Convert.ToInt16(Console.ReadLine()) - 1; if (ind < 0 || ind >= visitorsList.Last) { throw new LibraryException("Index out of range"); } Console.WriteLine(visitorsList.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(visitorsList.GetAllVisitors()); 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 Name\n2. Sort by Surname\n3. Sort by first digit AcademGroup\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 < visitorsList.Last; i++) { Console.WriteLine(visitorsList.SortByName()[i].Name); } Console.WriteLine("Succesfull"); Console.ReadKey(); } catch (Exception e) { Console.WriteLine($"{e.Message}\nPress any key to continue..."); Console.ReadKey(); } break; case "2": try { visitorsList.SortBySurname(); Console.WriteLine("Succesfull"); Console.ReadKey(); } catch (Exception e) { Console.WriteLine($"{e.Message}\nPress any key to continue..."); Console.ReadKey(); } break; case "3": try { visitorsList.SortByGroup(); 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; case "7": try { Console.WriteLine("1. Add to Offer's\n2. Remove from Offers\n3. Check who take the same Book\n0.Exit"); string answ = Console.ReadLine(); Console.Clear(); switch (answ) { case "0": run = false; visitorsList.Save(); docsList.Save(); break; case "1": try { AddOffer(); } catch (Exception e) { Console.WriteLine($"{e.Message}\nPress any key to continue..."); Console.ReadKey(); } break; case "2": try { RemoveOffer(); } catch (Exception e) { Console.WriteLine($"{e.Message}\nPress any key to continue..."); Console.ReadKey(); } break; case "3": try { Avaible(); } 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; } } }
public void RemoveV() { visitors.Add("test", "test", 117, new DocOffers()); visitors.Remove(0); }