static void Main(string[] args) { try { BookListStorage bookStorage = new BookListStorage("NewStorage.bin"); BookListService bookService = new BookListService(bookStorage); bookService.AddBookToShop(new Book("978-3-16-123451-0", "Ivanov", "one", "Minsk", 2000, 1000, 100)); bookService.AddBookToShop(new Book("978-3-16-123452-1", "Petrov", "two", "Gomel", 2001, 2000, 200)); bookService.AddBookToShop(new Book("978-3-16-123453-2", "Glebov", "three", "Brest", 2002, 3000, 300)); bookService.AddBookToShop(new Book("978-3-16-123454-3", "Arkhipov", "four", "Vitebsk", 2003, 4000, 400)); var books = new List <Book>(); books.Add(bookService.FindBook(new FindBookByName("one", bookService.GetAllBooks()))); PrintBook(books); bookService.Sort(null); PrintBook(bookService.GetAllBooks()); Console.WriteLine(books[0].ToString("2", CultureInfo.CurrentCulture)); bookService.Save(); Console.ReadKey(); } catch (Exception ex) { Log.Write(ex); } }
public void BookLoggerTest_InfoMessage() { Book rigthBook = new Book("978-0-7356-6745-7", "Jeffrey Richter", "CLR via C#", "Microsoft Press", 2012, 826, 59.99); bool added = bookShop.AddBookToShop(rigthBook); using (StreamReader reader = new StreamReader("Logs.log")) { line = reader.ReadLine(); } string[] mess = line.Split("[INFO]", StringSplitOptions.RemoveEmptyEntries); line = mess[1].Trim(); Assert.AreEqual(@"Book ""CLR via C#"" was added.", line); }
private static void AddBookToShop(BookListService bookShop) { Console.Write("To add book to the storage you need enter the following data:" + "\n"); Console.Write("ISBN * Author * Title * Publisher * Year of publication * Number of pages * Price." + "\n\n"); Console.WriteLine("Enter this data separated by commas."); string input = Console.ReadLine(); string[] enretedData = input.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var isbn = enretedData[0]; var author = enretedData[1]; var title = enretedData[2]; var publisher = enretedData[3]; var year = int.Parse(enretedData[4]); var pages = int.Parse(enretedData[5]); var price = double.Parse(enretedData[6]); bookShop.AddBookToShop(new Book(isbn, author, title, publisher, year, pages, price)); }