public void AddBook(Book book) { //TODO: validate if the user is admin // add new title if the title doesnt already exist if (!bookDao.CheckIfBookTitleExists(book.Title)) { //set default genre to General and default to 100 if (book.Genre.Count == 0) { AddTitle(book.Title, book.Author, book.Rating, book.Price == null ? 100 : book.Price, "General"); } else { AddTitle(book.Title, book.Author, book.Rating, book.Price == null ? 100 : book.Price, book.Genre[0]); //for multiple genres for (int i = 1; i < book.Genre.Count; i++) { bookDao.AddNewGenreToTitle(book.Title, book.Author, book.Genre[i]); } } } else { bookDao.AddBook(book.Title); } }
public void CanAddBook() { var helper = Substitute.For <IBookHelper>(); var bookDao = new BookDao(helper); var author = "author"; var title = "title"; var callNo = "callNo"; // Uses Helper to create a new book with a unique book ID. // Adds the book to a collection of books and returns new book. Assert.Equal(0, bookDao.BookList.Count); // Tell the mock what to return when it is called. helper.MakeBook(author, title, callNo, Arg.Any <int>()).Returns(new Book(author, title, callNo, 1)); var result = bookDao.AddBook(author, title, callNo); // Assert that the mock's MakeBook method was called. helper.Received().MakeBook(author, title, callNo, Arg.Any <int>()); Assert.NotNull(result); Assert.Equal(author, result.Author); Assert.Equal(title, result.Title); Assert.Equal(callNo, result.CallNumber); Assert.Equal(1, bookDao.BookList.Count); var book = bookDao.BookList[0]; Assert.Equal(book, result); }
public void CanCommitLoan() { ILoanHelper loanHelper = new LoanHelper(); ILoanDAO loanDao = new LoanDao(loanHelper); IMemberHelper memberHelper = new MemberHelper(); IMemberDAO memberDao = new MemberDao(memberHelper); IBookHelper bookHelper = new BookHelper(); IBookDAO bookDao = new BookDao(bookHelper); var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = memberDao.AddMember("Jim", "Tulip", "csu phone", "*****@*****.**"); var book = bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var loan = loanDao.CreateLoan(member, book, borrowDate, dueDate); loanDao.CommitLoan(loan); Assert.NotNull(loan); Assert.Equal(1, loanDao.LoanList.Count); Assert.Equal(loan, loanDao.LoanList[0]); Assert.NotEqual(0, loan.ID); }
public void CanUpdateOverdueStatus() { ILoanHelper loanHelper = new LoanHelper(); ILoanDAO loanDao = new LoanDao(loanHelper); IMemberHelper memberHelper = new MemberHelper(); IMemberDAO memberDao = new MemberDao(memberHelper); IBookHelper bookHelper = new BookHelper(); IBookDAO bookDao = new BookDao(bookHelper); var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = memberDao.AddMember("Jim", "Tulip", "csu phone", "*****@*****.**"); var book = bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var loan = loanDao.CreateLoan(member, book, borrowDate, dueDate); loanDao.CommitLoan(loan); Assert.Equal(LoanState.CURRENT, loan.State); loanDao.UpdateOverDueStatus(DateTime.Today.AddMonths(1)); Assert.Equal(LoanState.OVERDUE, loan.State); }
public void CreateBookFailsOnIllegalArguments() { IBookHelper helper = new BookHelper(); IBookDAO dao = new BookDao(helper); var author = "author"; var title = "title"; var callNumber = "call number"; Assert.Throws <ArgumentException>( () => { var book = dao.AddBook(null, title, callNumber); }); Assert.Throws <ArgumentException>( () => { var book = dao.AddBook(author, null, callNumber); }); Assert.Throws <ArgumentException>( () => { var book = dao.AddBook(author, title, null); }); }
public void CanGetOverdueLoans() { ILoanHelper loanHelper = new LoanHelper(); ILoanDAO loanDao = new LoanDao(loanHelper); IMemberHelper memberHelper = new MemberHelper(); IMemberDAO memberDao = new MemberDao(memberHelper); IBookHelper bookHelper = new BookHelper(); IBookDAO bookDao = new BookDao(bookHelper); var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = memberDao.AddMember("Jim", "Tulip", "csu phone", "*****@*****.**"); var book = bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var loan = loanDao.CreateLoan(member, book, borrowDate, dueDate); loanDao.CommitLoan(loan); Assert.Equal(LoanState.CURRENT, loan.State); loanDao.UpdateOverDueStatus(DateTime.Today.AddMonths(1)); Assert.Equal(LoanState.OVERDUE, loan.State); for (int i = 0; i < 10; i++) { var m = memberDao.AddMember("Test", "Test", "Test Phone", "Test Email"); var b = bookDao.AddBook("Test", "Test", "Test"); var l = loanDao.CreateLoan(m, b, borrowDate, dueDate); loanDao.CommitLoan(l); } var overdue = loanDao.FindOverDueLoans(); Assert.Equal(1, overdue.Count); Assert.Equal(loan, overdue[0]); }
public void CanGetBookById() { IBookHelper helper = new BookHelper(); IBookDAO dao = new BookDao(helper); var author = "author"; var title = "title"; var callNumber = "call number"; var book = dao.AddBook(author, title, callNumber); for (int i = 0; i < 10; i++) { dao.AddBook("Test", "Test", "Test"); } var result = dao.GetBookByID(book.ID); Assert.Equal(book, result); }
public void GetBookByAuthorAndTitleReturnsEmptyCollectionIfNotFound() { IBookHelper helper = new BookHelper(); IBookDAO dao = new BookDao(helper); var author = "author"; var title = "title"; var callNumber = "call number"; var book = dao.AddBook(author, title, callNumber); for (int i = 0; i < 10; i++) { dao.AddBook("Test", "Test", "Test"); } var result = dao.FindBooksByAuthorTitle("Jim Tulip", "Adventures in Programming"); Assert.Empty(result); }
public void GetBookByIdReturnsNullIfNotFound() { IBookHelper helper = new BookHelper(); IBookDAO dao = new BookDao(helper); var author = "author"; var title = "title"; var callNumber = "call number"; var book = dao.AddBook(author, title, callNumber); for (int i = 0; i < 10; i++) { dao.AddBook("Test", "Test", "Test"); } var result = dao.GetBookByID(1000); Assert.Null(result); }
public void CreateBookCreatesAUniqueId() { IBookHelper helper = new BookHelper(); IBookDAO dao = new BookDao(helper); var author = "author"; var title = "title"; var callNumber = "call number"; var book = dao.AddBook(author, title, callNumber); Assert.NotEqual(0, book.ID); }
public void CanGetBookByAuthorAndTitle() { IBookHelper helper = new BookHelper(); IBookDAO dao = new BookDao(helper); var author = "author"; var title = "title"; var callNumber = "call number"; var book = dao.AddBook(author, title, callNumber); for (int i = 0; i < 10; i++) { dao.AddBook("Test", "Test", "Test"); } var result = dao.FindBooksByAuthorTitle(book.Author, book.Title); var single = result.Single(); Assert.Equal(book, single); }
public void CanGetLoanByBorrower() { ILoanHelper loanHelper = new LoanHelper(); ILoanDAO loanDao = new LoanDao(loanHelper); IMemberHelper memberHelper = new MemberHelper(); IMemberDAO memberDao = new MemberDao(memberHelper); IBookHelper bookHelper = new BookHelper(); IBookDAO bookDao = new BookDao(bookHelper); var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = memberDao.AddMember("Jim", "Tulip", "csu phone", "*****@*****.**"); var book = bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var loan = loanDao.CreateLoan(member, book, borrowDate, dueDate); loanDao.CommitLoan(loan); for (int i = 0; i < 10; i++) { var m = memberDao.AddMember("Test", "Test", "Test Phone", "Test Email"); var b = bookDao.AddBook("Test", "Test", "Test"); var l = loanDao.CreateLoan(m, b, borrowDate, dueDate); loanDao.CommitLoan(l); } var result = loanDao.FindLoansByBorrower(member); var single = result.Single(); Assert.Equal(loan, single); }
public void GetLoanByLoanIdReturnsNullIfNotFound() { ILoanHelper loanHelper = new LoanHelper(); ILoanDAO loanDao = new LoanDao(loanHelper); IMemberHelper memberHelper = new MemberHelper(); IMemberDAO memberDao = new MemberDao(memberHelper); IBookHelper bookHelper = new BookHelper(); IBookDAO bookDao = new BookDao(bookHelper); var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = memberDao.AddMember("Jim", "Tulip", "csu phone", "*****@*****.**"); var book = bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var loan = loanDao.CreateLoan(member, book, borrowDate, dueDate); loanDao.CommitLoan(loan); for (int i = 0; i < 10; i++) { var m = memberDao.AddMember("Test", "Test", "Test Phone", "Test Email"); var b = bookDao.AddBook("Test", "Test", "Test"); var l = loanDao.CreateLoan(m, b, borrowDate, dueDate); loanDao.CommitLoan(l); } var result = loanDao.GetLoanByID(1000); Assert.Null(result); }
public void AddBookAssignsUniqueID() { var helper = Substitute.For <IBookHelper>(); var bookDao = new BookDao(helper); var author = "author"; var title = "title"; var callNo = "callNo"; // Make sure the id increments as books are added. for (var id = 1; id < 10; id++) { helper.MakeBook(author, title, callNo, id).Returns(new Book(author, title, callNo, id)); var result = bookDao.AddBook(author, title, callNo); // Assert that the mock's MakeBook method was called. helper.Received().MakeBook(author, title, callNo, id); // Make sure the id of the book is new. Assert.Equal(id, result.ID); } }
public void CanCreateBook() { IBookHelper helper = new BookHelper(); var dao = new BookDao(helper); var author = "author"; var title = "title"; var callNumber = "call number"; var book = dao.AddBook(author, title, callNumber); Assert.NotNull(book); Assert.NotEmpty(dao.BookList); Assert.Equal(1, dao.BookList.Count); Assert.Equal(book, dao.BookList[0]); Assert.Equal(author, book.Author); Assert.Equal(title, book.Title); Assert.Equal(callNumber, book.CallNumber); Assert.NotEqual(0, book.ID); }
public int AddBook(Books book) { return(bookDao.AddBook(book)); }