public void RejectLoansControlNotConfirmingLoans() { var ctrl = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao); var ex = Assert.Throws<InvalidOperationException>(() => { ctrl.loansRejected(); }); Assert.Equal("Control state must be set to 'Confirming Loans'", ex.Message); }
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); }
public void CanRejectLoans() { var loan = Substitute.For<ILoan>(); var member = CreateMockIMember(); member.Loans.Returns(new List<ILoan>() { loan }); var ctrl = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao); InitialiseToScanBookPreConditions(ctrl, member); // Set the UI to the mock so we can test var borrowctrl = Substitute.For<ABorrowControl>(); ctrl._ui = borrowctrl; // Set Pre-conditions ctrl._state = EBorrowState.CONFIRMING_LOANS; ctrl._loanList.Add(loan); ctrl._loanList.Add(loan); Assert.NotNull(ctrl); Assert.NotEmpty(ctrl._loanList); Assert.Equal(EBorrowState.CONFIRMING_LOANS, ctrl._state); ctrl.loansRejected(); borrowctrl.Received().DisplayMemberDetails(member.ID, member.ToString(), member.ContactPhone); borrowctrl.Received().DisplayExistingLoan(loan.ToString()); borrowctrl.Received().DisplayPendingLoan(""); borrowctrl.Received().DisplayScannedBookDetails(""); Assert.Empty(ctrl._loanList); Assert.Empty(ctrl._bookList); Assert.Equal(1, ctrl.scanCount); Assert.True(!_reader.Enabled); Assert.True(_scanner.Enabled); Assert.Equal(EBorrowState.SCANNING_BOOKS, ctrl._state); }
public void CanRejectLoans() { var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email"); var existingBook = _bookDao.AddBook("Jim Tulip", "Adventures in Programming 2", "call number"); var existingLoan = _loanDao.CreateLoan(member, existingBook, DateTime.Today, DateTime.Today.AddDays(7)); _loanDao.CommitLoan(existingLoan); var book = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var loan = _loanDao.CreateLoan(member, book, DateTime.Today, DateTime.Today.AddDays(7)); var ctrl = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao); InitialiseToScanBookPreConditions(ctrl, member); // Set the UI to the mock so we can test var borrowctrl = Substitute.For<ABorrowControl>(); ctrl._ui = borrowctrl; // Set Pre-conditions ctrl._state = EBorrowState.CONFIRMING_LOANS; ctrl._loanList.Add(loan); Assert.NotNull(ctrl); Assert.NotEmpty(ctrl._loanList); Assert.Equal(EBorrowState.CONFIRMING_LOANS, ctrl._state); ctrl.loansRejected(); borrowctrl.Received().DisplayMemberDetails(member.ID, member.ToString(), member.ContactPhone); borrowctrl.Received().DisplayExistingLoan(existingLoan.ToString()); borrowctrl.Received().DisplayPendingLoan(""); borrowctrl.Received().DisplayScannedBookDetails(""); Assert.Empty(ctrl._loanList); Assert.Empty(ctrl._bookList); Assert.Equal(1, ctrl.scanCount); Assert.True(!_reader.Enabled); Assert.True(_scanner.Enabled); Assert.Equal(EBorrowState.SCANNING_BOOKS, ctrl._state); }