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

            book.ReturnBook(false);

            Assert.Null(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 CanReturnBook()
        {
            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);

            book.ReturnBook(false);

            Assert.Null(book.Loan);
        }
        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 WhenBookIsDamagedAndDisposedShouldBeDisposed()
        {
            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(true);

            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);
        }