Ejemplo n.º 1
0
        public void CanGetLoansByBorrower()
        {
            var helper = Substitute.For<ILoanHelper>();

            var loanDao = new LoanDao(helper);

            var borrowDate = DateTime.Today;
            var dueDate = DateTime.Today.AddDays(7);

            var borrower = Substitute.For<Member>("Borris", "Natasha", "phone", "email", 1);

            var storedLoan = new Loan(Substitute.For<IBook>(), borrower, borrowDate, dueDate);

            loanDao.LoanList = new List<ILoan>
            {
                Substitute.For<ILoan>(),
                Substitute.For<ILoan>(),
                storedLoan
            };

            var loans = loanDao.FindLoansByBorrower(borrower);

            Assert.NotNull(loans);
            Assert.Equal(storedLoan, loans[0]);
        }
        public void GetLoanByBorrowerReturnsEmptyCollectionIfNotFound()
        {
            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);

            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 result = loanDao.FindLoansByBorrower(new Member("Test", "Test", "Test", "Test", 100));

            Assert.Empty(result);
        }