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 SwipeBorrowerCardShowsCurrentLoans()
        {
            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);

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

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

            foreach (var l in member.Loans)
            {
                borrowctrl.Received().DisplayExistingLoan(l.ToString());
            }
        }
        public void SwipeBorrowerCardShowErrorIfMemberHasReachedFinesLimit()
        {
            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);

            member.AddFine(BookConstants.FINE_LIMIT + 1.00f);

            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().DisplayOverFineLimitMessage(member.FineAmount);
        }
Esempio n. 4
0
        public void SwipeBorrowerCardMemberDoesntExist()
        {
            var memberId = 1;

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

            //Test pre-conditions
            Assert.True(ctrl._reader.Enabled);
            Assert.Equal(ctrl, ctrl._reader.Listener);
            Assert.NotNull(ctrl._memberDAO);
            Assert.Equal(EBorrowState.INITIALIZED, ctrl._state);

            _memberDao.GetMemberByID(memberId).Returns((Member)null);

            ctrl.cardSwiped(memberId);

            _memberDao.Received().GetMemberByID(memberId);

            // Test using mocks that it received a Borrower not found error.
            borrowctrl.Received().DisplayErrorMessage("Borrower was not found in database");
        }
Esempio n. 5
0
        public void SwipeBorrowerCardShowErrorIfMemberHasReachedFinesLimit()
        {
            var member = CreateMockIMember();

            member.HasReachedFineLimit.Returns(true);
            member.FineAmount.Returns(100.00f);

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

            //Test pre-conditions
            Assert.True(ctrl._reader.Enabled);
            Assert.Equal(ctrl, ctrl._reader.Listener);
            Assert.NotNull(ctrl._memberDAO);
            Assert.Equal(EBorrowState.INITIALIZED, ctrl._state);

            _memberDao.GetMemberByID(member.ID).Returns(member);

            ctrl.cardSwiped(member.ID);

            _memberDao.Received().GetMemberByID(member.ID);

            borrowctrl.Received().DisplayOverFineLimitMessage(member.FineAmount);
        }
Esempio n. 6
0
        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 RunBookAlreadyScanned()
        {
            // 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._bookList.Add(book);

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

            // 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 has already been scanned", scanBookCtrl.errorMessage.Content);

            Assert.Equal(EBorrowState.SCANNING_BOOKS, controller._state);
        }
Esempio n. 8
0
        public void InitialiseControllerDisablesScanner()
        {
            var ctrl = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao);

            ctrl.initialise();

            Assert.True(!ctrl._scanner.Enabled);
        }
Esempio n. 9
0
        public void InitialiseControllerSetsStateToInitialized()
        {
            var ctrl = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao);

            ctrl.initialise();

            Assert.Equal(EBorrowState.INITIALIZED, ctrl._state);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        public void ScanBookControlNotScanningBooks()
        {
            var ctrl = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao);

            ctrl.initialise();

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

            Assert.Equal("Control state must be set to 'Scanning Books'", ex.Message);
        }
        private void InitialiseToScanBookPreConditions(BorrowController ctrl, IMember member)
        {
            ctrl.initialise();

            ctrl.cardSwiped(member.ID);

            // Test Pre-conditions
            Assert.NotNull(ctrl);
            Assert.NotNull(ctrl._scanner);
            Assert.Equal(ctrl._scanner.Listener, ctrl);
            Assert.Equal(EBorrowState.SCANNING_BOOKS, ctrl._state);
        }
        public void CanSwipeBorrowerCard()
        {
            var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email");

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

            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); // If we get to the end of the method then it hasn't thrown an exception.
        }
        public void SwipeBorrowerCardRestricted()
        {
            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().DisplayMemberDetails(member.ID, member.ToString(), member.ContactPhone);

            borrowctrl.Received().DisplayErrorMessage("Member has been restricted from borrowing");

            foreach (var l in member.Loans)
            {
                borrowctrl.Received().DisplayExistingLoan(l.ToString());
            }

            Assert.Equal(member, ctrl._borrower);
            Assert.True(!ctrl._reader.Enabled);
            Assert.True(!ctrl._scanner.Enabled);
            Assert.Equal(EBorrowState.BORROWING_RESTRICTED, ctrl._state);
        }
Esempio n. 16
0
        public void SwipeBorrowerCardRestricted()
        {
            var member = CreateMockIMember();

            member.HasOverDueLoans.Returns(true);

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

            //Test pre-conditions
            Assert.True(ctrl._reader.Enabled);
            Assert.Equal(ctrl, ctrl._reader.Listener);
            Assert.NotNull(ctrl._memberDAO);
            Assert.Equal(EBorrowState.INITIALIZED, ctrl._state);

            _memberDao.GetMemberByID(member.ID).Returns(member);

            ctrl.cardSwiped(member.ID);

            _memberDao.Received().GetMemberByID(member.ID);

            _reader.Received().Enabled  = false;
            _scanner.Received().Enabled = false;

            borrowctrl.Received().DisplayMemberDetails(member.ID, member.ToString(), member.ContactPhone);

            borrowctrl.Received().DisplayErrorMessage("Member has been restricted from borrowing");

            foreach (var l in member.Loans)
            {
                borrowctrl.Received().DisplayExistingLoan(l.ToString());
            }

            Assert.Equal(member, ctrl._borrower);
            Assert.True(!ctrl._reader.Enabled);
            Assert.True(!ctrl._scanner.Enabled);
            Assert.Equal(EBorrowState.BORROWING_RESTRICTED, ctrl._state);
        }
Esempio n. 17
0
        public void SwipeBorrowerCardShowsCurrentLoans()
        {
            var loan = Substitute.For <ILoan>();

            var member = CreateMockIMember();

            member.Loans.Returns(new List <ILoan>()
            {
                loan, loan, loan
            });

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

            //Test pre-conditions
            Assert.True(ctrl._reader.Enabled);
            Assert.Equal(ctrl, ctrl._reader.Listener);
            Assert.NotNull(ctrl._memberDAO);
            Assert.Equal(EBorrowState.INITIALIZED, ctrl._state);

            _memberDao.GetMemberByID(member.ID).Returns(member);

            ctrl.cardSwiped(member.ID);

            _memberDao.Received().GetMemberByID(member.ID);

            foreach (var l in member.Loans)
            {
                borrowctrl.Received().DisplayExistingLoan(l.ToString());
            }
        }
Esempio n. 18
0
        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);
        }
        public void RunScanCountEqualsLoanLimit()
        {
            // 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.scanCount = BookConstants.LOAN_LIMIT - 1;

            // 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;
            var confirmingLoansCtrl = borrowCtrl._controlDict.Single(c => c.Value is ConfirmLoanControl).Value as ConfirmLoanControl;

            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, controller._borrower);
            Assert.Equal(EBorrowState.SCANNING_BOOKS, controller._state);

            // Run use case
            controller.bookScanned(book.ID);

            // Test Post-conditions
            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.Equal(BookConstants.LOAN_LIMIT, controller.scanCount);

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

            Assert.True(scanBookCtrl.pendingLoanBox.Text.Contains(controller._loanList[0].ToString()));
            Assert.True(confirmingLoansCtrl.confirmLoanBox.Text.Contains(controller._loanList[0].ToString()));

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

            ctrl.initialise(); // If test does not fail to this point it hasn't thrown, so Initialise method has worked.
        }
        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);
        }