コード例 #1
0
        public void CanSwipeBorrowerCard()
        {
            var member = CreateMockIMember();

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

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

            ctrl.cardSwiped(member.ID); // If we get to the end of the method then it hasn't thrown an exception.
        }
コード例 #2
0
        public void ScanningABook_ThatCanBeBorrowed_ShouldBeAddedToPendingLoans(
            IEventAggregator eventAggregator
            , [Frozen] IBookDAO bookDao
            , ILoanDAO loanDao
            , IMemberDAO memberDao
            , ScanBookModel scanBookModel
            , ScanBookViewModel viewModel
            , Book book
            , IBorrowingModel borrowingModel
            , Member borrower
            , List<ILoan> loanList )
        {
            var fixture = new Fixture();
            var loan = fixture.Build<Loan>()
                .FromFactory(() => new Loan(book, borrower, DateTime.Today, DateTime.Today.AddDays(10)))
                .Create();


            eventAggregator.GetEvent<ScanningRecievedEvent>().Returns(new ScanningRecievedEvent());
            eventAggregator.GetEvent<BorrowingStateEvent>().Returns(new BorrowingStateEvent());
            eventAggregator.GetEvent<ScanningEvent>().Returns(new ScanningEvent());

            // Arrange - Setup book on loan.
            bookDao.GetBookByID(scanBookModel.Barcode).Returns(book);

            // We are currently in the scanning book state.
            borrowingModel.BorrowingState.Returns(EBorrowState.SCANNING_BOOKS);

            // Establish the current user identified on borrowing model, and returned from member dao.
            borrowingModel.ID = borrower.ID;
            memberDao.GetMemberByID(borrower.ID).Returns(borrower);

            // Configure mapping.
            AutoMapperConfig.RegisterMaps();

            loanDao.LoanList.Returns(loanList);

            var controller = new ScanBookController(eventAggregator)
            {
                BookDao = bookDao,
                LoanDao = loanDao,
                MemberDao = memberDao,
                ViewModel = viewModel
            };

            loanDao.CreateLoan(borrower, book, Arg.Any<DateTime>(), Arg.Any<DateTime>()).Returns(loan);

            controller.ScanBook(borrowingModel);

            // Act -Scan a book.
            controller.Scanning(scanBookModel);

            // Assert - Results in an error message.
            viewModel.PendingLoans.Should().NotBeNullOrEmpty();
        }
コード例 #3
0
        public void ScanningABook_ThatsAlreadyScanned_ResultsInAlreadyScannedError(IEventAggregator eventAggregator
            , IBookDAO bookDao
            , [Frozen] IBook book
            , ILoanDAO loanDao
            , IMemberDAO memberDao
            , ScanBookModel scanBookModel
            , IBorrowingModel borrowingModel
            , ScanBookViewModel viewModel
            , List<ILoan> loanList
            , [Frozen] Member borrower)
        {
            // Arrange - Setup a book that has already been scanned.

            // Mock the events.
            eventAggregator.GetEvent<BorrowingStateEvent>().Returns(new BorrowingStateEvent());
            eventAggregator.GetEvent<ScanningRecievedEvent>().Returns(new ScanningRecievedEvent());
            eventAggregator.GetEvent<ScanningEvent>().Returns(new ScanningEvent());

            // We are currently in the scanning book state.
            borrowingModel.BorrowingState.Returns(EBorrowState.SCANNING_BOOKS);

            // Establish the current user identified on borrowing model, and returned from member dao.
            borrowingModel.ID = borrower.ID;
            memberDao.GetMemberByID(borrower.ID).Returns(borrower);

            // Configure mapping.
            AutoMapperConfig.RegisterMaps();


            // One of the loans in the loan list has a status of pending for the current borrower.
            var existingLoan = loanList.First();
            existingLoan.State.Returns(LoanState.PENDING);
            existingLoan.Borrower.Returns(borrower);

            // The loan Dao returns this loan list when requested
            loanDao.LoanList.Returns(loanList);

            // The book to be scanned is the same book as already scanned.
            bookDao.GetBookByID(scanBookModel.Barcode).Returns(existingLoan.Book);

            // The book is available for loan.
            existingLoan.Book.State.Returns(BookState.AVAILABLE);

            var controller = new ScanBookController(eventAggregator)
            {
                BookDao = bookDao,
                LoanDao = loanDao,
                MemberDao = memberDao,
                ViewModel = viewModel
            };

            // Prepare Scanner
            controller.ScanBook(borrowingModel);


            // Act -Scan a book.
            controller.Scanning(scanBookModel);

            // Assert - Already scanned error message appears.
            viewModel.ErrorMessage.Should().Be($"Book {existingLoan.Book.ID} already scanned ");
        }
コード例 #4
0
        public void cardSwiped(int memberID)
        {
            if (_state != EBorrowState.INITIALIZED)
            {
                throw new InvalidOperationException("Controls must be initialised before member's card is swiped");
            }

            var member = _memberDAO.GetMemberByID(memberID);

            if (member == null)
            {
                _ui.DisplayErrorMessage("Borrower was not found in database");
                return;
            }

            var hasOverdueLoans     = member.HasOverDueLoans;
            var hasReachedLoanLimit = member.HasReachedLoanLimit;
            var hasReachedFineLimit = member.HasReachedFineLimit;

            if (hasOverdueLoans || hasReachedLoanLimit || hasReachedFineLimit)
            {
                setState(EBorrowState.BORROWING_RESTRICTED);

                _reader.Enabled  = false;
                _scanner.Enabled = false;

                _ui.DisplayErrorMessage("Member has been restricted from borrowing");
            }
            else
            {
                setState(EBorrowState.SCANNING_BOOKS);

                _reader.Enabled  = false;
                _scanner.Enabled = true;

                _ui.DisplayScannedBookDetails("");
                _ui.DisplayPendingLoan("");
            }

            if (hasOverdueLoans)
            {
                _ui.DisplayOverDueMessage();
            }

            if (member.HasReachedLoanLimit)
            {
                _ui.DisplayAtLoanLimitMessage();
            }

            if (member.HasReachedFineLimit)
            {
                _ui.DisplayOverFineLimitMessage(member.FineAmount);
            }

            _borrower = member;

            _ui.DisplayMemberDetails(member.ID, member.ToString(), member.ContactPhone);

            foreach (var loan in member.Loans)
            {
                _ui.DisplayExistingLoan(loan.ToString());
            }

            this.scanCount = member.Loans.Count;
        }