public void SwipeBorrowerCardShowErrorIfMemberHasOverdueLoans() { var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email"); var book = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var loan = _loanDao.CreateLoan(member, book, borrowDate, dueDate); _loanDao.CommitLoan(loan); _loanDao.UpdateOverDueStatus(DateTime.Today.AddMonths(1)); var ctrl = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao); // Set the UI to the mock so we can test calls being made var borrowctrl = Substitute.For <ABorrowControl>(); ctrl._ui = borrowctrl; 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); ctrl.cardSwiped(member.ID); borrowctrl.Received().DisplayOverDueMessage(); }
public void RunMemberExistsAndNotRestricted() { // Set up var controller = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao); controller.initialise(); // Some test data initialisation var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = _memberDao.AddMember("Jim", "Tulip", "Phone", "Email"); var book = _bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var loan = _loanDao.CreateLoan(member, book, borrowDate, dueDate); _loanDao.CommitLoan(loan); // Test Pre-conditions Assert.True(_display.Display.IsEnabled); var borrowCtrl = ((BorrowControl)_display.Display); var swipeCtrl = borrowCtrl._controlDict.Single(c => c.Value is SwipeCardControl).Value as SwipeCardControl; var scanBookCtrl = borrowCtrl._controlDict.Single(c => c.Value is ScanBookControl).Value as ScanBookControl; Assert.NotNull(swipeCtrl); Assert.True(swipeCtrl.IsEnabled); Assert.True(swipeCtrl.cancelButton.IsEnabled); Assert.True(_reader.Enabled); Assert.Equal(controller, _reader.Listener); Assert.NotNull(controller._memberDAO); Assert.Equal(EBorrowState.INITIALIZED, controller._state); // Run use case controller.cardSwiped(member.ID); // Test Post-conditions 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(member.ID, scanBookCtrl.idLabel.Content); Assert.Equal($"{member.FirstName} {member.LastName}", scanBookCtrl.nameLabel.Content.ToString()); Assert.Equal(member.Loans[0].ToString(), scanBookCtrl.existingLoanBox.Text); // Test one existing loan is present Assert.Equal(member.Loans.Count, controller.scanCount); Assert.Equal(member, controller._borrower); Assert.Equal(EBorrowState.SCANNING_BOOKS, controller._state); }
public void RunBookNotFound() { // 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); // Set up var controller = new BorrowController(_display, _reader, _scanner, _printer, _bookDao, _loanDao, _memberDao); controller.initialise(); controller.cardSwiped(member.ID); // 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(5); // 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 scanned was not found", scanBookCtrl.errorMessage.Content); Assert.Equal(EBorrowState.SCANNING_BOOKS, controller._state); }
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); }
public void EdgeCase_CantMoveFromPendingToOverdue(ILoanDAO loanDao, IMember borrower, IBook book) { // Create and commit to the loan. var loan = loanDao.CreateLoan(borrower, book, _today, _dueDate); loan.State.Should().Be(LoanState.PENDING); // Return the book should be prevented. loan.Invoking(x => x.CheckOverDue(_overdueDate)) .ShouldThrow<ApplicationException>(); loan.State.Should().Be(LoanState.PENDING); }
public void bookScanned(int barcode) { if (_state != EBorrowState.SCANNING_BOOKS) { throw new InvalidOperationException("Control state must be set to 'Scanning Books'"); } var book = _bookDAO.GetBookByID(barcode); if (book == null) { _ui.DisplayErrorMessage("Book scanned was not found"); return; } if (book.State != BookState.AVAILABLE) { _ui.DisplayErrorMessage("Book is not available to be borrowed"); return; } if (_bookList.Contains(book)) { _ui.DisplayErrorMessage("Book has already been scanned"); return; } this.scanCount++; var loan = _loanDAO.CreateLoan(_borrower, book, DateTime.Today, DateTime.Today.AddDays(7)); _ui.DisplayPendingLoan(loan.ToString()); _ui.DisplayScannedBookDetails(book.ToString()); _ui.DisplayErrorMessage(""); _loanList.Add(loan); _bookList.Add(book); if (this.scanCount == BookConstants.LOAN_LIMIT) { _scanner.Enabled = false; setState(EBorrowState.CONFIRMING_LOANS); foreach (var l in _loanList) { _ui.DisplayConfirmingLoan(l.ToString()); } } }
public void OverDueCase_UserBorrowsAndReturnsBookAfterDue(ILoanDAO loanDao, IMember borrower, IBook book) { // Create and commit to the loan. var loan = loanDao.CreateLoan(borrower, book, _today, _dueDate); loan.State.Should().Be(LoanState.PENDING); // Commit the loan. loan.Commit(200); loan.State.Should().Be(LoanState.CURRENT); // The book is now overdue. loan.CheckOverDue(_overdueDate); loan.State.Should().Be(LoanState.OVERDUE); loan.IsOverDue.Should().BeTrue(); // Return the book loan.Complete(); loan.State.Should().Be(LoanState.COMPLETE); loan.IsOverDue.Should().BeFalse(); }
public void HappyCase_UserBorrowsAndReturnsBookBeforeDue(ILoanDAO loanDao, IMember borrower, IBook book) { // Create and commit to the loan. var loan = loanDao.CreateLoan(borrower, book, _today, _dueDate); loan.State.Should().Be(LoanState.PENDING); // Commit the loan. loan.Commit(200); loan.State.Should().Be(LoanState.CURRENT); // Check if the book is overdue. loan.CheckOverDue(_notYetDueDate); loan.State.Should().Be(LoanState.CURRENT); // Return the book loan.Complete(); loan.State.Should().Be(LoanState.COMPLETE); loan.IsOverDue.Should().BeFalse(); }
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(); }
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); }
private void SetUpTestData() { IBook[] book = new IBook[15]; IMember[] member = new IMember[6]; book[0] = _bookDAO.AddBook("author1", "title1", "callNo1"); book[1] = _bookDAO.AddBook("author1", "title2", "callNo2"); book[2] = _bookDAO.AddBook("author1", "title3", "callNo3"); book[3] = _bookDAO.AddBook("author1", "title4", "callNo4"); book[4] = _bookDAO.AddBook("author2", "title5", "callNo5"); book[5] = _bookDAO.AddBook("author2", "title6", "callNo6"); book[6] = _bookDAO.AddBook("author2", "title7", "callNo7"); book[7] = _bookDAO.AddBook("author2", "title8", "callNo8"); book[8] = _bookDAO.AddBook("author3", "title9", "callNo9"); book[9] = _bookDAO.AddBook("author3", "title10", "callNo10"); book[10] = _bookDAO.AddBook("author4", "title11", "callNo11"); book[11] = _bookDAO.AddBook("author4", "title12", "callNo12"); book[12] = _bookDAO.AddBook("author5", "title13", "callNo13"); book[13] = _bookDAO.AddBook("author5", "title14", "callNo14"); book[14] = _bookDAO.AddBook("author5", "title15", "callNo15"); member[0] = _memberDAO.AddMember("fName1", "lName1", "0001", "email1"); member[1] = _memberDAO.AddMember("fName2", "lName2", "0002", "email2"); member[2] = _memberDAO.AddMember("fName3", "lName3", "0003", "email3"); member[3] = _memberDAO.AddMember("fName4", "lName4", "0004", "email4"); member[4] = _memberDAO.AddMember("fName5", "lName5", "0005", "email5"); member[5] = _memberDAO.AddMember("fName6", "lName6", "0006", "email6"); DateTime borrowDate = DateTime.Now; TimeSpan loanPeriod = new TimeSpan(LoanConstants.LOAN_PERIOD, 0, 0, 0); DateTime dueDate = borrowDate.Add(loanPeriod); //create a member with overdue loans for (int i = 0; i < 2; i++) { ILoan loan = _loanDAO.CreateLoan(member[1], book[i], borrowDate, dueDate); _loanDAO.CommitLoan(loan); } DateTime checkDate = dueDate.Add(new TimeSpan(1, 0, 0, 0)); _loanDAO.UpdateOverDueStatus(checkDate); //create a member with maxed out unpaid fines member[2].AddFine(10.0f); //create a member with maxed out loans for (int i = 2; i < 7; i++) { ILoan loan = _loanDAO.CreateLoan(member[3], book[i], borrowDate, dueDate); _loanDAO.CommitLoan(loan); } //a member with a fine, but not over the limit member[4].AddFine(5.0f); //a member with a couple of loans but not over the limit for (int i = 7; i < 9; i++) { ILoan loan = _loanDAO.CreateLoan(member[5], book[i], borrowDate, dueDate); _loanDAO.CommitLoan(loan); } }
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; var scanBookCtrl = borrowCtrl._controlDict.Single(c => c.Value is ScanBookControl).Value as ScanBookControl; 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.loansRejected(); // Test Post-conditions 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); Assert.Equal(member.ID, scanBookCtrl.idLabel.Content); Assert.Equal($"{member.FirstName} {member.LastName}", scanBookCtrl.nameLabel.Content.ToString()); Assert.Equal(member.Loans[0].ToString(), scanBookCtrl.existingLoanBox.Text); // Test one existing loan is present Assert.Equal("", scanBookCtrl.pendingLoanBox.Text); Assert.Equal("", scanBookCtrl.currentbookBox.Text); Assert.NotNull(controller._bookList); Assert.Empty(controller._bookList); Assert.NotNull(controller._loanList); Assert.Empty(controller._loanList); Assert.Equal(1, controller.scanCount); }