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


            bookManagerMock.Setup(m =>
                                  m.GetBookByBookNumber(It.IsAny <int>()))
            .Returns(new Book
            {
                BookNumber = 2
            });

            shelfManagerMock.Setup(m =>
                                   m.GetShelfByShelfNumber(It.IsAny <int>(), (It.IsAny <int>())))
            .Returns(new Shelf
            {
                ShelfID = 2
            });

            var bookAPI = new BookAPI(bookManagerMock.Object, shelfManagerMock.Object, null);
            var result  = bookAPI.AddBook("Boken om kakor", "Gunni", "9789127154377", 2018, 3, 80, 18, false, 1, 3);

            Assert.AreEqual(ErrorCodesAddBook.BookAlreadyExsist, result);
            bookManagerMock.Verify(m =>
                                   m.AddBook("Boken om kakor", "Gunni", "9789127154377", 2018, 3, 80, 18, false, 1, 3), Times.Never());
        }
        public void TestAddBookNeedShelf()
        {
            var bookManagerMock  = new Mock <IBookManager>();
            var shelfManagerMock = new Mock <IShelfManager>();
            var book             = new Book
            {
                BookNumber = 1
            };
            var bookAPI = new BookAPI(bookManagerMock.Object, shelfManagerMock.Object, null);
            var result  = bookAPI.AddBook("Boken om kakor", "Gunni", "9789127154377", 2018, 3, 80, 18, false, 1, 3);

            Assert.AreEqual(ErrorCodesAddBook.BookNeedsAShelf, result);
            bookManagerMock.Verify(m =>
                                   m.AddBook(
                                       It.IsAny <string>(),
                                       It.IsAny <string>(),
                                       It.IsAny <string>(),
                                       It.IsAny <int>(),
                                       It.IsAny <int>(),
                                       It.IsAny <int>(),
                                       It.IsAny <int>(),
                                       It.IsAny <bool>(),
                                       It.IsAny <int>(),
                                       It.IsAny <int>()),
                                   Times.Never());
        }
Esempio n. 3
0
        private static bool AddBookNumberOne(Mock <IBookManager> bookmanagerMock)
        {
            var book        = new BookAPI(bookmanagerMock.Object);
            var successfull = book.AddBook(9780132911221);

            return(successfull);
        }
        private BookStatusCodes AddBookNumberOne(Mock <IBookManager> bookManagerMock)
        {
            var shelfManagerMock = new Mock <IShelfManager>();

            var bookAPI     = new BookAPI(shelfManagerMock.Object, bookManagerMock.Object);
            var successfull = bookAPI.AddBook("Clean Code", "Robert C. Martin", "9780132350884", 452, 2019, 5, new Shelf(), false);

            return(successfull);
        }
Esempio n. 5
0
        public void AddBookToNonExistingShelf()
        {
            var shelfManagerMock = SetupMock((Shelf)null);
            var bookManagerMock  = new Mock <IBookManager>();

            var bookAPI = new BookAPI(shelfManagerMock.Object, bookManagerMock.Object);
            var result  = bookAPI.AddBook("9781526610140", "Circe", "Madeline Miller", 199, 4, 1, 3);

            Assert.AreEqual(AddBookStatusCodes.NoSuchShelf, result);
            bookManagerMock.Verify(
                m => m.AddBook("9781526610140", "Circe", "Madeline Miller", 2019, 199, 4, new Shelf(), false, null), Times.Never());
        }
Esempio n. 6
0
        //ADD BOOK:
        private AddBookStatusCodes AddFirstBookCirce(Mock <IBookManager> bookManagerMock)
        {
            var aisle = new Aisle {
                AisleNumber = 3
            };
            var shelfManagerMock = SetupMock(new Shelf
            {
                ShelfNumber = 1,
                Aisle       = aisle
            });

            var bookAPI     = new BookAPI(shelfManagerMock.Object, bookManagerMock.Object);
            var successfull = bookAPI.AddBook("9781526610140", "Circe", "Madeline Miller", 199, 4, 1, 3);

            return(successfull);
        }
        private ErrorCodesAddBook AddBookNumberOne(Mock <IBookManager> bookManagerMock)
        {
            var shelfManagerMock = new Mock <IShelfManager>();

            shelfManagerMock.Setup(m =>
                                   m.GetShelfByShelfNumber(It.IsAny <int>(), (It.IsAny <int>())))
            .Returns(new Shelf
            {
                ShelfNumber = 1,
                PathID      = 1
            });

            var bookAPI     = new BookAPI(bookManagerMock.Object, shelfManagerMock.Object, null);
            var successfull = bookAPI.AddBook("Boken om kakor", "Gunni", "9789127154377", 2018, 3, 80, 18, false, 1, 3);

            return(successfull);
        }
Esempio n. 8
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (this.mode_edit)
     {
         if (BookAPI.EditBook(Program.books, txtBookID.Text, txtBookName.Text, txtBookAuthor.Text, txtBookCount.Text))
         {
             MessageBox.Show("修改成功");
             Close();
             return;
         }
         MessageBox.Show("修改失败");
     }
     else
     {
         if (BookAPI.AddBook(Program.books, txtBookName.Text, txtBookAuthor.Text, txtBookCount.Text))
         {
             MessageBox.Show("添加成功");
             Close();
             return;
         }
         MessageBox.Show("添加失败");
         return;
     }
 }