public void CanGetOverdueLoans() { var helper = Substitute.For<ILoanHelper>(); var book = Substitute.For<IBook>(); var member = Substitute.For<IMember>(); var loanDao = new LoanDao(helper); var borrowDate = DateTime.Today.AddMonths(-1); var dueDate = DateTime.Today.AddMonths(-1).AddDays(7); // Adds the member to a collection of members and returns new member. Assert.Equal(0, loanDao.LoanList.Count); // Tell the mock what to return when it is called. helper.MakeLoan(book, member, borrowDate, dueDate).Returns(Substitute.For<Loan>(book, member, borrowDate, dueDate)); var loan = loanDao.CreateLoan(member, book, borrowDate, dueDate); loanDao.CommitLoan(loan); // Assert that the mock's MakeLoan method was called. helper.Received().MakeLoan(book, member, borrowDate, dueDate); // Store two more for testing loanDao.CommitLoan(Substitute.For<ILoan>()); loanDao.CommitLoan(Substitute.For<ILoan>()); loanDao.UpdateOverDueStatus(DateTime.Today); var loans = loanDao.FindOverDueLoans(); Assert.NotNull(loans); Assert.Equal(1, loans.Count); Assert.Equal(loan, loans[0]); }
public void CanGetOverdueLoans() { ILoanHelper loanHelper = new LoanHelper(); ILoanDAO loanDao = new LoanDao(loanHelper); IMemberHelper memberHelper = new MemberHelper(); IMemberDAO memberDao = new MemberDao(memberHelper); IBookHelper bookHelper = new BookHelper(); IBookDAO bookDao = new BookDao(bookHelper); var borrowDate = DateTime.Today; var dueDate = DateTime.Today.AddDays(7); var member = memberDao.AddMember("Jim", "Tulip", "csu phone", "*****@*****.**"); var book = bookDao.AddBook("Jim Tulip", "Adventures in Programming", "call number"); var loan = loanDao.CreateLoan(member, book, borrowDate, dueDate); loanDao.CommitLoan(loan); Assert.Equal(LoanState.CURRENT, loan.State); loanDao.UpdateOverDueStatus(DateTime.Today.AddMonths(1)); Assert.Equal(LoanState.OVERDUE, loan.State); for (int i = 0; i < 10; i++) { var m = memberDao.AddMember("Test", "Test", "Test Phone", "Test Email"); var b = bookDao.AddBook("Test", "Test", "Test"); var l = loanDao.CreateLoan(m, b, borrowDate, dueDate); loanDao.CommitLoan(l); } var overdue = loanDao.FindOverDueLoans(); Assert.Equal(1, overdue.Count); Assert.Equal(loan, overdue[0]); }