public void BorrowBookThrowsRuntimeExceptionIfBookIsNotCurrentlyAvailable()
        {
            // Set book state to something other than Available.
            var book = new Book("author", "title", "call number", 1) {State = BookState.LOST};

            var loan = Substitute.For<ILoan>();

            // Associate the book with the loan.
            var ex = Assert.Throws<InvalidOperationException>(() => book.Borrow(loan));

            Assert.Equal("Cannot borrow a book that is not available", ex.Message);
        }
        public void BorrowBookThrowsRuntimeExceptionIfBookIsNotCurrentlyAvailable()
        {
            // Set book state to something other than Available.
            var book = new Book("author", "title", "call number", 1) { State = BookState.LOST };
            var member = new Member("first", "last", "phone", "email", 1);

            var loan = new Loan(book, member, DateTime.Today, DateTime.Today.AddDays(7));

            // Associate the book with the loan.
            var ex = Assert.Throws<InvalidOperationException>(() => book.Borrow(loan));

            Assert.Equal("Cannot borrow a book that is not available", ex.Message);
        }
        public void CanBorrowBook()
        {
            var book = new Book("author", "title", "call number", 1);
            var member = new Member("first", "last", "phone", "email", 1);

            var loan = new Loan(book, member, DateTime.Today, DateTime.Today.AddDays(7));

            // Associate the book with the loan.
            book.Borrow(loan);

            // Set book state to ON_LOAN - affected by GetLoanFromBookReturnsNullIfBookIsNotON_LOAN()
            book.State = BookState.ON_LOAN;

            Assert.Equal(loan, book.Loan);
        }
        public void CanBorrowBook()
        {
            var book = new Book("author", "title", "call number", 1);

            var loan = Substitute.For<ILoan>();

            // Associate the book with the loan.
            book.Borrow(loan);

            // Set book state to ON_LOAN - affected by GetLoanFromBookReturnsNullIfBookIsNotON_LOAN()
            book.State = BookState.ON_LOAN;

            Assert.Equal(loan, book.Loan);
        }
        public void ReturningBookThrowsExceptionIfNotOnLoan()
        {
            var book = new Book("author", "title", "call number", 1);

            var loan = Substitute.For<ILoan>();
            book.Borrow(loan);

            // Set book state to ON_LOAN - affected by GetLoanFromBookReturnsNullIfBookIsNotON_LOAN()
            book.State = BookState.ON_LOAN;

            Assert.Equal(loan, book.Loan);

            // Set book state to LOST so we can make sure it's not ON_LOAN already.
            book.State = BookState.LOST;

            var ex = Assert.Throws<InvalidOperationException>(() => book.ReturnBook(false));

            Assert.Equal("Book is currently not on loan", ex.Message);
        }
        public void ReturningBookSetsStateToDamaged()
        {
            var book = new Book("author", "title", "call number", 1);

            var loan = Substitute.For<ILoan>();
            book.Borrow(loan);

            // Set book state to ON_LOAN - affected by GetLoanFromBookReturnsNullIfBookIsNotON_LOAN()
            book.State = BookState.ON_LOAN;

            Assert.Equal(loan, book.Loan);

            // Set damaged flag to true.
            book.ReturnBook(true);

            Assert.Null(book.Loan);
            Assert.Equal(BookState.DAMAGED, book.State);
        }
        public void GetLoanFromBookReturnsNullIfBookIsNotON_LOAN()
        {
            var book = new Book("author", "title", "call number", 1);

            // Testing the getter on the book.
            var loanRetrieved = book.Loan;

            // Make sure the book returns null when no loan associated.
            Assert.Null(loanRetrieved);

            var loan = Substitute.For<ILoan>();

            // Associate the book with the loan.
            book.Borrow(loan);

            // Make sure the loan comes back if it is on loan.
            book.State = BookState.ON_LOAN;

            loanRetrieved = book.Loan;

            // Make sure the loan retrieved is the same one loaned out.
            Assert.Equal(loan, loanRetrieved);

            // Set the loan state to not ON_LOAN.
            book.State = BookState.AVAILABLE;

            // Make sure null is returned if book is not ON_LOAN.
            loanRetrieved = book.Loan;

            Assert.Null(loanRetrieved);
        }
        public void GetLoanFromBookReturnsNullIfBookIsNotON_LOAN()
        {
            var book = new Book("author", "title", "call number", 1);
            var member = new Member("first", "last", "phone", "email", 1);

            var loan = new Loan(book, member, DateTime.Today, DateTime.Today.AddDays(7));

            // Testing the getter on the book.
            var loanRetrieved = book.Loan;

            // Make sure the book returns null when no loan associated.
            Assert.Null(loanRetrieved);

            // Associate the book with the loan.
            book.Borrow(loan);

            // Make sure the loan comes back if it is on loan.
            book.State = BookState.ON_LOAN;

            loanRetrieved = book.Loan;

            // Make sure the loan retrieved is the same one loaned out.
            Assert.Equal(loan, loanRetrieved);

            // Set the loan state to not ON_LOAN.
            book.State = BookState.AVAILABLE;

            // Make sure null is returned if book is not ON_LOAN.
            loanRetrieved = book.Loan;

            Assert.Null(loanRetrieved);
        }
        public void WhenBookIsOnLoanAndReturnedUndamagedShouldBeAvailable()
        {
            var book = new Book("author", "title", "call number", 1);
            var member = new Member("first", "last", "phone", "email", 1);

            var loan = new Loan(book, member, DateTime.Today, DateTime.Today.AddDays(7));

            book.Borrow(loan);

            book.ReturnBook(false);

            Assert.Equal(BookState.AVAILABLE, book.State);
        }
        public void WhenBookIsOnLoanAndLostThenShouldBeLost()
        {
            var book = new Book("author", "title", "call number", 1);
            var member = new Member("first", "last", "phone", "email", 1);

            var loan = new Loan(book, member, DateTime.Today, DateTime.Today.AddDays(7));

            book.Borrow(loan);

            book.Lose();

            Assert.Equal(BookState.LOST, book.State);
        }
        public void WhenBookIsLostAndDisposedShouldBeDisposed()
        {
            var book = new Book("author", "title", "call number", 1);
            var member = new Member("first", "last", "phone", "email", 1);

            var loan = new Loan(book, member, DateTime.Today, DateTime.Today.AddDays(7));

            book.Borrow(loan);

            book.Lose();

            book.Dispose();

            Assert.Equal(BookState.DISPOSED, book.State);
        }
        public void ReturningBookThrowsExceptionIfNotOnLoan()
        {
            var book = new Book("author", "title", "call number", 1);
            var member = new Member("first", "last", "phone", "email", 1);

            var loan = new Loan(book, member, DateTime.Today, DateTime.Today.AddDays(7));

            book.Borrow(loan);

            // Set book state to ON_LOAN - affected by GetLoanFromBookReturnsNullIfBookIsNotON_LOAN()
            book.State = BookState.ON_LOAN;

            Assert.Equal(loan, book.Loan);

            // Set book state to LOST so we can make sure it's not ON_LOAN already.
            book.State = BookState.LOST;

            var ex = Assert.Throws<InvalidOperationException>(() => book.ReturnBook(false));

            Assert.Equal("Book is currently not on loan", ex.Message);
        }
        public void ReturningBookSetsStateToDamaged()
        {
            var book = new Book("author", "title", "call number", 1);
            var member = new Member("first", "last", "phone", "email", 1);

            var loan = new Loan(book, member, DateTime.Today, DateTime.Today.AddDays(7));

            book.Borrow(loan);

            // Set book state to ON_LOAN - affected by GetLoanFromBookReturnsNullIfBookIsNotON_LOAN()
            book.State = BookState.ON_LOAN;

            Assert.Equal(loan, book.Loan);

            // Set damaged flag to true.
            book.ReturnBook(true);

            Assert.Null(book.Loan);
            Assert.Equal(BookState.DAMAGED, book.State);
        }