public void RunBookNotFound() { // Some test data initialisation var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email"); var existingBook = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var existingLoan = _loanDao.CreateLoan(member, existingBook, borrowDate, dueDate); _loanDao.CommitLoan(existingLoan); // Set up var controller = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao); controller.initialise(); controller.cardSwiped(member.ID); // Test Pre-conditions Assert.True(_display.Display.IsEnabled); var borrowCtrl = ((BorrowControl)_display.Display); var scanBookCtrl = borrowCtrl._controlDict.Single(c => c.Value is ScanBookControl).Value as ScanBookControl; Assert.NotNull(scanBookCtrl); Assert.True(scanBookCtrl.IsEnabled); Assert.True(scanBookCtrl.cancelButton.IsEnabled); Assert.True(scanBookCtrl.completeButton.IsEnabled); Assert.True(!_reader.Enabled); Assert.True(_scanner.Enabled); Assert.Equal(controller, _scanner.Listener); Assert.Equal(member.Loans.Count, controller.scanCount); Assert.Equal(member, controller._borrower); Assert.Equal(EBorrowState.SCANNING_BOOKS, controller._state); // Run use case controller.bookScanned(5); // Test Post-conditions Assert.True(scanBookCtrl.IsEnabled); Assert.True(scanBookCtrl.cancelButton.IsEnabled); Assert.True(scanBookCtrl.completeButton.IsEnabled); Assert.True(!_reader.Enabled); Assert.True(_scanner.Enabled); Assert.Equal("Book scanned was not found", scanBookCtrl.errorMessage.Content); Assert.Equal(EBorrowState.SCANNING_BOOKS, controller._state); }
public void RunMemberExistsAndNotRestricted() { // Set up var controller = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao); controller.initialise(); // Some test data initialisation var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email"); var book = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var loan = _loanDao.CreateLoan(member, book, borrowDate, dueDate); _loanDao.CommitLoan(loan); // Test Pre-conditions Assert.True(_display.Display.IsEnabled); var borrowCtrl = ((BorrowControl)_display.Display); var swipeCtrl = borrowCtrl._controlDict.Single(c => c.Value is SwipeCardControl).Value as SwipeCardControl; var scanBookCtrl = borrowCtrl._controlDict.Single(c => c.Value is ScanBookControl).Value as ScanBookControl; Assert.NotNull(swipeCtrl); Assert.True(swipeCtrl.IsEnabled); Assert.True(swipeCtrl.cancelButton.IsEnabled); Assert.True(_reader.Enabled); Assert.Equal(controller, _reader.Listener); Assert.NotNull(controller._memberDAO); Assert.Equal(EBorrowState.INITIALIZED, controller._state); // Run use case controller.cardSwiped(member.ID); // Test Post-conditions Assert.NotNull(scanBookCtrl); Assert.True(scanBookCtrl.IsEnabled); Assert.True(scanBookCtrl.cancelButton.IsEnabled); Assert.True(scanBookCtrl.completeButton.IsEnabled); Assert.True(!_reader.Enabled); Assert.True(_scanner.Enabled); Assert.Equal(member.ID, scanBookCtrl.idLabel.Content); Assert.Equal($"{member.FirstName} {member.LastName}", scanBookCtrl.nameLabel.Content.ToString()); Assert.Equal(member.Loans[0].ToString(), scanBookCtrl.existingLoanBox.Text); // Test one existing loan is present Assert.Equal(member.Loans.Count, controller.scanCount); Assert.Equal(member, controller._borrower); Assert.Equal(EBorrowState.SCANNING_BOOKS, controller._state); }
public void SwipeBorrowerCardShowErrorIfMemberHasOverdueLoans() { var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email"); var book = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var loan = _loanDao.CreateLoan(member, book, borrowDate, dueDate); _loanDao.CommitLoan(loan); _loanDao.UpdateOverDueStatus(DateTime.Today.AddMonths(1)); var ctrl = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao); // Set the UI to the mock so we can test calls being made var borrowctrl = Substitute.For <ABorrowControl>(); ctrl._ui = borrowctrl; ctrl.initialise(); //Test pre-conditions Assert.True(ctrl._reader.Enabled); Assert.Equal(ctrl, ctrl._reader.Listener); Assert.NotNull(ctrl._memberDAO); Assert.Equal(EBorrowState.INITIALIZED, ctrl._state); ctrl.cardSwiped(member.ID); borrowctrl.Received().DisplayOverDueMessage(); }
public void loansConfirmed() { if (_state != EBorrowState.CONFIRMING_LOANS) { throw new InvalidOperationException("Control state must be set to 'Confirming Loans'"); } foreach (var loan in _loanList) { _loanDAO.CommitLoan(loan); _printer.print(loan.ToString()); } _reader.Enabled = false; _scanner.Enabled = false; setState(EBorrowState.COMPLETED); this.close(); }
public void RunScenario() { // Some test data initialisation var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email"); var existingBook = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var existingLoan = _loanDao.CreateLoan(member, existingBook, borrowDate, dueDate); _loanDao.CommitLoan(existingLoan); var book = _bookDao.AddBook("Jim Tulip", "Adventures in Programming 2", "call number"); // Set up var controller = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao); controller.initialise(); controller.cardSwiped(member.ID); controller.bookScanned(book.ID); controller.scansCompleted(); // Test Pre-conditions Assert.True(_display.Display.IsEnabled); var borrowCtrl = ((BorrowControl)_display.Display); var confirmingLoansCtrl = borrowCtrl._controlDict.Single(c => c.Value is ConfirmLoanControl).Value as ConfirmLoanControl; Assert.NotNull(confirmingLoansCtrl); Assert.True(confirmingLoansCtrl.IsEnabled); Assert.True(confirmingLoansCtrl.cancelButton.IsEnabled); Assert.True(confirmingLoansCtrl.rejectButton.IsEnabled); Assert.True(!_reader.Enabled); Assert.True(!_scanner.Enabled); Assert.NotNull(controller._loanList); Assert.NotEmpty(controller._loanList); Assert.Equal(1, controller._loanList.Count); Assert.Equal(book, controller._loanList[0].Book); Assert.Equal(member, controller._loanList[0].Borrower); var loan = controller._loanList[0]; Assert.NotNull(controller._bookList); Assert.NotEmpty(controller._bookList); Assert.Equal(1, controller._bookList.Count); Assert.Equal(book, controller._bookList[0]); Assert.Equal(EBorrowState.CONFIRMING_LOANS, controller._state); // Run use case controller.loansConfirmed(); // Test Post-conditions Assert.True(borrowCtrl.IsEnabled); Assert.Equal(LoanState.CURRENT, loan.State); Assert.Equal(loan.ToString() + "\n\n", ((Printer)_printer).printBox.Text); Assert.True(!_reader.Enabled); Assert.True(!_scanner.Enabled); Assert.Equal(EBorrowState.COMPLETED, controller._state); }
private void SetUpTestData() { IBook[] book = new IBook[15]; IMember[] member = new IMember[6]; book[0] = _bookDAO.AddBook("author1", "title1", "callNo1"); book[1] = _bookDAO.AddBook("author1", "title2", "callNo2"); book[2] = _bookDAO.AddBook("author1", "title3", "callNo3"); book[3] = _bookDAO.AddBook("author1", "title4", "callNo4"); book[4] = _bookDAO.AddBook("author2", "title5", "callNo5"); book[5] = _bookDAO.AddBook("author2", "title6", "callNo6"); book[6] = _bookDAO.AddBook("author2", "title7", "callNo7"); book[7] = _bookDAO.AddBook("author2", "title8", "callNo8"); book[8] = _bookDAO.AddBook("author3", "title9", "callNo9"); book[9] = _bookDAO.AddBook("author3", "title10", "callNo10"); book[10] = _bookDAO.AddBook("author4", "title11", "callNo11"); book[11] = _bookDAO.AddBook("author4", "title12", "callNo12"); book[12] = _bookDAO.AddBook("author5", "title13", "callNo13"); book[13] = _bookDAO.AddBook("author5", "title14", "callNo14"); book[14] = _bookDAO.AddBook("author5", "title15", "callNo15"); member[0] = _memberDAO.AddMember("fName1", "lName1", "0001", "email1"); member[1] = _memberDAO.AddMember("fName2", "lName2", "0002", "email2"); member[2] = _memberDAO.AddMember("fName3", "lName3", "0003", "email3"); member[3] = _memberDAO.AddMember("fName4", "lName4", "0004", "email4"); member[4] = _memberDAO.AddMember("fName5", "lName5", "0005", "email5"); member[5] = _memberDAO.AddMember("fName6", "lName6", "0006", "email6"); DateTime borrowDate = DateTime.Now; TimeSpan loanPeriod = new TimeSpan(LoanConstants.LOAN_PERIOD, 0, 0, 0); DateTime dueDate = borrowDate.Add(loanPeriod); //create a member with overdue loans for (int i = 0; i < 2; i++) { ILoan loan = _loanDAO.CreateLoan(member[1], book[i], borrowDate, dueDate); _loanDAO.CommitLoan(loan); } DateTime checkDate = dueDate.Add(new TimeSpan(1, 0, 0, 0)); _loanDAO.UpdateOverDueStatus(checkDate); //create a member with maxed out unpaid fines member[2].AddFine(10.0f); //create a member with maxed out loans for (int i = 2; i < 7; i++) { ILoan loan = _loanDAO.CreateLoan(member[3], book[i], borrowDate, dueDate); _loanDAO.CommitLoan(loan); } //a member with a fine, but not over the limit member[4].AddFine(5.0f); //a member with a couple of loans but not over the limit for (int i = 7; i < 9; i++) { ILoan loan = _loanDAO.CreateLoan(member[5], book[i], borrowDate, dueDate); _loanDAO.CommitLoan(loan); } }
public void RunScenario() { // Some test data initialisation var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email"); var existingBook = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var existingLoan = _loanDao.CreateLoan(member, existingBook, borrowDate, dueDate); _loanDao.CommitLoan(existingLoan); var book = _bookDao.AddBook("Jim Tulip", "Adventures in Programming 2", "call number"); // Set up var controller = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao); controller.initialise(); controller.cardSwiped(member.ID); controller.bookScanned(book.ID); controller.scansCompleted(); // Test Pre-conditions Assert.True(_display.Display.IsEnabled); var borrowCtrl = ((BorrowControl)_display.Display); var confirmingLoansCtrl = borrowCtrl._controlDict.Single(c => c.Value is ConfirmLoanControl).Value as ConfirmLoanControl; var scanBookCtrl = borrowCtrl._controlDict.Single(c => c.Value is ScanBookControl).Value as ScanBookControl; Assert.NotNull(confirmingLoansCtrl); Assert.True(confirmingLoansCtrl.IsEnabled); Assert.True(confirmingLoansCtrl.cancelButton.IsEnabled); Assert.True(confirmingLoansCtrl.rejectButton.IsEnabled); Assert.True(!_reader.Enabled); Assert.True(!_scanner.Enabled); Assert.NotNull(controller._loanList); Assert.NotEmpty(controller._loanList); Assert.Equal(1, controller._loanList.Count); Assert.Equal(book, controller._loanList[0].Book); Assert.Equal(member, controller._loanList[0].Borrower); var loan = controller._loanList[0]; Assert.NotNull(controller._bookList); Assert.NotEmpty(controller._bookList); Assert.Equal(1, controller._bookList.Count); Assert.Equal(book, controller._bookList[0]); Assert.Equal(EBorrowState.CONFIRMING_LOANS, controller._state); // Run use case controller.loansRejected(); // Test Post-conditions Assert.NotNull(scanBookCtrl); Assert.True(scanBookCtrl.IsEnabled); Assert.True(scanBookCtrl.cancelButton.IsEnabled); Assert.True(scanBookCtrl.completeButton.IsEnabled); Assert.True(!_reader.Enabled); Assert.True(_scanner.Enabled); Assert.Equal(controller, _scanner.Listener); Assert.Equal(member.Loans.Count, controller.scanCount); Assert.Equal(member, controller._borrower); Assert.Equal(EBorrowState.SCANNING_BOOKS, controller._state); Assert.Equal(member.ID, scanBookCtrl.idLabel.Content); Assert.Equal($"{member.FirstName} {member.LastName}", scanBookCtrl.nameLabel.Content.ToString()); Assert.Equal(member.Loans[0].ToString(), scanBookCtrl.existingLoanBox.Text); // Test one existing loan is present Assert.Equal("", scanBookCtrl.pendingLoanBox.Text); Assert.Equal("", scanBookCtrl.currentbookBox.Text); Assert.NotNull(controller._bookList); Assert.Empty(controller._bookList); Assert.NotNull(controller._loanList); Assert.Empty(controller._loanList); Assert.Equal(1, controller.scanCount); }