public void CanCreateLoan()
        {
            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);

            Assert.NotNull(loan);

            Assert.Empty(loanDao.LoanList);

            Assert.Equal(book, loan.Book);
            Assert.Equal(member, loan.Borrower);

            Assert.Equal(0, loan.ID);
        }
        public void LoanHelperImplementsILoanHelperInterface()
        {
            var helper = new LoanHelper();

            Assert.IsAssignableFrom<ILoanHelper>(helper);

            var typedMember = helper as ILoanHelper;

            Assert.NotNull(typedMember);
        }
        public void CanMakeLoan()
        {
            var book = Substitute.For<IBook>();
            var borrower = Substitute.For<IMember>();
            var borrowDate = DateTime.Today;
            var dueDate = DateTime.Today.AddDays(7);

            var helper = new LoanHelper();

            var loan = helper.MakeLoan(book, borrower, borrowDate, dueDate);

            Assert.NotNull(loan);
            Assert.Equal(0, loan.ID);
            Assert.Equal(book, loan.Book);
            Assert.Equal(borrower, loan.Borrower);
        }
        public MockDataProviderModule()
        {
            _memberHelper = new MemberHelper();
            _memberDAO = new MemberDAO(_memberHelper);
            _loanHelper = new LoanHelper();
            _loanDAO = new LoanDAO(_loanHelper);
            _bookHelper = new BookHelper();
            _bookDao = new BookDAO(_bookHelper);

            // Setup dates for test data
            _borrowDate = DateTime.Now;
            _loanPeriod = new TimeSpan(LoanConstants.LOAN_PERIOD, 0, 0, 0);
            _dueDate = _borrowDate.Add(_loanPeriod);
          
            SetupBookTestData();
            SetupMemberTestData();
            SetUpLoanTestData();
            SetUpTestData();
        }
        public void CanGetLoanByBookTitle()
        {
            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.FindLoansByBookTitle(book.Title);

            var single = result.Single();

            Assert.Equal(loan, single);
        }
Exemple #6
0
 public LoanDaoTests()
 {
     // Arrange
     _loanHelper = new LoanHelper();
     _loanDao = new LoanDAO(_loanHelper);
 }
        public void CanCreateLoanHelper()
        {
            var helper = new LoanHelper();

            Assert.NotNull(helper);
        }
        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);
        }
        public void CanUpdateOverdueStatus()
        {
            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);
        }
        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]);
        }