Ejemplo n.º 1
0
        public CardReaderViewModel(IEventAggregator eventAggregator, ICardReaderController cardReaderController)
        {
            Controller = cardReaderController;
            EventAggregator = eventAggregator;

            // Subscribe to setEnabled event from the borrower. 
            // In the event that the Borrowers current state is initialised, Enables this control, otherwise disables it.
            eventAggregator.GetEvent<Messages.BorrowingStateEvent>().Subscribe(borrowModel => Enabled = borrowModel.BorrowingState == EBorrowState.INITIALIZED);

            // Listen to Swipe button press 
            CardSwipedCmd = new DelegateCommand<string>(cardReaderController.CardSwiped).ObservesCanExecute(p => Enabled);

            // Listen to window close event.
            CloseWindowCommand = new DelegateCommand(CloseWindow, () => false);
        }
Ejemplo n.º 2
0
        public void SwipeCard_WithValidBorrowerId_SetsBorrowerDetailsForBookScanner(
            IScanBookController scanBookController, IBorrowController borrowController,
            ICardReaderViewModel cardReaderViewModel, ICardReaderController cardReaderController,
            IScanBookViewModel scanBookViewModel)
        {
            AutoMapperConfig.RegisterMaps();

            // The borrow controller has been clicked.
            borrowController.WaitForCardSwipe();

            // The card is swiped with a known user.
            cardReaderViewModel.BorrowerId = "0001";

            // When the card is swiped.
            cardReaderController.CardSwiped(cardReaderViewModel.BorrowerId);

            scanBookViewModel.BorrowerId.Should().Be(1);
            scanBookViewModel.Name.Should().Be("fName1 lName1");
            scanBookViewModel.Contact.Should().Be("0001");
        }
Ejemplo n.º 3
0
        public void SwipeCard_WithValidBorrowerId_CardReaderIsDisabled(
            IScanBookController scanBookController
            , IBorrowController borrowController
            , ICardReaderController cardReaderController
            , ICardReaderViewModel cardReaderViewModel
            , IScanBookViewModel scanBookViewModel)
        {
            PreConditions(borrowController, cardReaderViewModel);

            // Arrange - unrestricted user.
            const string borrowerId = "1";
            cardReaderViewModel.BorrowerId = borrowerId;

            // Act - Swipe the card.
            cardReaderController.CardSwiped(borrowerId);

            // Assert - ensure that the card reader is disabled.
            cardReaderViewModel.Enabled.Should().BeFalse();
        }
Ejemplo n.º 4
0
        public void SwipeCard_WithValidBorrowerId_ExistingLoansDisplayed(
      IScanBookController scanBookController
      , IBorrowController borrowController
      , IBorrowingViewModel borrowingViewModel
      , ICardReaderController cardReaderController
      , ICardReaderViewModel cardReaderViewModel
      , IScanBookViewModel scanBookViewModel
      , IScannerController scannerController
      , IScannerViewModel scannerViewModel)
        {
            PreConditions(borrowController, cardReaderViewModel);

            // Arrange - User with existing loans.
            const string borrowerId = "2";
            cardReaderViewModel.BorrowerId = borrowerId;

            // Act - Swipe the card.
            cardReaderController.CardSwiped(borrowerId);
            

            // Assert - ensure that the card reader is disabled.
            scanBookViewModel.ExistingLoan.Should().Contain("author1");
            scanBookViewModel.ExistingLoan.Should().Contain("title2 ");
            scanBookViewModel.ExistingLoan.Should().Contain("fName2 lName2");
            scanBookViewModel.ExistingLoan.Should().Contain(DateTime.Today.ToShortDateString());
            scanBookViewModel.ExistingLoan.Should().Contain(DateTime.Today.AddDays(14).ToShortDateString());
        }