static void Main(string[] args)
 {
     var temp = new Book("one", "One");
     var first = new Book("Роулинг Джоанн", "Гарри Поттер и философский камень", "Фантастика", "РОСМЭН-Издат",
         300);
     var seventh = new Book("J.K.Rouling", "Harry Potter and the deathly Hallows");
     var bookList = new BookListService();
     bookList.AddBook(first);
     bookList.AddBook(seventh);
     bookList.AddBook(temp);
     try { bookList.AddBook(null); } catch (ArgumentNullException) { }
     try { bookList.AddBook(new Book("one", "One")); } catch (ArgumentException) { }
     try { bookList.RemoveBook(null); } catch (ArgumentNullException) { }
     try { bookList.RemoveBook(new Book("two", "Two")); } catch (ArgumentException) { }
     Console.WriteLine("BookListService");
     var brw = new BinaryReaderWriter("books_new.bin");
     bookList.SaveBooks(brw);
     bookList.PrintBooks();
     Console.WriteLine();
     bookList.SortBooksByAuthor();
     bookList.PrintBooks();
     Console.WriteLine();
     bookList.SortBooksByTitle();
     bookList.PrintBooks();
     Console.WriteLine();
     var newList = new BookListService();
     newList.LoadBooks(brw);
     newList.PrintBooks();
     Console.ReadLine();
 }
Example #2
0
        private static void SaveService(IRepository serializator)
        {
            BookListService service = new BookListService();

            service.AddBook(new Book("fAuthor1", "Title1", "Text1", 1));
            service.AddBook(new Book("eAuthor2", "Title2", "Text2", 2));
            service.AddBook(new Book("aAuthor3", "Title3", "Text3", 3));
            service.AddBook(new Book("cAuthor4", "Title4", "Text4", 4));
            service.AddBook(new Book("bAuthor5", "Title5", "Text5", 5));
            service.AddBook(new Book("dAuthor6", "Title6", "Text6", 6));

            Console.WriteLine("---------- Old Service ----------");
            Console.WriteLine(service.PrintBooks());
            service.Sort((b1, b2) => b1.Author.CompareTo(b2.Author));
            Console.WriteLine("FindByAuthor: " + service.FindBy(author:"aAuthor3").Print());
            Console.WriteLine("FindByTitle: " + service.FindBy(title:"Title1").Print());
            Console.WriteLine(service.RemoveBook(service.FindBy(author:"fAuthor1")));

            try { service.AddBook(null); }
            catch (Exception) { }
            try { service.AddBook(new Book("dAuthor6", "Title6", "Text6", 6)); }
            catch (Exception) { }
            try { service.RemoveBook(null); }
            catch (Exception) { }
            try { service.RemoveBook(new Book("dAuthor", "Title6", "Text6", 6)); }
            catch (Exception) { }
            try { service.FindBy(author: null).Print(); }
            catch (Exception) { }
            try { service.FindBy(title: "").Print(); }
            catch (Exception) { }

            try
            {
                try { service.Save("test.bin", serializator); } catch (Exception) { }
            }
            catch (ArgumentException e) 
            { Console.WriteLine("Wrong argument error with message: {0}", e.Message); }
        }