public void CanCreateLoan() { 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); Assert.NotNull(loan); Assert.Empty(loanDao.LoanList); Assert.Equal(book, loan.Book); Assert.Equal(member, loan.Borrower); Assert.Equal(0, loan.ID); }
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 RunScenario() { var bookDao = new BookDao(new BookHelper()); var loanDao = new LoanDao(new LoanHelper()); var memberDao = new MemberDao(new MemberHelper()); var display = new MainWindow(); var reader = new CardReader(); var scanner = new Scanner(); var printer = new Printer(); var controller = new BorrowController(display, reader, scanner, printer, bookDao, loanDao, memberDao); // Test pre-conditions Assert.NotNull(controller); Assert.NotNull(bookDao); Assert.NotNull(loanDao); Assert.NotNull(memberDao); Assert.NotNull(display); Assert.NotNull(reader); Assert.NotNull(scanner); Assert.NotNull(printer); Assert.Equal(controller._bookDAO, bookDao); Assert.Equal(controller._loanDAO, loanDao); Assert.Equal(controller._memberDAO, memberDao); Assert.Equal(controller._display, display); Assert.Equal(controller._reader, reader); Assert.Equal(controller._scanner, scanner); Assert.Equal(controller._printer, printer); Assert.Equal(controller._reader.Listener, controller); Assert.Equal(controller._scanner.Listener, controller); Assert.Equal(EBorrowState.CREATED, controller._state); // Run use case controller.initialise(); // Test post-conditions // Borrow book UI Displayed Assert.True(display.Display.IsEnabled); var borrowCtrl = ((BorrowControl) display.Display); var swipeCtrl = borrowCtrl._controlDict.Single(c => c.Value is SwipeCardControl).Value as SwipeCardControl; Assert.NotNull(swipeCtrl); Assert.True(swipeCtrl.IsEnabled); Assert.True(swipeCtrl.cancelButton.IsEnabled); Assert.True(reader.Enabled); Assert.True(!scanner.Enabled); Assert.Equal(EBorrowState.INITIALIZED, controller._state); }
public void BookDaoImplementsIBookDAOInterface() { var helper = Substitute.For<IBookHelper>(); var bookDao = new BookDao(helper); Assert.IsAssignableFrom<IBookDAO>(bookDao); var typedMember = bookDao as IBookDAO; Assert.NotNull(typedMember); }
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 CanCreateBookDao() { var helper = Substitute.For<IBookHelper>(); var bookDao = new BookDao(helper); Assert.NotNull(bookDao); }
public void GetBookByTitleReturnsEmptyList() { var helper = Substitute.For<IBookHelper>(); var bookDao = new BookDao(helper); var author = "author"; var title = "title"; var callNo = "callNo"; bookDao.BookList = new List<IBook> { Substitute.For<Book>("one", "two", "three", 1), Substitute.For<Book>(author, title, callNo, 2), Substitute.For<Book>("one", "two", "three", 3), }; var list = bookDao.FindBooksByTitle("The Twits"); Assert.NotNull(list); Assert.Empty(list); }
public void GetBookByIdReturnsNullIfNotFound() { var helper = Substitute.For<IBookHelper>(); var bookDao = new BookDao(helper); bookDao.BookList = new List<IBook> { Substitute.For<Book>("one", "two", "three", 1), Substitute.For<Book>("one", "two", "three", 3), }; var book = bookDao.GetBookByID(2); Assert.Null(book); }
public void CreateBookDaoThrowsExceptionOnNullParameter() { var ex = Assert.Throws<ArgumentException>(() => { var bookDao = new BookDao(null); }); Assert.Equal("Helper must be provided when creating BookDao", ex.Message); }
public void CanGetBookByTitle() { var helper = Substitute.For<IBookHelper>(); var bookDao = new BookDao(helper); var author = "author"; var title = "title"; var callNo = "callNo"; bookDao.BookList = new List<IBook> { Substitute.For<Book>("one", "two", "three", 1), Substitute.For<Book>(author, title, callNo, 2), Substitute.For<Book>("one", "two", "three", 3), }; var book = bookDao.FindBooksByTitle(title).Single(); Assert.NotNull(book); Assert.Equal(2, book.ID); Assert.Equal(author, book.Author); Assert.Equal(title, book.Title); Assert.Equal(callNo, book.CallNumber); }
public void CanGetLoanByBookTitle() { 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.FindLoansByBookTitle(book.Title); 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 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 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]); }