コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }