public static void FillWithSampleData(LibraryManager manager) { manager.AddNewReader("Jacek", "Kowal"); manager.AddNewReader("Aneta", "Dzwon"); manager.AddNewBookItem("Dziady", "Adam Mickiewicz"); manager.RegisterCopies(0, 20, 10.20, "pln"); manager.RegisterCopies(0, 1, 10.99, "pln"); manager.RegisterBorrowing(1, 0); manager.RegisterPurchase(0, 0); }
//4. Dodaj czytelnika /// <summary> /// Funkcja rysująca na ekranie kreator nowego czytelnika. /// </summary> /// <param name="library">Biblioteka</param> static void MenuAddNewReader(LibraryManager library) { Console.WriteLine("Dodaj nowego czytelnika"); Console.WriteLine(); Console.Write("Imię i nazwisko: "); string name = Console.ReadLine(); Console.Write("Numer telefonu: "); string phoneNumber = Console.ReadLine(); Console.Write("Adres email: "); string emailAddress = Console.ReadLine(); Console.WriteLine(); try { library.AddNewReader(name, phoneNumber, emailAddress); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); Console.WriteLine("Czytelnik nie został dodany, wciśnij dowolny klawisz aby kontynuować..."); Console.ReadKey(); } catch (FormatException ex) { Console.WriteLine(ex.Message); Console.WriteLine("Czytelnik nie został dodany, wciśnij dowolny klawisz aby kontynuować..."); Console.ReadKey(); } }
public void Test2() { LibraryManager libraryManager = new LibraryManager(new DataRepository()); libraryManager.AddNewReader("Jacek", "Kowal"); libraryManager.AddNewReader("Aneta", "Dzwon"); libraryManager.AddNewBookItem("Dziady", "Adam Mickiewicz"); libraryManager.RegisterCopies(0, 20, 10.20, "pln"); libraryManager.RegisterCopies(0, 1, 10.99, "pln"); libraryManager.RegisterBorrowing(1, 0); libraryManager.RegisterPurchase(0, 0); MyXmlSerializer.CreateFile(typeof(LibraryManager), libraryManager, "serialization.xml"); LibraryManager managerBackup = (LibraryManager)MyXmlSerializer.ReadFile(typeof(LibraryManager), "serialization.xml"); libraryManager.dataRepository.dataContext.books.Values.Last().author = "zmiana"; Assert.AreEqual("zmiana", libraryManager.dataRepository.dataContext.copyInfos.First().bookItem.author); managerBackup.dataRepository.dataContext.books.Values.Last().author = "zmiana"; Assert.AreEqual("zmiana", managerBackup.dataRepository.dataContext.copyInfos.First().bookItem.author); }
//[Fact] public void MethodsTest() { DataService testService = new LibraryManager(new DataRepository(new MyXmlReader("path"))); string title1 = "Dziady", title2 = "Wiersze", title3 = "Treny", author1 = "Adam Mickiewicz", author2 = "Jan Brzechwa", author3 = "Jan Kochanowski"; string name1 = "Jan", name2 = "Piotr", name3 = "Adam", lastName1 = "Kowalski", lastName2 = "Nowak", lastName3 = "Puszek"; Assert.True(testService.AddNewBookItem(title1, author1)); Assert.True(testService.AddNewBookItem(title2, author2)); Assert.False(testService.AddNewBookItem(title2, author2)); Assert.Equal(2, testService.GetInfo("bookItems").Count); Assert.True(testService.ChangeBookItemData(0, title3, author3)); Assert.Contains(title3, testService.GetInfo("bookItems")[0]); Assert.Contains(author3, testService.GetInfo("bookItems")[0]); Assert.False(testService.ChangeBookItemData(3, title3, author3)); Assert.True(testService.AddNewReader(name1, lastName1)); Assert.True(testService.AddNewReader(name2, lastName2)); Assert.False(testService.AddNewReader(name2, lastName2)); Assert.Equal(2, testService.GetInfo("readers").Count); Assert.True(testService.ChangeReaderData(0, name3, lastName3)); Assert.Contains(name3, testService.GetInfo("readers")[0]); Assert.Contains(lastName3, testService.GetInfo("readers")[0]); Assert.False(testService.ChangeReaderData(3, name3, lastName3)); Random rnd = new Random(); int quantity = rnd.Next(10, 256); double prize = rnd.NextDouble() * quantity; string currency = "PLN"; Assert.True(testService.RegisterCopies(0, quantity, prize, currency)); quantity = rnd.Next(10, 256); prize = rnd.NextDouble() * quantity; currency = "USD"; Assert.True(testService.RegisterCopies(1, quantity, prize, currency)); Assert.True(testService.RegisterCopies(1, quantity, prize, currency)); Assert.Equal(2, testService.GetInfo("copyInfos").Count); Assert.Contains((quantity * 2).ToString(), testService.GetInfo("copyInfos")[1]); quantity = rnd.Next(10, 256); prize = rnd.NextDouble() * quantity; currency = "EUR"; Assert.True(testService.ChangeCopiesData(0, 1, quantity, prize, currency)); Assert.Contains(title2, testService.GetInfo("copyInfos")[0]); Assert.Contains(author2, testService.GetInfo("copyInfos")[0]); Assert.Contains(quantity.ToString(), testService.GetInfo("copyInfos")[0]); Assert.Contains(prize.ToString("0.00"), testService.GetInfo("copyInfos")[0]); Assert.Contains(currency.ToString(), testService.GetInfo("copyInfos")[0]); Assert.False(testService.ChangeCopiesData(3, 1, quantity, prize, currency)); int tmp = rnd.Next(1, quantity); Assert.True(testService.RetractCopies(0, tmp)); Assert.Equal(quantity - tmp, testService.GetQuantity(0)); DateTime date1 = new DateTime(1995, 1, 1); date1 = date1.AddDays(rnd.Next(200, 1000)); Assert.True(testService.RegisterBorrowing(0, 0)); Assert.True(testService.RegisterBorrowing(1, 1, date1)); date1 = date1.AddDays(rnd.Next(200, 1000)); DateTime date2 = date1.AddDays(rnd.Next(1, 100)); Assert.True(testService.RegisterBorrowing(0, 1, date1, date2)); Assert.False(testService.RegisterBorrowing(2, 0)); Assert.False(testService.RegisterBorrowing(0, 2, date1)); Assert.False(testService.RegisterBorrowing(2, 0)); Assert.False(testService.RegisterBorrowing(2, 2, date1, date2)); Assert.True(testService.RegisterPurchase(0, 0)); Assert.True(testService.RegisterPurchase(1, 0, date2)); Assert.False(testService.SetReturned(3)); // date 1 < date2 Assert.False(testService.RegisterBorrowing(0, 0, date2, date1)); Assert.Equal(5, testService.GetInfo("events").Count); Assert.True(testService.SetReturned(0)); Assert.False(testService.SetReturned(0)); Assert.True(testService.RemoveReader(0)); Assert.True(testService.RemoveReader(0)); Assert.False(testService.RemoveReader(0)); Assert.False(testService.ChangeReaderData(0, name3, lastName3)); Assert.True(testService.RemoveBookItem(0)); Assert.True(testService.RemoveBookItem(1)); Assert.False(testService.RemoveBookItem(0)); Assert.False(testService.ChangeBookItemData(1, title3, author3)); Assert.True(testService.RetractCopies(1)); Assert.False(testService.ChangeCopiesData(1, 1, quantity, prize, currency)); }