public void Add_Book_With_Duplicated_ISBN()
        {
            // Arrange
            var  book    = new Book(iSBN: "A123C", title: "Se solto Teodoro", authors: "Pedro Pablo Leon Jaramillo");
            IDao bookDAO = new BookDAO();

            bookDAO.Add(book);

            // Act + Assert
            Assert.That(() => bookDAO.Add(book),
                        Throws.ArgumentException.With.Message.EqualTo("A book with this ISBN already exists."));
        }
        public void List_AllBooks()
        {
            // Arrange
            IDao dao = new BookDAO();

            dao.Add(new Book("ABC", "Libro Prueba", "JNovas"));
            dao.Add(new Book("CDE", "Libro Prueba", "JNovas"));
            dao.Add(new Book("DEF", "Libro Prueba", "JNovas"));

            // Act
            int booksCount = dao.GetAll().Count;

            // Act + Assert
            Assert.That(booksCount, Is.EqualTo(3));
        }
        public void Add_Book_With_Null_Author()
        {
            // Arrange
            var  book    = new Book(iSBN: "A123C", title: "Platero y yo", authors: null);
            IDao bookDAO = new BookDAO();

            // Act + Assert
            Assert.That(() => bookDAO.Add(book),
                        Throws.ArgumentNullException.With.Message.EqualTo("Author cannot be null."));
        }
        public void Add_Book_With_Null_Title()
        {
            // Arrange
            var  book    = new Book(iSBN: "A123C", title: null, authors: "Pedro Pablo Leon Jaramillo");
            IDao bookDAO = new BookDAO();

            // Act + Assert
            Assert.That(() => bookDAO.Add(book),
                        Throws.ArgumentNullException.With.Message.EqualTo("Title cannot be null."));
        }
        public void Add_Book_With_All_Info()
        {
            // Arrange
            var  book    = new Book(iSBN: "A123456Z", title: "Platero y yo", authors: "Pedro Pablo Leon Jaramillo");
            IDao bookDAO = new BookDAO();

            // Act
            bool expectedResult = bookDAO.Add(book);

            // Assert
            Assert.That(expectedResult, Is.EqualTo(true));
        }
        public void Return_Book_That_Already_Available()
        {
            //Arrange
            string  bookId = "E0";
            BookDAO dao    = new BookDAO();

            //Act
            dao.Add(new Book(bookId, "Libro Prueba", "JNovas"));

            //Assert
            Assert.That(() => dao.Return(bookId),
                        Throws.InvalidOperationException.With.Message.EqualTo("This book was not given to anyone"));
        }
        public void Lend_Book_To_Employee()
        {
            //Arrange
            string  bookId     = "E0";
            int     employeeId = 1;
            BookDAO bookLender = new BookDAO();

            //Act
            bookLender.Add(new Book(bookId, "Libro Prueba", "JNovas"));
            bool status = bookLender.Lend(bookId, employeeId);

            //Assert
            Assert.That(status, Is.EqualTo(true));
        }
Ejemplo n.º 8
0
 private void btnFilter_Click(object sender, EventArgs e)
 {
     if (check == 1)//Add
     {
         Book b = new Book();
         b.Title     = txtTitle.Text;
         b.Authors   = txtAuthors.Text;
         b.Publisher = txtPublisher.Text;
         if (BookDAO.ValidateBook(b))
         {
             BookDAO.Add(b);
             dgvBooks.DataSource = BookDAO.GetDataTable();
             MessageBox.Show("Add Successful");
             display(0);
             check = 0;
         }
     }
     else if (check == 2)  //Edit
     {
         Book b = new Book();
         b.BookNumber = Convert.ToInt32(txtBookNumber.Text);
         b.Title      = txtTitle.Text;
         b.Authors    = txtAuthors.Text;
         b.Publisher  = txtPublisher.Text;
         if (BookDAO.ValidateBook(b))
         {
             BookDAO.Edit(b);
             dgvBooks.DataSource = BookDAO.GetDataTable();
             MessageBox.Show("Edit Successful");
             display(0);
             check = 0;
         }
     }
     else if (check == 0)
     {
         check = 3;
         display(8);
     }
     else if (check == 3)
     {
         Book b = new Book();
         b.BookNumber        = (txtBookNumber.Text != "") ? Convert.ToInt32(txtBookNumber.Text) : -1;
         b.Title             = txtTitle.Text;
         b.Authors           = txtAuthors.Text;
         b.Publisher         = txtPublisher.Text;
         dgvBooks.DataSource = BookDAO.SearchBook(b);
         btnAddBook.Enabled  = true;
     }
 }
        public void Return_Book_From_Employee()
        {
            //Arrange
            string  bookId     = "E0";
            int     employeeId = 1;
            BookDAO dao        = new BookDAO();

            //Act
            dao.Add(new Book(bookId, "Libro Prueba", "JNovas"));
            dao.Lend(bookId, employeeId);
            bool status = dao.Return(bookId);

            //Assert
            Assert.That(status, Is.EqualTo(true));
        }