public void SetDiscardBook()
        {
            var bookManagerMock  = new Mock <IBookManager>();
            var shelfManagerMock = new Mock <IShelfManager>();


            bookManagerMock.Setup(m =>
                                  m.GetBookByNumber(It.IsAny <long>()))
            .Returns(new Book
            {
                BookDiscardListNr = 1,
                Condition         = 2,
                OnLoan            = false,
                Title             = "Clean Code",
                AisleNr           = 3,
                ShelfNr           = 7
            });



            var bookAPI     = new BookAPI(bookManagerMock.Object, shelfManagerMock.Object);
            var successfull = bookAPI.RemoveBook(1);

            Assert.AreEqual(RemoveBookErrorCodes.PoorCondition, successfull);
            bookManagerMock.Verify(m =>
                                   m.RemoveBook(It.IsAny <long>()), Times.Once);
        }
示例#2
0
        public void RemoveNonExistingBook()
        {
            var bookManagerMock = SetupMock((Book)null);

            var bookAPI     = new BookAPI(null, bookManagerMock.Object);
            var successfull = bookAPI.RemoveBook("Circe");

            Assert.AreEqual(RemoveBookStatusCodes.NoSuchBook, successfull);
            bookManagerMock.Verify(m =>
                                   m.RemoveBook(It.IsAny <int>()), Times.Never);
        }
        public void TestRemoveNonexistingBook()
        {
            var bookManagerMock = new Mock <IBookManager>();

            bookManagerMock.Setup(m =>
                                  m.GetBookByBookNumber(It.IsAny <int>()))
            .Returns((Book)null);

            var bookAPI     = new BookAPI(bookManagerMock.Object, null, null);
            var successfull = bookAPI.RemoveBook(1);

            Assert.AreEqual(ErrorCodesRemoveBook.NoSuchBook, successfull);
            bookManagerMock.Verify(m =>
                                   m.RemoveBook(It.IsAny <int>()), Times.Never);
        }
示例#4
0
        public void RemoveBorrowedBook()
        {
            var bookManagerMock = SetupMock(new Book
            {
                BookID     = 4,
                BookTitle  = "Circe",
                IsBorrowed = true
            });

            var bookAPI     = new BookAPI(null, bookManagerMock.Object);
            var successfull = bookAPI.RemoveBook("Circe");

            Assert.AreEqual(RemoveBookStatusCodes.BookIsBorrowed, successfull);
            bookManagerMock.Verify(m =>
                                   m.RemoveBook(It.IsAny <int>()), Times.Never);
        }
        public void TestRemoveNonExistingBook()
        {
            var bookManagerMock = new Mock <IBookManager>();
            var loanManagerMock = new Mock <ILoanManager>();


            bookManagerMock.Setup(m =>
                                  m.GetBookByBookTitle(It.IsAny <string>()))
            .Returns((Book)null);

            var bookAPI     = new BookAPI(bookManagerMock.Object, loanManagerMock.Object);
            var successfull = bookAPI.RemoveBook("ABC");

            Assert.AreEqual(BookStatusCodes.NoSuchBook, successfull);
            bookManagerMock.Verify(m =>
                                   m.RemoveBook(It.IsAny <int>()), Times.Never);
        }
        public void TestRemoveLonelyBook()
        {
            var bookManagerMock = new Mock <IBookManager>();
            var loanManagerMock = new Mock <ILoanManager>();

            bookManagerMock.Setup(m =>
                                  m.GetBookByBookTitle(It.IsAny <string>()))
            .Returns(new Book
            {
                BookTitle = "Oliver Twist",
                Loan      = new List <Loan>()
            });

            var libraryAPI  = new BookAPI(bookManagerMock.Object, loanManagerMock.Object);
            var successfull = libraryAPI.RemoveBook("Oliver Twist");

            Assert.AreEqual(BookStatusCodes.Ok, successfull);
            bookManagerMock.Verify(m =>
                                   m.RemoveBook(It.IsAny <int>()), Times.Once);
        }
        public void TestRemoveExistingBook()
        {
            var bookManagerMock  = new Mock <IBookManager>();
            var loanManagerMock  = new Mock <ILoanManager>();
            var shelfManagerMock = new Mock <IShelfManager>();

            bookManagerMock.Setup(m =>
                                  m.GetBookByBookNumber(It.IsAny <int>()))
            .Returns(new Book
            {
                BookNumber = 4,
                Loans      = new List <Loan>()
            });

            var BookAPI     = new BookAPI(bookManagerMock.Object, shelfManagerMock.Object, null);
            var successfull = BookAPI.RemoveBook(4);

            Assert.AreEqual(ErrorCodesRemoveBook.Ok, successfull);
            bookManagerMock.Verify(m =>
                                   m.RemoveBook(It.IsAny <int>()), Times.Once);
        }
示例#8
0
        public void RemoveBook()
        {
            var bookManagerMock  = new Mock <IBookManager>();
            var shelfManagerMock = new Mock <IShelfManager>();


            bookManagerMock.Setup(m =>
                                  m.GetBookByNumber(It.IsAny <long>()))
            .Returns(new Book
            {
                BookOnLoan = new List <BookOnLoan>()
            });



            var bookAPI     = new BookAPI(bookManagerMock.Object, shelfManagerMock.Object);
            var successfull = bookAPI.RemoveBook(9780132911221);

            Assert.AreEqual(RemoveBookErrorCodes.OK, successfull);
            bookManagerMock.Verify(m =>
                                   m.RemoveBook(It.IsAny <long>()), Times.Once);
        }
        public void TestRemoveBookThatIsLoaned()
        {
            var bookManagerMock = new Mock <IBookManager>();
            var loanManagerMock = new Mock <ILoanManager>();

            bookManagerMock.Setup(m =>
                                  m.GetBookByBookTitle(It.IsAny <string>()))
            .Returns(new Book
            {
                BookTitle = "Middagstipset",
                Loan      = new List <Loan>
                {
                    new Loan()
                }
            });

            var bookAPI     = new BookAPI(bookManagerMock.Object, loanManagerMock.Object);
            var successfull = bookAPI.RemoveBook("Middagstipset");

            Assert.AreEqual(BookStatusCodes.BookIsLoaned, successfull);
            bookManagerMock.Verify(m =>
                                   m.RemoveBook(It.IsAny <int>()), Times.Never);
        }
        public void TestRemoveBookWithActiveLoan()
        {
            var bookManagerMock = new Mock <IBookManager>();
            var loanManagerMock = new Mock <ILoanManager>();

            bookManagerMock.Setup(m =>
                                  m.GetBookByBookNumber(It.IsAny <int>()))
            .Returns(new Book
            {
                BookNumber = 3,
                Loans      = new List <Loan>
                {
                    new Loan()
                }
            });

            var bookAPI     = new BookAPI(bookManagerMock.Object, null, loanManagerMock.Object);
            var successfull = bookAPI.RemoveBook(3);

            Assert.AreEqual(ErrorCodesRemoveBook.BookBelongsToAnActiveLoan, successfull);
            bookManagerMock.Verify(m =>
                                   m.RemoveBook(It.IsAny <int>()), Times.Never);
        }