public void ScanningABook_ThatIsOnLoan_ResultsInNotAvailableError(IEventAggregator eventAggregator , IBookDAO bookDao , [Frozen] IBook book , ILoanDAO loanDao , ScanBookModel scanBookModel , IScanBookViewModel viewModel) { // Arrange - Setup book on loan. eventAggregator.GetEvent<BorrowingStateEvent>().Returns(new BorrowingStateEvent()); bookDao.GetBookByID(scanBookModel.Barcode).Returns(book); book.State.Returns(BookState.ON_LOAN); loanDao.LoanList.Returns(new List<ILoan>()); var controller = new ScanBookController(eventAggregator) { BookDao = bookDao, LoanDao = loanDao, ViewModel = viewModel }; // Act -Scan a book. controller.Scanning(scanBookModel); // Assert - viewModel.ErrorMessage.Should().Be($"Book {book.ID} is not available: {book.State}"); }
public void ScanningABook_ThatDoesntExist_ResultsInErrorMessage(IEventAggregator eventAggregator, [Frozen] IBookDAO bookDao, ScanBookModel scanBookModel, IScanBookViewModel viewModel) { // Arrange - A barcode that doesnt exist. //scanBookModel.Barcode = barCode; bookDao.GetBookByID(Arg.Any<int>()).Returns((IBook)null); eventAggregator.GetEvent<BorrowingStateEvent>().Returns(new BorrowingStateEvent()); var controller = new ScanBookController(eventAggregator) { BookDao = bookDao, ViewModel = viewModel }; // Act -Scan a book. controller.Scanning(scanBookModel); // Assert - Results in an error message. viewModel.ErrorMessage.Should().Be($"Book {scanBookModel.Barcode} not found"); }
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"); }
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(); }
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()); }