示例#1
0
        public void ScanBook(IBorrowingModel borrowingModel)
        {
            // Respond only to scanning books message.
            if (borrowingModel.BorrowingState == EBorrowState.INITIALIZED) return;

            ViewModel.ErrorMessage = "";

            // Is this a valid user?
            _borrower = MemberDao.GetMemberByID(borrowingModel.ID);
            if (_borrower == null)
                ViewModel.ErrorMessage = $"Member {borrowingModel.ID} is not known to the system.";

            if (borrowingModel.HasOverDueLoans || borrowingModel.HasReachedLoanLimit || borrowingModel.HasReachedFineLimit)
                ViewModel.ErrorMessage = $"Member {borrowingModel.ID} Cannot borrow at this time.";

            var borrowerLoans = LoanDao.FindLoansByBorrower(_borrower);
            if (borrowerLoans != null && borrowerLoans.Count > 0)
            {
                borrowerLoans = borrowerLoans.Where(x => (x.State == LoanState.CURRENT || x.State == LoanState.OVERDUE)).ToList();
                ViewModel.ExistingLoan = string.Join(Environment.NewLine + Environment.NewLine, borrowerLoans);
            }

            // Display details
            Mapper.Map(borrowingModel, (ScanBookViewModel) ViewModel);

            EventAggregator.GetEvent<Messages.ScanningRecievedEvent>().Subscribe(Scanning);
            EventAggregator.GetEvent<Messages.ScanningEvent>().Publish(new ScanBookModel());
        }
        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 ");
        }
        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();
        }
示例#4
0
 public void DisableScanner(IBorrowingModel borrowingModel)
 {
     _borrower = borrowingModel;
     ViewModel.Enabled = borrowingModel.BorrowingState == EBorrowState.SCANNING_BOOKS;
 }
 /// <summary>
 /// Borrow a single publication for a single member
 /// </summary>
 /// <param name="borrowingModel"></param>
 public void BorrowBook(IBorrowingModel borrowingModel)
 {
     _datacontext.BorrowBook(borrowingModel.Member.MemberId, borrowingModel.Publication.BookId, DateTime.Now, borrowingModel.DueDate);
 }