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);
        }
        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);
        }
        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 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);
            }
        }
        public void RunScenario()
        {
            var bookDao = new BookDao(new BookHelper());
               var loanDao = new LoanDao(new LoanHelper());
               var memberDao = new MemberDao(new MemberHelper());

            var display = new MainWindow();
            var reader = new CardReader();
            var scanner = new Scanner();
            var printer = new Printer();

            var controller = new BorrowController(display, reader, scanner, printer,
                bookDao, loanDao, memberDao);

            // Test pre-conditions
            Assert.NotNull(controller);

            Assert.NotNull(bookDao);
            Assert.NotNull(loanDao);
            Assert.NotNull(memberDao);
            Assert.NotNull(display);
            Assert.NotNull(reader);
            Assert.NotNull(scanner);
            Assert.NotNull(printer);

            Assert.Equal(controller._bookDAO, bookDao);
            Assert.Equal(controller._loanDAO, loanDao);
            Assert.Equal(controller._memberDAO, memberDao);
            Assert.Equal(controller._display, display);
            Assert.Equal(controller._reader, reader);
            Assert.Equal(controller._scanner, scanner);
            Assert.Equal(controller._printer, printer);

            Assert.Equal(controller._reader.Listener, controller);
            Assert.Equal(controller._scanner.Listener, controller);

            Assert.Equal(EBorrowState.CREATED, controller._state);

            // Run use case
            controller.initialise();

            // Test post-conditions
            // Borrow book UI Displayed
            Assert.True(display.Display.IsEnabled);

            var borrowCtrl = ((BorrowControl) display.Display);
            var swipeCtrl = borrowCtrl._controlDict.Single(c => c.Value is SwipeCardControl).Value as SwipeCardControl;

            Assert.NotNull(swipeCtrl);
            Assert.True(swipeCtrl.IsEnabled);
            Assert.True(swipeCtrl.cancelButton.IsEnabled);

            Assert.True(reader.Enabled);
            Assert.True(!scanner.Enabled);
            Assert.Equal(EBorrowState.INITIALIZED, controller._state);
        }
        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);
        }
        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 CanGetMemberByEmailAddress()
        {
            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.FindMembersByEmailAddress(member.EmailAddress);

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

            Assert.Equal(member, singleResult);
        }
        public void GetMemberByEmailAddressReturnsNullIfNotFound()
        {
            var helper = Substitute.For<IMemberHelper>();

            var memberDao = new MemberDao(helper);

            var emailAddress = "email address";

            memberDao.MemberList = new List<IMember>
            {
                Substitute.For<IMember>(),
                Substitute.For<IMember>(),
            };

            var list = memberDao.FindMembersByEmailAddress(emailAddress);

            Assert.NotNull(list); // Shouldn't be null, should be an empty collection.
            Assert.Empty(list);
        }
        public void CreateMemberDaoThrowsExceptionOnNullParameter()
        {
            var ex = Assert.Throws<ArgumentException>(() => { var memberDao = new MemberDao(null); });

            Assert.Equal("Helper must be provided when creating MemberDao", ex.Message);
        }
        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 CanCreateMemberDao()
        {
            var helper = Substitute.For<IMemberHelper>();

            var memberDao = new MemberDao(helper);

            Assert.NotNull(memberDao);
        }
        public void MemberDaoImplementsIMemberDAOInterface()
        {
            var helper = Substitute.For<IMemberHelper>();

            var memberDao = new MemberDao(helper);

            Assert.IsAssignableFrom<IMemberDAO>(memberDao);

            var typedMember = memberDao as IMemberDAO;

            Assert.NotNull(typedMember);
        }
        public void GetMemberByIdReturnsNullIfNotFound()
        {
            var helper = Substitute.For<IMemberHelper>();

            var memberDao = new MemberDao(helper);

            memberDao.MemberList = new List<IMember>
            {
                Substitute.For<Member>("one", "two", "three", "four", 1),
                Substitute.For<Member>("one", "two", "three", "four", 3),
            };

            var member = memberDao.GetMemberByID(2);

            Assert.Null(member);
        }
        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); });
        }
        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);
        }
        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 GetMemberByNamesReturnsNullIfNotFound()
        {
            var helper = Substitute.For<IMemberHelper>();

            var memberDao = new MemberDao(helper);

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

            memberDao.MemberList = new List<IMember>
            {
                Substitute.For<IMember>(),
                Substitute.For<IMember>(),
            };

            var list = memberDao.FindMembersByNames(firstName, lastName);

            Assert.NotNull(list); // Shouldn't be null, should be an empty collection.
            Assert.Empty(list);
        }
 public void CreateMemberFailsOnNullHelper()
 {
     IMemberHelper helper = null;
     Assert.Throws<ArgumentException>(() => { IMemberDAO dao = new MemberDao(helper); });
 }
        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);
        }
        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);
        }
        public void CanGetMemberByEmailAddress()
        {
            var helper = Substitute.For<IMemberHelper>();

            var memberDao = new MemberDao(helper);

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

            memberDao.MemberList = new List<IMember>
            {
                Substitute.For<IMember>(),
                Substitute.For<Member>(firstName, lastName, contactPhone, emailAddress, 2),
                Substitute.For<IMember>(),
            };

            var member = memberDao.FindMembersByEmailAddress(emailAddress).Single();

            Assert.NotNull(member);

            Assert.Equal(2, member.ID);
            Assert.Equal(firstName, member.FirstName);
            Assert.Equal(lastName, member.LastName);
            Assert.Equal(contactPhone, member.ContactPhone);
            Assert.Equal(emailAddress, member.EmailAddress);
        }
        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]);
        }