public void SetUp()
        {
            b1  = new Book("A Tale Of Two Cities", "Charles Dickens", 1859, 3.76);
            b2  = new Book("The Great Gatsby", "F. Scott Fitzgerald", 1925, 3.85);
            b3  = new Book("Pride and Prejudice", "Jane Austen", 1813, 4.23);
            b4  = new Book("To Kill A Mockingbird", "Harper Lee", 1960, 4.23);
            b5  = new Book("Jane Eyre", "Charlotte Bronte", 1847, 4.07);
            b6  = new Book("The Catcher and the Rye", "J.D. Salinger", 1951, 3.77);
            b7  = new Book("Sense and Sensibility", "Jane Austen", 1811, 4.04);
            b8  = new Book("Emma", "Jane Austen", 1815, 3.97);
            b9  = new Book("1984", "George Orwell", 1949, 4.09);
            b10 = new Book("Oliver Twist", "Charles Dickens", 1838, 3.82);

            books = new BookList();
            books.AddBook(b1);
            books.AddBook(b2);
            books.AddBook(b3);
            books.AddBook(b4);
            books.AddBook(b5);
            books.AddBook(b6);
            books.AddBook(b7);
            books.AddBook(b8);
            books.AddBook(b9);
            books.AddBook(b10);
        }
        public void TestBooksAdded()
        {
            Assert.AreEqual(10, books.NumberBooks());

            //add new book to make sure NumberBooks() works
            Book b11 = new Book("Twilight", "Stephanie Myers", 2005, 3.57);

            books.AddBook(b11);
            Assert.AreEqual(11, books.NumberBooks());
        }
Esempio n. 3
0
        public void SizeOfBookListTest()
        {
            var booklist  = new BookList();
            var book      = new Book("Book", "Author", 2000, "isbn", Category.Drama);
            var booktwo   = new Book("Book", "Author", 2000, "isbn", Category.Drama);
            var bookthree = new Book("Book", "Author", 2000, "isbn", Category.Drama);

            booklist.AddBook(book);
            booklist.AddBook(booktwo);
            booklist.AddBook(bookthree);
            Assert.Equal(3, booklist.Size());
        }
Esempio n. 4
0
 public MainWindow()
 {
     InitializeComponent();
     bookList = new BookList();
     bookList.AddBook(new Book("111-222-333-4444", "ferfe", "freferf", "freferf", 344, 34, "43"));
     bookListView.ItemsSource = bookList.Books;
 }
Esempio n. 5
0
        public void CreateBookListAddBookTest()
        {
            var booklist = new BookList();
            var book     = new Book("Book", "Author", 2000, "isbn", Category.Drama);

            booklist.AddBook(book);
            Assert.Equal(1, booklist.Size());
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            try
            {
                Book book1 = new Book("qqq", "www", "www", "www", 1995, 1000, 132);
                Book book2 = new Book("qq1q", "ww2w", "ww3w", "ww4w", 1995, 1200, 90);
                Book book3 = new Book("qqq", "www", "www", "www", 1995, 800, 175.0);
                Book book4 = new Book("qqq", "www", "www", "www", 1995, 800, 5);

                BookList bookList = new BookList(logger);
                Console.WriteLine("Adding books in BookList");
                bookList.AddBook(book1);
                bookList.AddBook(book2);
                bookList.AddBook(book3);
                Console.WriteLine("Added!");
                Console.WriteLine("removing books in BookList");
                bookList.RemoveBook(book3);
                Console.WriteLine("Removed!");

                Console.WriteLine("Save information about books in the binary file!");
                string       path        = @"D:\Epam\Epam.ASP.NET\NET.S.2018.Danilovich.10\BookStorageLogic\file.txt";
                IBookStorage bookStorage = new BinaryStorage(path);
                bookList.SaveBooksIntoStorage(bookStorage);
                Console.WriteLine("Saved!");
            }
            catch (FormatException error)
            {
                logger.WriteInfo("Format exseption");
                logger.WriteError(error.StackTrace);
            }
            catch (ArgumentNullException error)
            {
                logger.WriteInfo("Argument null exception");
                logger.WriteError(error.StackTrace);
            }
            catch (Exception error)
            {
                logger.WriteInfo("Unhandled exception:");
                logger.WriteError(error.StackTrace);
            }
        }
Esempio n. 7
0
 private void addBtn_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         string isbn        = isbnTextBox.Text;
         string author      = authorTextBox.Text;
         string title       = titleTextBox.Text;
         string publisher   = publisherTextBox.Text;
         int    publishedAt = int.Parse(publishedAtTextBox.Text);
         int    pagesCount  = int.Parse(pagesCountTextBox.Text);
         string price       = priceTextBox.Text;
         Book   book        = new Book(isbn, author, title, publisher, publishedAt, pagesCount, price);
         foreach (Book otherBook in bookList.Books)
         {
             if (book.ISBN == otherBook.ISBN)
             {
                 if (book.Equals(otherBook))
                 {
                     break;
                 }
                 else
                 {
                     throw new FormatException("ISBN must be unique for different editions.");
                 }
             }
         }
         bookList.AddBook(book);
     }
     catch (OverflowException ex)
     {
         MessageBox.Show(ex.Message);
     }
     catch (ArgumentException ex)
     {
         MessageBox.Show(ex.ParamName);
     }
     catch (FormatException ex)
     {
         MessageBox.Show(ex.Message);
     }
     catch
     {
         MessageBox.Show("Wrong data");
     }
     return;
 }
Esempio n. 8
0
        public bool AddNewBook(string bookName, string bookAuthor)
        {
            AbstractSerialize serializeObj = new FileHandling();
            BookList          bookListObj  = BookList.GetBookList();

            serializeObj.ReadBookList();
            Book.BookCount = bookListObj.ListOfBooks.Count;

            if (bookListObj.AddBook(bookName, bookAuthor))
            {
                serializeObj.WriteBookList();
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string bookName  = txtBookName.Text;
            string bookGenre = txtBookGenre.Text;
            string bookPrice = txtPrice.Text;
            //string bookAuthor = txtAuthorName.Text;
            string bookDescript = txtBookDascript.Text;

            // secilmish qrupun ID nomresinin  groupID-ye verilmesi
            string authorId = ((BookComboBox)cmbAuthor.SelectedItem).Value;

            // Author tipinden deyishen yaradiriq
            // ve author siyahisinin ID-lerinden secilmishini deyishene veririk
            Author selectedAuthor = AuthorList.GetAuthorByID(authorId);

            if (selectedAuthor == null) // eger secilmish author yoxdursa
            {
                MessageBox.Show("Author doesn't exist");
                return;
            }

            if (string.IsNullOrEmpty(bookName))
            {
                // ERROR mesajinin verilmersi
                MessageBox.Show("Book name is not valid", "Failed!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }
            if (string.IsNullOrEmpty(bookGenre))
            {
                // ERROR mesajinin verilmersi
                MessageBox.Show("Book genre is not valid", "Failed!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }
            if (string.IsNullOrEmpty(bookDescript))
            {
                // ERROR mesajinin verilmersi
                MessageBox.Show("Book description is not valid", "Failed!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }
            if (string.IsNullOrEmpty(bookPrice))
            {
                // ERROR mesajinin verilmersi
                MessageBox.Show("Book price is not valid", "Failed!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            // eger AuthorListde bu ad varsa
            if (BookList.ContainsBookName(bookName))
            {
                // ERROR mesaji verilir
                MessageBox.Show("Book name is duplicate", "Failed!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }



            BookList.AddBook(new Book {
                BookName    = bookName,
                BookJenre   = bookGenre,
                Price       = bookPrice,
                Description = bookDescript,
                Authors     = selectedAuthor,
            });

            txtBookName.Text     = "";
            txtBookGenre.Text    = "";
            txtBookDascript.Text = "";
            txtPrice.Text        = "";
        }