コード例 #1
0
        public void CanAddMember()
        {
            var helper = Substitute.For <IMemberHelper>();

            var memberDao = new MemberDao(helper);

            var firstName    = "first";
            var lastName     = "last";
            var contactPhone = "phone";
            var emailAddress = "email address";

            // Uses Helper to create a new member with a unique member ID.
            // Adds the member to a collection of members and returns new member.
            Assert.Equal(0, memberDao.MemberList.Count);

            // Tell the mock what to return when it is called.
            helper.MakeMember(firstName, lastName, contactPhone, emailAddress, Arg.Any <int>()).Returns(Substitute.For <Member>(firstName, lastName, contactPhone, emailAddress, 1));

            var result = memberDao.AddMember(firstName, lastName, contactPhone, emailAddress);

            // Assert that the mock's MakeMember method was called.
            helper.Received().MakeMember(firstName, lastName, contactPhone, emailAddress, Arg.Any <int>());

            Assert.NotNull(result);
            Assert.Equal(firstName, result.FirstName);
            Assert.Equal(lastName, result.LastName);
            Assert.Equal(contactPhone, result.ContactPhone);
            Assert.Equal(emailAddress, result.EmailAddress);

            Assert.Equal(1, memberDao.MemberList.Count);

            var member = memberDao.MemberList[0];

            Assert.Equal(member, result);
        }
コード例 #2
0
        public void CanCreateMember()
        {
            IMemberHelper helper = new MemberHelper();
            IMemberDAO    dao    = new MemberDao(helper);

            var firstName    = "first";
            var lastName     = "last";
            var contactPhone = "contactPhone";
            var emailAddress = "emailAddress";

            var member = dao.AddMember(firstName, lastName, contactPhone, emailAddress);

            Assert.NotNull(member);

            Assert.NotEmpty(dao.MemberList);
            Assert.Equal(1, dao.MemberList.Count);

            Assert.Equal(member, dao.MemberList[0]);

            Assert.Equal(firstName, member.FirstName);
            Assert.Equal(lastName, member.LastName);
            Assert.Equal(contactPhone, member.ContactPhone);
            Assert.Equal(emailAddress, member.EmailAddress);

            Assert.NotEqual(0, member.ID);
        }
コード例 #3
0
        public void AddMemberAssignsUniqueID()
        {
            var helper = Substitute.For <IMemberHelper>();

            var memberDao = new MemberDao(helper);

            var firstName    = "first";
            var lastName     = "last";
            var contactPhone = "phone";
            var emailAddress = "email address";

            // Make sure the id increments as Members are added.
            for (var id = 1; id < 10; id++)
            {
                helper.MakeMember(firstName, lastName, contactPhone, emailAddress, id).Returns(Substitute.For <Member>(firstName, lastName, contactPhone, emailAddress, id));

                var result = memberDao.AddMember(firstName, lastName, contactPhone, emailAddress);

                // Assert that the mock's MakeMember method was called.
                helper.Received().MakeMember(firstName, lastName, contactPhone, emailAddress, id);

                // Make sure the id of the Member is new.
                Assert.Equal(id, result.ID);
            }
        }
コード例 #4
0
        public void CanCommitLoan()
        {
            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.NotNull(loan);

            Assert.Equal(1, loanDao.LoanList.Count);
            Assert.Equal(loan, loanDao.LoanList[0]);

            Assert.NotEqual(0, loan.ID);
        }
コード例 #5
0
        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);
        }
コード例 #6
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]);
        }
コード例 #7
0
        public void CanGetMemberById()
        {
            IMemberHelper helper = new MemberHelper();
            IMemberDAO    dao    = new MemberDao(helper);

            var firstName    = "first";
            var lastName     = "last";
            var contactPhone = "contactPhone";
            var emailAddress = "emailAddress";

            var member = dao.AddMember(firstName, lastName, contactPhone, emailAddress);

            for (int i = 0; i < 10; i++)
            {
                dao.AddMember("Test", "Test", "test phone", "test email");
            }

            var result = dao.GetMemberByID(member.ID);

            Assert.Equal(member, result);
        }
コード例 #8
0
        public void GetMemberByNamesReturnsEmptyCollectionIfNotFound()
        {
            IMemberHelper helper = new MemberHelper();
            IMemberDAO    dao    = new MemberDao(helper);

            var firstName    = "first";
            var lastName     = "last";
            var contactPhone = "contactPhone";
            var emailAddress = "emailAddress";

            var member = dao.AddMember(firstName, lastName, contactPhone, emailAddress);

            for (int i = 0; i < 10; i++)
            {
                dao.AddMember("Test", "Test", "test phone", "test email");
            }

            var result = dao.FindMembersByNames("Jim", "Tulip");

            Assert.Empty(result);
        }
コード例 #9
0
        public void GetMemberByIdReturnsNullIfNotFound()
        {
            IMemberHelper helper = new MemberHelper();
            IMemberDAO    dao    = new MemberDao(helper);

            var firstName    = "first";
            var lastName     = "last";
            var contactPhone = "contactPhone";
            var emailAddress = "emailAddress";

            var member = dao.AddMember(firstName, lastName, contactPhone, emailAddress);

            for (int i = 0; i < 10; i++)
            {
                dao.AddMember("Test", "Test", "test phone", "test email");
            }

            var result = dao.GetMemberByID(1000);

            Assert.Null(result);
        }
コード例 #10
0
        public void CreateMemberFailsOnIllegalArguments()
        {
            IMemberHelper helper = new MemberHelper();
            IMemberDAO    dao    = new MemberDao(helper);

            var firstName    = "first";
            var lastName     = "last";
            var contactPhone = "contactPhone";
            var emailAddress = "emailAddress";

            Assert.Throws <ArgumentException>(
                () => { var member = dao.AddMember(null, lastName, contactPhone, emailAddress); });

            Assert.Throws <ArgumentException>(
                () => { var member = dao.AddMember(firstName, null, contactPhone, emailAddress); });

            Assert.Throws <ArgumentException>(
                () => { var member = dao.AddMember(firstName, lastName, null, emailAddress); });

            Assert.Throws <ArgumentException>(
                () => { var member = dao.AddMember(firstName, lastName, contactPhone, null); });
        }
コード例 #11
0
        public void CanGetLoanByBorrower()
        {
            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(member);

            var single = result.Single();

            Assert.Equal(loan, single);
        }
コード例 #12
0
        public void CreateMemberCreatesAUniqueId()
        {
            IMemberHelper helper = new MemberHelper();
            IMemberDAO    dao    = new MemberDao(helper);

            var firstName    = "first";
            var lastName     = "last";
            var contactPhone = "contactPhone";
            var emailAddress = "emailAddress";

            var member = dao.AddMember(firstName, lastName, contactPhone, emailAddress);

            Assert.NotEqual(0, member.ID);
        }
コード例 #13
0
        public void CanGetMemberByNames()
        {
            IMemberHelper helper = new MemberHelper();
            IMemberDAO    dao    = new MemberDao(helper);

            var firstName    = "first";
            var lastName     = "last";
            var contactPhone = "contactPhone";
            var emailAddress = "emailAddress";

            var member = dao.AddMember(firstName, lastName, contactPhone, emailAddress);

            for (int i = 0; i < 10; i++)
            {
                dao.AddMember("Test", "Test", "test phone", "test email");
            }

            var result = dao.FindMembersByNames(member.FirstName, member.LastName);

            var singleResult = result.Single(); // Test there should only be one result and get it.

            Assert.Equal(member, singleResult);
        }
コード例 #14
0
        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);
        }