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);
        }
예제 #2
0
        public void CanAddBook()
        {
            var helper = Substitute.For<IBookHelper>();

            var bookDao = new BookDao(helper);

            var author = "author";
            var title = "title";
            var callNo = "callNo";

            // Uses Helper to create a new book with a unique book ID.
            // Adds the book to a collection of books and returns new book.
            Assert.Equal(0, bookDao.BookList.Count);

            // Tell the mock what to return when it is called.
            helper.MakeBook(author, title, callNo, Arg.Any<int>()).Returns(new Book(author, title, callNo, 1));

            var result = bookDao.AddBook(author, title, callNo);

            // Assert that the mock's MakeBook method was called.
            helper.Received().MakeBook(author, title, callNo, Arg.Any<int>());

            Assert.NotNull(result);
            Assert.Equal(author, result.Author);
            Assert.Equal(title, result.Title);
            Assert.Equal(callNo, result.CallNumber);

            Assert.Equal(1, bookDao.BookList.Count);

            var book = bookDao.BookList[0];

            Assert.Equal(book, result);
        }
예제 #3
0
        public void AddBookAssignsUniqueID()
        {
            var helper = Substitute.For<IBookHelper>();

            var bookDao = new BookDao(helper);

            var author = "author";
            var title = "title";
            var callNo = "callNo";

            // Make sure the id increments as books are added.
            for (var id = 1; id < 10; id++)
            {
                helper.MakeBook(author, title, callNo, id).Returns(new Book(author, title, callNo, id));

                var result = bookDao.AddBook(author, title, callNo);

                // Assert that the mock's MakeBook method was called.
                helper.Received().MakeBook(author, title, callNo, id);

                // Make sure the id of the book is new.
                Assert.Equal(id, result.ID);
            }
        }
        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);
        }
        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]);
        }