Example #1
0
        public void TestBorrowBookWithAlreadyMaxAmountOfBooks()
        {
            var costumerManagerMock = new Mock <ICostumerManager>();
            var bookManagerMock     = new Mock <IBookManager>();

            var costumerAPI = new CostumerAPI(costumerManagerMock.Object, bookManagerMock.Object);

            bookManagerMock.Setup(m =>
                                  m.GetBookByName(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <int>()))
            .Returns(new Book
            {
                BookID        = 20,
                BookName      = "Clean Code",
                InLibrary     = true,
                BookCondition = 4,
            });

            costumerManagerMock.Setup(m =>
                                      m.GetCostumerByCostumerName(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <string>()))
            .Returns(new Costumer
            {
                CostumerName  = "Jan",
                CostumerID    = 10,
                AmountOfBooks = 5,
                IsInDebt      = false
            });

            var successfull = costumerAPI.SetCostumerToBook(0, 0, "Jan", "1990-01-01", false, false, 0, "Clean Code", false, 5, "Fågelvägen 1");

            Assert.AreEqual(BorrowBookCodes.CostumerHaveMaxAmountOfBooks, successfull);
            costumerManagerMock.Verify(
                m => m.SetCostumerToBook(0, 0),
                Times.Never());
        }
Example #2
0
        public void TestBorrowNoneExistingBook()
        {
            var costumerManagerMock = new Mock <ICostumerManager>();
            var bookManagerMock     = new Mock <IBookManager>();

            var costumerAPI = new CostumerAPI(costumerManagerMock.Object, bookManagerMock.Object);


            costumerManagerMock.Setup(m =>
                                      m.GetCostumerByCostumerName(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <string>()))
            .Returns(new Costumer());

            var successfull = costumerAPI.SetCostumerToBook(0, 0, "Jan", "1990-01-01", false, false, 0, "Clean Code", false, 5, "Fågelvägen 1");

            Assert.AreEqual(BorrowBookCodes.NoBooksToBorrow, successfull);
            costumerManagerMock.Verify(
                m => m.SetCostumerToBook(0, 0),
                Times.Never());
        }