Пример #1
0
        public void GetBooks_Test()
        {
            //Arrange
            Patron newPatron = new Patron("Paulo Coelho");

            newPatron.Save();
            Book newBook = new Book("The Future is Mine", 8);

            newBook.Save();
            Book newBook1 = new Book("I Don't Remember", 3);

            newBook1.Save();

            //Act
            newPatron.AddBook(newBook);
            newPatron.AddBook(newBook1);

            List <Book> expectedResult = new List <Book> {
                newBook, newBook1
            };
            List <Book> result = newPatron.GetBooks();

            //Assert
            CollectionAssert.AreEqual(expectedResult, result);
        }
Пример #2
0
        public void Delete_RemovesBookFromDatabase_Void()
        {
            //Arrange
            Book testBook = new Book("Jaws", "FICTION BENCHLEY 1991", "Jaw1", DateTime.Today, DateTime.Today);

            testBook.Save();
            Book testBook2 = new Book("It", "FICTION KING", "It1", DateTime.Today, DateTime.Today);

            testBook2.Save();
            Patron testPatron = new Patron("Peter", "Benchley", "*****@*****.**", 1004);

            testPatron.Save();
            Author testAuthor = new Author("Stephen", "King");

            testAuthor.Save();

            testPatron.AddBook(testBook);
            testAuthor.AddBook(testBook);

            //Act
            testBook.Delete();
            List <Book> allBooks        = Book.GetAll();
            List <Book> testPatronBooks = testPatron.GetBooks();
            List <Book> testAuthorBooks = testAuthor.GetBooks();

            //Assert
            Assert.AreEqual(1, allBooks.Count);
            Assert.AreEqual(0, testPatronBooks.Count);
            Assert.AreEqual(0, testAuthorBooks.Count);
        }
        public ActionResult AddBook(int patronId, int bookId)
        {
            Patron patron = Patron.Find(patronId);
            Book   book   = Book.Find(bookId);

            patron.AddBook(book);
            return(RedirectToAction("Show", new { id = patronId }));
        }
Пример #4
0
        public void AddABookToAPatron()
        {
            //Arrange
            Patron testPatron = new Patron("Beavis");

            testPatron.Save();
            Book testBook = new Book("A tale of Two Cities", "non-fiction", 2);

            testBook.Save();

            //Act
            testPatron.AddBook(testBook);

            List <Book> result   = testPatron.GetBooks();
            List <Book> testList = new List <Book> {
                testBook
            };

            //Assert
            CollectionAssert.AreEqual(testList, result);
        }