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 RunMemberExistsAndRestricted() { // 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); // Make the loan overdue to put member on restricted status _loanDao.UpdateOverDueStatus(DateTime.Today.AddMonths(1)); // 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 restrictedCtrl = borrowCtrl._controlDict.Single(c => c.Value is RestrictedControl).Value as RestrictedControl; 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(restrictedCtrl); Assert.True(restrictedCtrl.IsEnabled); Assert.True(restrictedCtrl.cancelButton.IsEnabled); Assert.True(!_reader.Enabled); Assert.True(!_scanner.Enabled); Assert.Equal(member.ID, restrictedCtrl.idLabel.Content); Assert.Equal($"{member.FirstName} {member.LastName}", restrictedCtrl.nameLabel.Content.ToString()); Assert.Equal(member.Loans[0].ToString(), restrictedCtrl.existingLoanBox.Text); // Test one existing loan is present Assert.Equal("Borrower has overdue loans", restrictedCtrl.overDueLoanLabel.Content); Assert.Equal("Member has been restricted from borrowing", restrictedCtrl.errorMessage.Content); Assert.Equal(member, controller._borrower); Assert.Equal(EBorrowState.BORROWING_RESTRICTED, 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); } }