public void CanConfirmLoans()
        {
            var loan = Substitute.For<ILoan>();

            var ctrl = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao);

            // Set the UI to the mock so we can test
            var borrowctrl = Substitute.For<ABorrowControl>();
            ctrl._ui = borrowctrl;

            ctrl.initialise();

            // 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.loansConfirmed();

            _loanDao.Received(2).CommitLoan(loan);

            _printer.Received(2).print(loan.ToString());

            Assert.True(!_reader.Enabled);
            Assert.True(!_scanner.Enabled);
            Assert.Equal(EBorrowState.COMPLETED, ctrl._state);
        }
        public void CanConfirmLoans()
        {
            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, DateTime.Today, DateTime.Today.AddDays(7));

            var ctrl = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao);

            // Set the UI to the mock so we can test
            var borrowctrl = Substitute.For<ABorrowControl>();
            ctrl._ui = borrowctrl;

            ctrl.initialise();

            // 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.loansConfirmed();

            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, ctrl._state);
        }
        public void ConfirmLoansControlNotConfirmingLoans()
        {
            var ctrl = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao);

            var ex = Assert.Throws<InvalidOperationException>(() => { ctrl.loansConfirmed(); });

            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;

            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);
        }