Ejemplo n.º 1
0
        public void ExtendBorrowCustomerHasDebt()
        {
            var customerManagerMock = SetupMock(new Customer
            {
                CustomerID = 1,
                Debt       = 100
            });
            var bookManagerMock = SetupMock(new Book
            {
                BookID     = 1,
                IsBorrowed = true
            });
            var borrowManagerMock = SetupMock(new Borrow
            {
                BorrowID   = 1,
                CustomerID = 1,
                BookID     = 1
            });

            var borrowAPI = new BorrowAPI(borrowManagerMock.Object, customerManagerMock.Object, bookManagerMock.Object);
            var result    = borrowAPI.AddBorrow(000001, "Circe");

            Assert.AreEqual(AddBorrowStatusCodes.CustomerHasDebtCanNotExtendBorrow, result);
            borrowManagerMock.Verify(
                m => m.ExtendBorrowDate(It.Is <int>(i => i == 1), It.IsAny <DateTime>(), It.IsAny <DateTime>()),
                Times.Never());
        }
Ejemplo n.º 2
0
        public void ExtendBorrowOk()
        {
            var customerManagerMock = SetupMock(new Customer
            {
                CustomerID = 1,
                Debt       = 0
            });
            var bookManagerMock = SetupMock(new Book
            {
                BookID     = 1,
                IsBorrowed = true
            });
            var borrowManagerMock = SetupMock(new Borrow
            {
                BorrowID   = 1,
                CustomerID = 1,
                BookID     = 1
            });

            var borrowAPI = new BorrowAPI(borrowManagerMock.Object, customerManagerMock.Object, bookManagerMock.Object);
            var result    = borrowAPI.AddBorrow(000001, "Circe");

            Assert.AreEqual(AddBorrowStatusCodes.ExtendBorrowForCustomer, result);
            borrowManagerMock.Verify(
                m => m.ExtendBorrowDate(It.Is <int>(i => i == 1), It.IsAny <DateTime>(), It.IsAny <DateTime>()),
                Times.Once());

            borrowManagerMock.Verify(
                m => m.AddToHistoryListOfBorrow(It.Is <int>(i => i == 000001), It.Is <string>(i => i == "Circe"), It.IsAny <DateTime>()),
                Times.Once());
        }
Ejemplo n.º 3
0
        public void AddBorrowCustomerHasDebt()
        {
            var borrowManagerMock   = new Mock <IBorrowManager>();
            var customerManagerMock = SetupMock(new Customer
            {
                CustomerNumber = 000001,
                Debt           = 100
            });
            var bookManagerMock = SetupMock(new Book
            {
                BookTitle  = "Circe",
                IsBorrowed = false
            });

            borrowManagerMock.Setup(m =>
                                    m.GetAllCurrentBorrowFromCustomer(It.IsAny <int>()))
            .Returns(new List <Borrow>
            {
                new Borrow
                {
                    CustomerID = 1,
                    BookID     = 1
                },
            });

            var borrowAPI = new BorrowAPI(borrowManagerMock.Object, customerManagerMock.Object, bookManagerMock.Object);
            var result    = borrowAPI.AddBorrow(000001, "Circe");

            Assert.AreEqual(AddBorrowStatusCodes.CustomerHasDebt, result);
            borrowManagerMock.Verify(
                m => m.AddBorrow(It.Is <int>(i => i == 000001), It.Is <string>(i => i == "Circe"),
                                 It.IsAny <DateTime>(), It.IsAny <DateTime>()),
                Times.Never());
        }
Ejemplo n.º 4
0
        public void AddBorrowNoSuchCustomer()
        {
            var borrowManagerMock   = new Mock <IBorrowManager>();
            var customerManagerMock = SetupMock((Customer)null);
            var bookManagerMock     = SetupMock(new Book {
                BookTitle = "Circe"
            });

            var borrowAPI = new BorrowAPI(borrowManagerMock.Object, customerManagerMock.Object, bookManagerMock.Object);
            var result    = borrowAPI.AddBorrow(000020, "Circe");

            Assert.AreEqual(AddBorrowStatusCodes.NoSuchCustomer, result);
            borrowManagerMock.Verify(
                m => m.AddBorrow(000020, "Circe", new DateTime(), new DateTime()), Times.Never());
        }
Ejemplo n.º 5
0
        public void AddBorrowNoSuchBook()
        {
            var borrowManagerMock   = new Mock <IBorrowManager>();
            var customerManagerMock = SetupMock(new Customer {
                CustomerNumber = 000001
            });
            var bookManagerMock = SetupMock((Book)null);

            var borrowAPI = new BorrowAPI(borrowManagerMock.Object, customerManagerMock.Object, bookManagerMock.Object);
            var result    = borrowAPI.AddBorrow(000001, "HejHopp");

            Assert.AreEqual(AddBorrowStatusCodes.NoSuchBook, result);
            borrowManagerMock.Verify(
                m => m.AddBorrow(000001, "HejHopp", new DateTime(), new DateTime()), Times.Never());
        }
Ejemplo n.º 6
0
        //ADD BORROW:
        private AddBorrowStatusCodes AddBorrowNumberOne(Mock <IBorrowManager> borrowManagerMock)
        {
            var customerManagerMock = SetupMock(new Customer {
                CustomerNumber = 000001
            });
            var bookManagerMock = SetupMock(new Book
            {
                BookTitle  = "Circe",
                IsBorrowed = false
            });

            var borrowAPI   = new BorrowAPI(borrowManagerMock.Object, customerManagerMock.Object, bookManagerMock.Object);
            var successfull = borrowAPI.AddBorrow(000001, "Circe");

            return(successfull);
        }
Ejemplo n.º 7
0
        public void AddBorrowBookIsUnavailable()
        {
            var borrowManagerMock   = new Mock <IBorrowManager>();
            var customerManagerMock = SetupMock(new Customer {
                CustomerNumber = 000001
            });
            var bookManagerMock = SetupMock(new Book
            {
                BookTitle  = "Flights",
                IsBorrowed = true
            });

            var borrowAPI = new BorrowAPI(borrowManagerMock.Object, customerManagerMock.Object, bookManagerMock.Object);
            var result    = borrowAPI.AddBorrow(000001, "Flights");

            Assert.AreEqual(AddBorrowStatusCodes.BookIsUnavailable, result);
            borrowManagerMock.Verify(
                m => m.AddBorrow(000001, "Flights", new DateTime(), new DateTime()), Times.Never());
        }