Пример #1
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");
        }
Пример #2
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);
        }
        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);
        }
        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);
        }
Пример #6
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);
        }
Пример #7
0
        public void SwipeBorrowerCardControlNotInitialized()
        {
            var ctrl = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao);

            Assert.Equal(EBorrowState.CREATED, ctrl._state);

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

            Assert.Equal("Controls must be initialised before member's card is swiped", 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);
        }
Пример #11
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);
        }
Пример #12
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());
            }
        }
Пример #13
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 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);
        }
        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);
        }