public void ScanBooksBookScanCountEqualsLoanLimit()
        {
            var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email");

            var book  = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number");
            var book2 = _bookDao.AddBook("Jim Tulip", "Adventures in Programming 2", "call number");

            var borrowDate = DateTime.Today;
            var dueDate    = 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;

            InitialiseToScanBookPreConditions(ctrl, member);

            ctrl.scanCount = BookConstants.LOAN_LIMIT - 2;

            ctrl.bookScanned(book.ID);
            ctrl.bookScanned(book2.ID);

            borrowctrl.Received().DisplayScannedBookDetails(book.ToString());
            borrowctrl.Received().DisplayScannedBookDetails(book2.ToString());

            Assert.Equal(BookConstants.LOAN_LIMIT, ctrl.scanCount);
            Assert.NotNull(ctrl._loanList);
            Assert.NotEmpty(ctrl._loanList);
            Assert.Equal(2, ctrl._loanList.Count);

            borrowctrl.Received().DisplayPendingLoan(ctrl._loanList[0].ToString());
            borrowctrl.Received().DisplayPendingLoan(ctrl._loanList[1].ToString());

            borrowctrl.Received().DisplayConfirmingLoan(ctrl._loanList[0].ToString());
            borrowctrl.Received().DisplayConfirmingLoan(ctrl._loanList[1].ToString());

            Assert.NotNull(ctrl._bookList);
            Assert.NotEmpty(ctrl._bookList);
            Assert.Equal(2, ctrl._bookList.Count);

            Assert.Equal(book, ctrl._bookList[0]);

            Assert.True(!_scanner.Enabled);

            Assert.Equal(EBorrowState.CONFIRMING_LOANS, ctrl._state);
        }
示例#2
0
        public void ScanBooksBookNotAvailable()
        {
            var member = CreateMockIMember();

            var book = Substitute.For <IBook>();

            book.State.Returns(BookState.DISPOSED);

            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;

            InitialiseToScanBookPreConditions(ctrl, member);

            _bookDao.GetBookByID(0).Returns(book);

            ctrl.bookScanned(0);

            _bookDao.Received().GetBookByID(0);

            borrowctrl.Received().DisplayErrorMessage("Book is not available to be borrowed");

            Assert.Equal(EBorrowState.SCANNING_BOOKS, ctrl._state);
        }
        public void ScanBooksBookScanCountLessThanLoanLimit()
        {
            var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email");

            var book = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number");

            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;

            InitialiseToScanBookPreConditions(ctrl, member);

            ctrl.bookScanned(book.ID);

            borrowctrl.Received().DisplayScannedBookDetails(book.ToString());

            Assert.Equal(1, ctrl.scanCount);
            Assert.NotNull(ctrl._loanList);
            Assert.NotEmpty(ctrl._loanList);
            Assert.Equal(1, ctrl._loanList.Count);

            borrowctrl.Received().DisplayPendingLoan(ctrl._loanList[0].ToString());

            Assert.NotNull(ctrl._bookList);
            Assert.NotEmpty(ctrl._bookList);
            Assert.Equal(1, ctrl._bookList.Count);

            Assert.Equal(book, ctrl._bookList[0]);

            Assert.Equal(EBorrowState.SCANNING_BOOKS, ctrl._state);
        }
示例#4
0
        public void ScanBooksBookAlreadyScanned()
        {
            var member = CreateMockIMember();

            var book = Substitute.For <IBook>();

            book.State.Returns(BookState.AVAILABLE);

            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;

            InitialiseToScanBookPreConditions(ctrl, member);

            _bookDao.GetBookByID(0).Returns(book);

            ctrl._bookList.Add(book); // Add the book to the booklist.

            ctrl.bookScanned(0);

            _bookDao.Received().GetBookByID(0);

            borrowctrl.Received().DisplayErrorMessage("Book has already been scanned");

            Assert.Equal(EBorrowState.SCANNING_BOOKS, ctrl._state);
        }
示例#5
0
        public void ScanBooksBookScanCountLessThanLoanLimitClearsPreviousError()
        {
            var member = CreateMockIMember();

            var book = Substitute.For <IBook>();

            book.State.Returns(BookState.AVAILABLE);

            var borrowDate = DateTime.Today;
            var dueDate    = DateTime.Today.AddDays(7);

            var loan = Substitute.For <Loan>(book, member, borrowDate, dueDate);

            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;

            InitialiseToScanBookPreConditions(ctrl, member);

            _bookDao.GetBookByID(0).Returns(book);
            _loanDao.CreateLoan(member, book, borrowDate, dueDate).Returns(loan);

            ctrl.bookScanned(0);

            // Expect the error message to be cleared
            borrowctrl.Received().DisplayErrorMessage("");
        }
        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);
        }
示例#7
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);
        }
        public void CanScanBook()
        {
            var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email");

            var book = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number");

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

            InitialiseToScanBookPreConditions(ctrl, member);

            ctrl.bookScanned(book.ID); // if we get this far we've worked.
        }
示例#9
0
        public void CanScanBook()
        {
            var member = CreateMockIMember();

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

            InitialiseToScanBookPreConditions(ctrl, member);

            // Make the bookDao return a successful read
            _bookDao.GetBookByID(0).Returns(Substitute.For <IBook>());

            ctrl.bookScanned(0); // if we get this far we've worked.
        }
        public void ScanBooksScannerEnabled()
        {
            var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email");

            var book = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number");

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

            InitialiseToScanBookPreConditions(ctrl, member);

            ctrl.bookScanned(book.ID);

            Assert.True(_scanner.Enabled);
        }
示例#11
0
        public void ScanBooksBookScanCountLessThanLoanLimit()
        {
            var member = CreateMockIMember();

            var book = Substitute.For <IBook>();

            book.State.Returns(BookState.AVAILABLE);

            var borrowDate = DateTime.Today;
            var dueDate    = DateTime.Today.AddDays(7);

            var loan = Substitute.For <Loan>(book, member, borrowDate, dueDate);

            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;

            InitialiseToScanBookPreConditions(ctrl, member);

            _bookDao.GetBookByID(0).Returns(book);
            _loanDao.CreateLoan(member, book, borrowDate, dueDate).Returns(loan);

            ctrl.bookScanned(0);

            _bookDao.Received().GetBookByID(0);
            _loanDao.Received().CreateLoan(member, book, borrowDate, dueDate);

            borrowctrl.Received().DisplayScannedBookDetails(book.ToString());

            borrowctrl.Received().DisplayPendingLoan(loan.ToString());

            Assert.Equal(1, ctrl.scanCount);
            Assert.NotNull(ctrl._loanList);
            Assert.NotEmpty(ctrl._loanList);
            Assert.Equal(1, ctrl._loanList.Count);

            Assert.Equal(loan, ctrl._loanList[0]);

            Assert.NotNull(ctrl._bookList);
            Assert.NotEmpty(ctrl._bookList);
            Assert.Equal(1, ctrl._bookList.Count);

            Assert.Equal(book, ctrl._bookList[0]);

            Assert.Equal(EBorrowState.SCANNING_BOOKS, ctrl._state);
        }
示例#12
0
        public void ScanBooksScannerEnabled()
        {
            var member = CreateMockIMember();

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

            InitialiseToScanBookPreConditions(ctrl, member);

            // Make the bookDao return a successful read
            _bookDao.GetBookByID(0).Returns(Substitute.For <IBook>());

            ctrl.bookScanned(0);

            Assert.True(_scanner.Enabled);
        }
        public void ScanBooksBookNotFound()
        {
            var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email");

            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;

            InitialiseToScanBookPreConditions(ctrl, member);

            ctrl.bookScanned(0);

            borrowctrl.Received().DisplayErrorMessage("Book scanned was not found");

            Assert.Equal(EBorrowState.SCANNING_BOOKS, ctrl._state);
        }
        public void ScanBooksBookScanCountLessThanLoanLimitClearsPreviousError()
        {
            var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email");

            var book = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number");

            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;

            InitialiseToScanBookPreConditions(ctrl, member);

            ctrl.bookScanned(book.ID);

            // Expect the error message to be cleared
            borrowctrl.Received().DisplayErrorMessage("");
        }
        public void ScanBooksBookAlreadyScanned()
        {
            var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email");

            var book = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number");

            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;

            InitialiseToScanBookPreConditions(ctrl, member);

            ctrl._bookList.Add(book); // Add the book to the booklist.

            ctrl.bookScanned(book.ID);

            borrowctrl.Received().DisplayErrorMessage("Book has already been scanned");

            Assert.Equal(EBorrowState.SCANNING_BOOKS, ctrl._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);
        }