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

            var loanDao = new LoanDao(helper);

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

            var loan = loanDao.GetLoanByID(2);

            Assert.Null(loan);
        }
Ejemplo n.º 2
0
        public void CanGetLoanById()
        {
            var helper = Substitute.For<ILoanHelper>();

            var loanDao = new LoanDao(helper);

            var book = Substitute.For<IBook>();
            var member = Substitute.For<IMember>();

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

            helper.MakeLoan(book, member, borrowDate, dueDate)
                .Returns(Substitute.For<Loan>(book, member, borrowDate, dueDate));

            // Commit one we can test.
            var loan = loanDao.CreateLoan(member, book, borrowDate, dueDate);
            loanDao.CommitLoan(loan);

            helper.Received().MakeLoan(book, member, borrowDate, dueDate);

            var max = loanDao.LoanList.Max(l => l.ID);

            var result = loanDao.GetLoanByID(max);

            Assert.NotNull(loan);

            Assert.Equal(loan.ID, result.ID);
            Assert.Equal(loan, result);
        }
        public void GetLoanByLoanIdReturnsNullIfNotFound()
        {
            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.GetLoanByID(1000);

            Assert.Null(result);
        }