Beispiel #1
0
        public void GetBooks_Test()
        {
            //Arrange
            Author newAuthor = new Author("Paulo Coelho");

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

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

            newBook1.Save();

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

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

            //Assert
            CollectionAssert.AreEqual(expectedResult, result);
        }
Beispiel #2
0
    public static void Main(string[] args)
    {
        Book     b1 = new Book("1", "Title 1", null);
        Book     b2 = new Book("2", "Title 2", null);
        Book     b3 = new Book("3", "Title 3", null);
        DateTime d1, d2, d3;

        d1 = new DateTime(1976, 11, 18);
        Book b4 = new Book("4", "Title 4", null, d1, "person1");

        d2 = new DateTime(1913, 11, 19);
        Book b5 = new Book("5", "Title 5", null, d2, "person2");

        d3 = new DateTime(2005, 11, 20);
        Book   b6 = new Book("6", "Title 6", null, d3, "person3");
        Author a1 = new Author("fname1", "lname1", "id 1");
        Author a2 = new Author("fname2", "lname2", "id 2");

        a1.DisplayInfo();
        a2.DisplayInfo();
        a1.AddBook(b1);
        a1.AddBook(b3);
        a1.AddBook(b5);
        a1.DisplayBooks();
        a2.AddBook(b2);
        a2.AddBook(b6);
        a2.AddBook(b6);
        a2.DisplayBooks();
        a1.RemoveBook(b1.isbn);
        Console.WriteLine("After removing book....");
        a1.DisplayBooks();
    }
Beispiel #3
0
        public void Test_AddBook_AddsBookToAuthor()
        {
            //Arrange
            Author testAuthor = new Author("Parul");

            testAuthor.Save();

            Book testBook = new Book("The tea");

            testBook.Save();

            Book testBook2 = new Book("The coffee");

            testBook2.Save();

            //Act
            testAuthor.AddBook(testBook);
            testAuthor.AddBook(testBook2);

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

            //Assert
            CollectionAssert.AreEqual(testList, result);
        }
Beispiel #4
0
    public static void Main(string[] args)
    {
        Book     b1 = new Book("1", "Harry Potter", null);
        Book     b2 = new Book("2", "The Great Gatsby", null);
        Book     b3 = new Book("3", "Invisible Man ", null);
        DateTime d1, d2, d3;

        d1 = new DateTime(2010, 1, 18);
        Book b4 = new Book("4", "Don Quixote", null, d1, "person2");

        d2 = new DateTime(2010, 11, 19);
        Book b5 = new Book("5", "Beloved", null, d2, "person6");

        d3 = new DateTime(2010, 11, 20);
        Book   b6 = new Book("6", "To Kill a Mockingbird", null, d3, "person4");
        Author a1 = new Author("J", "Rowling", "id 1");
        Author a2 = new Author("F", "Fitzgerald", "id 2");
        Author a3 = new Author("Ralph", "Ellison", null);

        a1.DisplayInfo();
        a2.DisplayInfo();
        a1.AddBook(b1);
        a1.AddBook(b3);
        a1.AddBook(b5);
        a1.DisplayBooks();
        a2.AddBook(b2);
        a2.AddBook(b6);
        a2.DisplayBooks();
        a1.RemoveBook(b1.isbn);
        Console.WriteLine("After removing the book....");
        a1.DisplayBooks();
    }
Beispiel #5
0
    public static void Main(string[] args)
    {
        Book book1 = new Book("ISBN1", "Title1", new Author("First", "Last"));
        Book book2 = new Book("ISBN2", "Title2", new Author("First", "Last"));
        Book book3 = new Book("ISBN3", "Title3", new Author("First", "Last"));
        Book book4 = new Book("ISBN4", "Title4", new Author("First", "Last"), new DateTime(2011, 02, 21), "John Smith");
        Book book5 = new Book("ISBN5", "Title5", new Author("First", "Last"), new DateTime(1845, 03, 18), "John Appleseed");
        Book book6 = new Book("ISBN6", "Title6", new Author("First", "Last"), new DateTime(2020, 12, 06), "Justin Noble");

        Author author1 = new Author("Gary", "Miles");
        Author author2 = new Author("Abraham", "Lincoln");

        author1.DisplayInfo();
        author2.DisplayInfo();

        author1.AddBook(book1);
        author1.AddBook(book3);
        author1.AddBook(book4);
        author1.DisplayBooks();

        author2.AddBook(book2);
        author2.AddBook(book4);
        author2.AddBook(book6);
        author2.DisplayBooks();

        author1.RemoveBook(book1);
        author1.DisplayBooks();

        Patron patron1 = new Patron("First1", "Last1", "ID1");
        Patron patron2 = new Patron("First2", "Last2", "ID2");
        Patron patron3 = new Patron("First3", "Last3", "ID3");
        Patron patron4 = new Patron("First4", "Last4", "ID4");
        Patron patron5 = new Patron("First5", "Last5", "ID5");

        patron1.AddToRentalCart(book1, new DateTime(2021, 01, 07));

        patron1.AddToRentalCart(book3, DateTime.Today);
        patron1.RemoveFromRentalCart(book3);

        patron1.Display();

        LibraryCollection collection = new LibraryCollection();

        collection.AddPatron(patron1);
        collection.AddPatron(patron2);
        collection.AddPatron(patron3);
        collection.AddPatron(patron4);
        collection.AddPatron(patron5);

        collection.DisplayPatronInfo();

        collection.RemovePatron(patron5);

        collection.DisplayPatronInfo();
    }
Beispiel #6
0
    public static void Main(string[] args)
    {
        Author author1 = new Author("John", "Smith");

        author1.DisplayInfo();

        Author author2 = new Author("Calvin", "Thai");

        author2.DisplayInfo();

        //creating books using first constructor
        Book book1 = new Book("isbn1", "title1", "info1");
        Book book2 = new Book("isbn2", "title2", "info2");
        Book book3 = new Book("isbn3", "title3", "info3");

        //creating books using second constructor
        Book book4 = new Book("isbn4", "title4", "info4", Convert.ToDateTime("01/01/2021"), "publisher4");
        Book book5 = new Book("isbn5", "title5", "info5", Convert.ToDateTime("02/01/2021"), "publisher5");
        Book book6 = new Book("isbn6", "title6", "info6", Convert.ToDateTime("03/01/2021"), "publisher6");

        // assigning author names to authorinfoX
        string authorinfo1 = (author1.FirstName + " " + author1.LastName);

        string authorinfo2 = (author2.FirstName + " " + author2.LastName);

        //modifying AuthorInfo in book class with updated author names
        book1.AuthorInfo = authorinfo1;
        book3.AuthorInfo = authorinfo1;
        book5.AuthorInfo = authorinfo1;

        book2.AuthorInfo = authorinfo2;
        book4.AuthorInfo = authorinfo2;
        book6.AuthorInfo = authorinfo2;

        //adding books to author 1
        author1.AddBook(book1);
        author1.AddBook(book3);
        author1.AddBook(book5);

        author1.DisplayBooks();
        Console.WriteLine("\n");

        //adding books to author 2
        author2.AddBook(book2);
        author2.AddBook(book4);
        author2.AddBook(book6);

        author2.DisplayBooks();
        Console.WriteLine("\n");

        //removing book 1 from list
        author1.RemoveBook("isbn1");
        author1.DisplayBooks();
    }
Beispiel #7
0
        public void GetBooks_ReturnsAllAuthorBooks_BookList()
        {
            //Arrange
            Author testAuthor = new Author("Jane Austen");

            testAuthor.Save();

            Book testBook1 = new Book("Robinhood", "Fiction");

            testBook1.Save();

            Book testBook2 = new Book("History", "Literature");

            testBook2.Save();

            //Act
            testAuthor.AddBook(testBook1);
            List <Book> result   = testAuthor.GetBooks();
            List <Book> testList = new List <Book> {
                testBook1
            };

            //Assert
            CollectionAssert.AreEqual(testList, result);
        }
Beispiel #8
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);
        }
Beispiel #9
0
        public void GetBooks_ReturnsAllAuthorBooks_BookList()
        {
            //Arrange
            Author testAuthor = new Author("Michael");

            testAuthor.Save();

            Book testBook1 = new Book("The author");

            testBook1.Save();

            Book testBook2 = new Book("Common mistakes");

            testBook2.Save();

            //Act
            testAuthor.AddBook(testBook1);
            List <Book> savedBooks = testAuthor.GetBooks();
            List <Book> testList   = new List <Book> {
                testBook1
            };

            //Assert
            CollectionAssert.AreEqual(testList, savedBooks);
        }
        public ActionResult AuthorAddBook(int authorId)
        {
            Author author = Author.Find(authorId);
            Book   book   = Book.Find(Int32.Parse(Request.Form["book-id"]));

            author.AddBook(book);
            return(View("Success"));
        }
Beispiel #11
0
        public ActionResult AddBook(int authorId)
        {
            Author author   = Author.Find(authorId);
            Book   thisBook = Book.Find(Convert.ToInt32(Request.Form["book-id"]));

            author.AddBook(thisBook);
            return(RedirectToAction("Index"));
        }
        public ActionResult AddBook(int authorId, int bookId)
        {
            Author author = Author.Find(authorId);
            Book   book   = Book.Find(bookId);

            author.AddBook(book);
            return(RedirectToAction("Show", new { id = authorId }));
        }
Beispiel #13
0
        public ActionResult AddABook(int authorId)
        {
            Author author = Author.Find(authorId);
            Book   book   = Book.Find(Int32.Parse(Request.Form["book-id"]));

            author.AddBook(book);
            return(RedirectToAction("AuthorDetails", new { id = authorId }));
        }
Beispiel #14
0
        public void Methods_AddBook_ThrowsArgumentNullException()
        {
            var books  = new List <Book>();
            var author = new Author("Mau", "Petrini", DateTime.Now, books);

            var exception =
                Assert.Throws <ArgumentNullException>(() => author.AddBook(null));

            Assert.Contains("Book cannot be null", exception.Message);
        }
Beispiel #15
0
        public Task <bool> Handle(AddNewAuthorCommand request, CancellationToken cancellationToken)
        {
            var author = new Author(request.Name);

            foreach (var book in request.Books)
            {
                author.AddBook(book.Name);
            }
            _authorRepository.Add(author);
            return(_authorRepository.UnitOfWork.SaveEntitiesAsync());
        }
        public void Test_AddBook_AddsBookToAuthor()
        {
            Author testAuthor = new Author("Household chores");

            testAuthor.Save();
            Book testBook = new Book("Mow the lawn");

            testBook.Save();
            Book testBook2 = new Book("Water the garden");

            testBook2.Save();
            testAuthor.AddBook(testBook);
            testAuthor.AddBook(testBook2);
            List <Book> result   = testAuthor.GetBooks();
            List <Book> testList = new List <Book> {
                testBook, testBook2
            };

            CollectionAssert.AreEqual(testList, result);
        }
Beispiel #17
0
        public static void EnsureSeedDataForContext(this LibraryContext context)
        {
            context.Books.RemoveRange(context.Books);
            context.Authors.RemoveRange(context.Authors);

            var authors = new List <Author>();
            var books   = new List <Book>();

            var author = new Author("Stephen", "King", new DateTimeOffset(new DateTime(1947, 9, 21)), "Horror");

            var book = new Book("The Shining");

            book.AddDescription("The Shining is a horror novel by American author Stephen King. Published in 1977, it is King's third published novel and first hardback bestseller: the success of the book firmly established King as a preeminent author in the horror genre. ");
            book.AddAuthor(author);
            author.AddBook(book);

            book = new Book("It");
            book.AddDescription("It is a 1986 horror novel by American author Stephen King. The story follows the exploits of seven children as they are terrorized by the eponymous being, which exploits the fears and phobias of its victims in order to disguise itself while hunting its prey. 'It' primarily appears in the form of a clown in order to attract its preferred prey of young children.");
            book.AddAuthor(author);
            author.AddBook(book);

            authors.Add(author);

            author = new Author("George", "RR Martin", new DateTimeOffset(new DateTime(1948, 9, 20)), "Fantasy");
            book   = new Book("Game of Thrones");
            book.AddDescription("Game of Thrones is the first novel in A Song of Ice and Fire, a series of fantasy novels by American author George R. R. Martin. It was first published on August 1, 1996.");
            book.AddAuthor(author);
            author.AddBook(book);

            book = new Book("The Winds of Winter");
            book.AddDescription("Forthcoming 6th novel in A Song of Ice and Fire.");
            book.AddAuthor(author);
            author.AddBook(book);

            authors.Add(author);

            context.Authors.AddRange(authors);
            context.Books.AddRange(books);
            context.SaveChanges();
        }
Beispiel #18
0
        public void GetBooks_RetrievesAllBooksWithAuthor_BookList()
        {
            //Arrange, Act
            Author testAuthor = new Author("George Orwell");

            testAuthor.Save();
            Book firstBook = new Book("1984");

            firstBook.Save();
            testAuthor.AddBook(firstBook);
            Book secondBook = new Book("animal farm");

            secondBook.Save();
            testAuthor.AddBook(secondBook);
            List <Book> testBookList = new List <Book> {
                firstBook, secondBook
            };
            List <Book> resultBookList = testAuthor.GetBooks();

            //Assert
            CollectionAssert.AreEqual(testBookList, resultBookList);
        }
Beispiel #19
0
        public void Methods_AddBook_BookAdded()
        {
            //Arrange
            var books  = new List <Book>();
            var author = new Author("Mau", "Petrini", DateTime.Now, books);

            var book = new Book("Book 1", "Book description", 2019);

            //Act
            author.AddBook(book);

            //Assert
            Assert.Equal(1, author.Books.Count);
        }
Beispiel #20
0
        public void GetBooks_ReturnsAllAuthorBooks_BookList()
        {
            //Arrange
            Author testAuthor = new Author("Household chores");

            testAuthor.Save();
            Book testBook1 = new Book("Mow the lawn");

            testBook1.Save();
            Book testBook2 = new Book("Buy plane ticket");

            testBook2.Save();

            //Act
            testAuthor.AddBook(testBook1);
            testAuthor.AddBook(testBook2);
            List <Book> savedBooks = testAuthor.GetBooks();
            List <Book> testList   = new List <Book> {
                testBook1, testBook2
            };

            //Assert
            CollectionAssert.AreEqual(testList, savedBooks);
        }
Beispiel #21
0
        public ActionResult AddBook(int authorId, int bookAdded)
        {
            Dictionary <string, object> model = new Dictionary <string, object>();
            Author selectedAuthor             = Author.Find(authorId);
            Book   book = Book.Find(bookAdded);

            selectedAuthor.AddBook(book);
            List <Book> authorBooks = Author.GetBooks(authorId);
            List <Book> allBooks    = Book.GetAll();

            model.Add("authorBooks", authorBooks);
            model.Add("allBooks", allBooks);
            model.Add("author", selectedAuthor);
            return(View("Show", model));
        }
Beispiel #22
0
        public void Test_AddBook_AddsBookToAuthor()
        {
            //Arrange
            Author testAuthor = new Author("George Orwell");

            testAuthor.Save();
            Book testBook = new Book("1984");

            testBook.Save();
            Book testBook2 = new Book("Animal Farm");

            testBook2.Save();

            //Act
            testAuthor.AddBook(testBook);
            testAuthor.AddBook(testBook2);
            List <Book> result   = testAuthor.GetBooks();
            List <Book> testList = new List <Book> {
                testBook, testBook2
            };

            //Assert
            CollectionAssert.AreEqual(testList, result);
        }
        public static Author ToDomain(this AuthorDTO authorDTO)
        {
            var author = new Author();

            author.SetName(authorDTO.Name);

            foreach (var bookDTO in authorDTO.BookDTOs)
            {
                var book = new Book();
                book.SetName(bookDTO.Name);

                author.AddBook(book);
            }

            return(author);
        }
        public void Delete_DeletesAuthorAssociationsFromDatabase_AuthorList()
        {
            Book testBook = new Book("Mow the lawn");

            testBook.Save();
            string testName   = "Home stuff";
            Author testAuthor = new Author(testName);

            testAuthor.Save();
            testAuthor.AddBook(testBook);
            testAuthor.Delete();
            List <Author> resultBookCategories = testBook.GetAuthors();
            List <Author> testBookCategories   = new List <Author> {
            };

            CollectionAssert.AreEqual(testBookCategories, resultBookCategories);
        }
Beispiel #25
0
        public void AddBook_AddsNewBookToDatabase_List()
        {
            Book newBook = new Book("Harry Potter");

            newBook.Save();

            Author newAuthor = new Author("JK Rowling");

            newAuthor.Save();

            newAuthor.AddBook(newBook);

            var expected = new List <Book>()
            {
                newBook
            };
            var actual = newAuthor.GetBooks();

            CollectionAssert.AreEqual(expected, actual);
        }
Beispiel #26
0
        public void AddBook_AddBookToAuthor_ListBooks()
        {
            Author newAuthor = new Author("George RR");

            newAuthor.Save();

            DateTime testPublishDate = DateTime.Now;
            Book     newBook         = new Book("Bible", "History", testPublishDate);

            newBook.Save();

            newAuthor.AddBook(newBook);

            List <Book> expected = new List <Book> {
                newBook
            };
            List <Book> actual = newAuthor.GetBooks();

            CollectionAssert.AreEqual(expected, actual);
        }
Beispiel #27
0
        public void Delete_DeletesAuthorAssociationsFromDatabase_AuthorList()
        {
            //Arrange
            Book testBook = new Book("1984");

            testBook.Save();
            string testName   = "MR author";
            Author testAuthor = new Author("MR author");

            testAuthor.Save();

            //Act
            testAuthor.AddBook(testBook);
            testAuthor.Delete();
            List <Author> resultBookAuthors = testBook.GetAuthors();
            List <Author> testBookAuthors   = new List <Author> {
            };

            //Assert
            CollectionAssert.AreEqual(testBookAuthors, resultBookAuthors);
        }
Beispiel #28
0
        public void AddBook_AddsbooktoAuthor()
        {
            //Arrange
            Book testBook = new Book("Learn How To", "Education", 1);

            testBook.Save();
            Author testAuthor = new Author("K. Cobain");

            testAuthor.Save();

            //Act
            testAuthor.AddBook(testBook);

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

            //Assert
            CollectionAssert.AreEqual(testList, result);
        }
Beispiel #29
0
        public void AddBook_AddsBookToAuthor_BookList()
        {
            //Arrange
            Author testAuthor = new Author("Jane Austen");

            testAuthor.Save();

            Book testBook = new Book("Robinhood", "Fiction");

            testBook.Save();

            //Act
            testAuthor.AddBook(testBook);

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

            //Assert
            CollectionAssert.AreEqual(testList, result);
        }
        static void Main(string[] args)
        {
            var optionsBuilder = new DbContextOptionsBuilder <BookstoreDbContext>();

            optionsBuilder.UseSqlServer(ConnectionString);

            var context = new BookstoreDbContext(optionsBuilder.Options);

            context.Database.Migrate();

            var saeedGanji = Author.Create("Saeed", "Ganji", new DateTime(1985, 1, 1));

            context.Authors.Add(saeedGanji);
            context.SaveChanges();

            //
            // context.Database.Migrate();
            // context.Database.EnsureCreated();
            //
            // var me = Author.Create("Saeed", "Ganji", DateTime.Now.AddDays(-1));
            // me.AddBook("EF Core" , "132465");
            //
            // var other = Author.Create("John", "Doe", DateTime.Now.AddDays(-1));
            // other.AddBook("No Idea", "132465");
            //
            // context.Authors.AddRange(me,other);
            //
            // context.SaveChanges();

            Author me = null;

            // mention AsNoTracking in the article
            me = context.Authors.AsNoTracking().FirstOrDefault(x => x.FirstName == "Saeed");
            me.AddBook("SampleBook", "1234567-890");

            context.SaveChanges();

            Console.WriteLine(context.Entry(me).Property("CreatedOn").CurrentValue);
        }