Esempio n. 1
0
        private bool AddAisleNumberOne(Mock <IAisleManager> libraryManagerMock)
        {
            var libraryAPI  = new LibraryAPI(libraryManagerMock.Object, null);
            var successfull = libraryAPI.AddAisle(1);

            return(successfull);
        }
Esempio n. 2
0
        public void TestMoveBook()
        {
            var sectionManagerMock = new Mock <ISectionManager>();
            var shelfManagerMock   = new Mock <IShelfManager>();
            var bookManagerMock    = new Mock <IBookManager>();

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

            bookManagerMock.Setup(m =>
                                  m.GetBookByName(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <int>()))
            .Returns(new Book
            {
                BookID = 1,
                Shelf  = new Shelf()
            });

            var libraryAPI = new LibraryAPI(sectionManagerMock.Object, shelfManagerMock.Object, bookManagerMock.Object);
            var result     = libraryAPI.MoveBook("Clean Code", true, 2, 5);

            Assert.AreEqual(MoveBookCodes.Ok, result);
            bookManagerMock.Verify(m =>
                                   m.MoveBook(1, 1), Times.Once());
        }
Esempio n. 3
0
        public void TestRemoveBorrowedBook()
        {
            var sectionManagerMock = new Mock <ISectionManager>();
            var shelfManagerMock   = new Mock <IShelfManager>();
            var bookManagerMock    = new Mock <IBookManager>();

            bookManagerMock.Setup(m =>
                                  m.GetBookByName(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <int>()))
            .Returns(new Book
            {
                BookID    = 1,
                InLibrary = false
            });

            bookManagerMock.Setup(m =>
                                  m.RemoveBook(It.IsAny <int>()));

            var libraryAPI  = new LibraryAPI(sectionManagerMock.Object, shelfManagerMock.Object, bookManagerMock.Object);
            var successfull = libraryAPI.RemoveBook("Clean Code", false, 5);

            Assert.AreEqual(RemoveBookCodes.CantRemoveBorrowedBook, successfull);
            bookManagerMock.Verify(
                m => m.RemoveBook(It.IsAny <int>()),
                Times.Never());
        }
Esempio n. 4
0
        public void TestMoveShelf()
        {
            var sectionManagerMock = new Mock <ISectionManager>();
            var shelfManagerMock   = new Mock <IShelfManager>();
            var bookManagerMock    = new Mock <IBookManager>();

            sectionManagerMock.Setup(m =>
                                     m.GetSectionBySectionNumber(It.IsAny <int>()))
            .Returns(new Section {
                SectionID = 1
            });

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

            var libraryAPI = new LibraryAPI(sectionManagerMock.Object, shelfManagerMock.Object, bookManagerMock.Object);
            var result     = libraryAPI.MoveShelf(2, 2);

            Assert.AreEqual(MoveShelfCodes.Ok, result);
            shelfManagerMock.Verify(m =>
                                    m.MoveShelf(1, 1), Times.Once());
        }
Esempio n. 5
0
        public void TestMoveShelfOk()
        {
            var aisleManagerMock = new Mock <IAisleManager>();
            var shelfManagerMock = new Mock <IShelfManager>();

            aisleManagerMock.Setup(m =>
                                   m.GetAisleByAisleNumber(It.IsAny <int>()))
            .Returns(new Aisle {
                AisleID = 2
            });

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

            var libraryAPI = new LibraryAPI(aisleManagerMock.Object, shelfManagerMock.Object);
            var result     = libraryAPI.MoveShelf(101, 1);

            Assert.AreEqual(ShelfStatusCodes.Ok, result);
            shelfManagerMock.Verify(m =>
                                    m.MoveShelf(2, 2), Times.Once());
        }
Esempio n. 6
0
        private static AddBookErrorCodes AddBookNumberOne(Mock <IBookManager> bookManagerMock)
        {
            var libraryAPI  = new LibraryAPI(null, null, bookManagerMock.Object, null);
            var successfull = libraryAPI.AddBook(1, "Astrophysics for People in a Hurry", " Neil Degrasse Tyson", "9780393609394", 2);

            return(successfull);
        }
Esempio n. 7
0
        public void TestRemoveBookWithCustomer()
        {
            var bookManagerMock     = new Mock <IBookManager>();
            var customerManagerMock = new Mock <ICustomerManager>();

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

            customerManagerMock.Setup(m =>
                                      m.GetCustomerByCustomerNumber(It.IsAny <int>()))
            .Returns(new Customer
            {
                CustomerID = 2,
                Book       = new List <Book>()
            });

            var libraryAPI  = new LibraryAPI(null, null, bookManagerMock.Object, customerManagerMock.Object);
            var successfull = libraryAPI.RemoveBookWithCustomer(2, 1);

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

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

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

            var libraryAPI = new LibraryAPI(null, shelfManagerMock.Object, bookManagerMock.Object, null);
            var result     = libraryAPI.MoveBook(1, 1);

            Assert.AreEqual(MoveBookErrorCodes.Ok, result);
            bookManagerMock.Verify(m =>
                                   m.MoveBook(2, 2), Times.Once());
        }
Esempio n. 9
0
        private ShelfStatusCodes AddShelfNumberOne(Mock <IShelfManager> shelfManagerMock)
        {
            var aisleManagerMock = SetupMock(new Aisle {
                AisleNumber = 1
            });
            var libraryAPI  = new LibraryAPI(aisleManagerMock.Object, shelfManagerMock.Object);
            var successfull = libraryAPI.AddShelf(101, 1);

            return(successfull);
        }
Esempio n. 10
0
        public void TestAddExistingBook()
        {
            var bookManagerMock = SetupMockBook(new Book());
            var libraryAPI      = new LibraryAPI(null, null, bookManagerMock.Object, null);
            var successfull     = AddBookNumberOne(bookManagerMock);

            Assert.AreEqual(AddBookErrorCodes.Ok, successfull);
            bookManagerMock.Verify(m =>
                                   m.AddBook(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()),
                                   Times.Once());
        }
Esempio n. 11
0
        public void MoveShelfNoSuchShelf()
        {
            var aisleManagerMock = SetupMock(new Aisle {
                AisleNumber = 1
            });
            var shelfManagerMock = SetupMock((Shelf)null);

            var libraryApi = new LibraryAPI(aisleManagerMock.Object, shelfManagerMock.Object);
            var result     = libraryApi.MoveShelf(113, 1);

            Assert.AreEqual(ShelfStatusCodes.NoSuchShelf, result);
        }
Esempio n. 12
0
        public void MoveShelfNoSuchAisle()
        {
            var aisleManagerMock = SetupMock((Aisle)null);
            var shelfManagerMock = SetupMock(new Shelf {
                ShelfNumber = 101
            });

            var libraryApi = new LibraryAPI(aisleManagerMock.Object, shelfManagerMock.Object);
            var result     = libraryApi.MoveShelf(101, 9);

            Assert.AreEqual(ShelfStatusCodes.NoSuchAisle, result);
        }
Esempio n. 13
0
        public void TestAddBookBookNotGivenATitle()
        {
            var bookManagerMock = new Mock <IBookManager>();

            var libraryAPI  = new LibraryAPI(null, null, bookManagerMock.Object, null);
            var successfull = libraryAPI.AddBook(1, null, " Neil Degrasse Tyson", "9780393609394", 2);

            Assert.AreEqual(AddBookErrorCodes.BookNotGivenATitle, successfull);
            bookManagerMock.Verify(m =>
                                   m.AddBook(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()),
                                   Times.Never());
        }
Esempio n. 14
0
        public void TestAddBookBookNotGivenAnAuthor()
        {
            var bookManagerMock = new Mock <IBookManager>();

            var libraryAPI  = new LibraryAPI(null, null, bookManagerMock.Object, null);
            var successfull = libraryAPI.AddBook(1, "Astrophysics for People in a Hurry", null, "9780393609394", 2);

            Assert.AreEqual(AddBookErrorCodes.BookNotGivenAnAuthor, successfull);
            bookManagerMock.Verify(m =>
                                   m.AddBook(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()),
                                   Times.Never());
        }
Esempio n. 15
0
        public void TestAddBookISBNNumberNotValid()
        {
            var bookManagerMock = new Mock <IBookManager>();

            var libraryAPI  = new LibraryAPI(null, null, bookManagerMock.Object, null);
            var successfull = libraryAPI.AddBook(1, "Astrophysics for People in a Hurry", " Neil Degrasse Tyson", "9780393609395", 2);

            Assert.AreEqual(AddBookErrorCodes.ISBNNumberNotValid, successfull);
            bookManagerMock.Verify(m =>
                                   m.AddBook(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()),
                                   Times.Never());
        }
Esempio n. 16
0
        public void InsertAPI(LibraryAPI libraryAPI)
        {
            Library library = new Library();
            Code    code    = DataRepository.Code.GetByNameAndUpper(libraryAPI.LocationId[0]);

            library.LocationId  = DataRepository.Code.GetByNameAndUpper(libraryAPI.LocationId[1], code.CodeId).CodeId;
            library.LibraryId   = libraryAPI.LibraryId;
            library.Name        = libraryAPI.Name;
            library.Address     = libraryAPI.Address;
            library.Website     = libraryAPI.Website;
            library.PhoneNumber = libraryAPI.PhoneNumber;
            DataRepository.Library.Insert(library);
        }
Esempio n. 17
0
        public void TestRemoveNonExistingShelf()
        {
            var shelfManagerMock = new Mock <IShelfManager>();
            var bookManagerMock  = new Mock <IBookManager>();

            shelfManagerMock.Setup(m =>
                                   m.GetShelfByShelfNumber(It.IsAny <int>(), It.IsAny <int>()))
            .Returns((Shelf)null);

            var libraryAPI  = new LibraryAPI(shelfManagerMock.Object, bookManagerMock.Object);
            var successfull = libraryAPI.RemoveShelf(106, 6);

            Assert.AreEqual(ShelfStatusCodes.NoSuchShelf, successfull);
            shelfManagerMock.Verify(m =>
                                    m.RemoveShelf(It.IsAny <int>()), Times.Never);
        }
Esempio n. 18
0
        public void TestRemoveNonExistingAisle()
        {
            var aisleManagerMock = new Mock <IAisleManager>();
            var shelfManagerMock = new Mock <IShelfManager>();

            aisleManagerMock.Setup(m =>
                                   m.GetAisleByAisleNumber(It.IsAny <int>()))
            .Returns((Aisle)null);

            var libraryAPI  = new LibraryAPI(aisleManagerMock.Object, shelfManagerMock.Object);
            var successfull = libraryAPI.RemoveAisle(4);

            Assert.AreEqual(AisleStatusCodes.NoSuchAisle, successfull);
            aisleManagerMock.Verify(m =>
                                    m.RemoveAisle(It.IsAny <int>()), Times.Never);
        }
Esempio n. 19
0
        public void TestRemoveNoneExistingSection()
        {
            var sectionManagerMock = new Mock <ISectionManager>();
            var shelfManagerMock   = new Mock <IShelfManager>();
            var bookManagerMock    = new Mock <IBookManager>();

            sectionManagerMock.Setup(m =>
                                     m.GetSectionBySectionNumber(It.IsAny <int>()))
            .Returns((Section)null);

            var libraryAPI  = new LibraryAPI(sectionManagerMock.Object, shelfManagerMock.Object, bookManagerMock.Object);
            var successfull = libraryAPI.RemoveSection(1);

            Assert.AreEqual(RemoveSectionCodes.NoSuchSection, successfull);
            sectionManagerMock.Verify(m =>
                                      m.RemoveSection(It.IsAny <int>()), Times.Never);
        }
Esempio n. 20
0
        public void TestAddShelf()
        {
            var shelfManagerMock = new Mock <IShelfManager>();
            var aisleManagerMock = new Mock <IAisleManager>();

            shelfManagerMock.Setup(m =>
                                   m.AddShelf(It.IsAny <int>()));

            shelfManagerMock.Setup(m =>
                                   m.GetShelfByShelfNumber(It.IsAny <int>()));

            var libraryAPI  = new LibraryAPI(aisleManagerMock.Object, shelfManagerMock.Object, null, null);
            var successfull = libraryAPI.AddShelf(1);

            Assert.IsTrue(successfull);
            shelfManagerMock.Verify(m =>
                                    m.AddShelf(It.Is <int>(i => i == 1)),
                                    Times.Once());
        }
Esempio n. 21
0
        public void TestRemoveEmptyShelf()
        {
            var bookManagerMock  = new Mock <IBookManager>();
            var shelfManagerMock = new Mock <IShelfManager>();

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

            var libraryAPI  = new LibraryAPI(null, shelfManagerMock.Object, bookManagerMock.Object, null);
            var successfull = libraryAPI.RemoveShelf(4);

            Assert.AreEqual(RemoveShelfErrorCodes.Ok, successfull);
            shelfManagerMock.Verify(m =>
                                    m.RemoveShelf(It.IsAny <int>()), Times.Once);
        }
Esempio n. 22
0
        public void TestRemoveEmptyAisle()
        {
            var aisleManagerMock = new Mock <IAisleManager>();
            var shelfManagerMock = new Mock <IShelfManager>();

            aisleManagerMock.Setup(m =>
                                   m.GetAisleByAisleNumber(It.IsAny <int>()))
            .Returns(new Aisle
            {
                AisleNumber = 4,
                Shelf       = new List <Shelf>()
            });

            var libraryAPI  = new LibraryAPI(aisleManagerMock.Object, shelfManagerMock.Object);
            var successfull = libraryAPI.RemoveAisle(4);

            Assert.AreEqual(AisleStatusCodes.Ok, successfull);
            aisleManagerMock.Verify(m =>
                                    m.RemoveAisle(It.IsAny <int>()), Times.Once);
        }
Esempio n. 23
0
        public void TestSetPriceOnNoneExistingBook()
        {
            var SectionManagerMock = new Mock <ISectionManager>();
            var shelfManagerMock   = new Mock <IShelfManager>();
            var BookManagerMock    = new Mock <IBookManager>();

            BookManagerMock.Setup(m =>
                                  m.GetBookByName(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <int>()))
            .Returns((Book)null);

            BookManagerMock.Setup(m =>
                                  m.SetBookPrice(It.IsAny <string>(), It.IsAny <int>()));

            var libraryAPI  = new LibraryAPI(SectionManagerMock.Object, shelfManagerMock.Object, BookManagerMock.Object);
            var successfull = libraryAPI.SetBookPrice("Clean Code", 199, true, 5);

            Assert.IsFalse(successfull);
            BookManagerMock.Verify(
                m => m.SetBookPrice(It.Is <string>(i => i == "Clean Code"), It.Is <int>(i => i == 199)),
                Times.Never());
        }
Esempio n. 24
0
        public void TestRemoveEmptySection()
        {
            var sectionManagerMock = new Mock <ISectionManager>();
            var shelfManagerMock   = new Mock <IShelfManager>();
            var bookManagerMock    = new Mock <IBookManager>();

            sectionManagerMock.Setup(m =>
                                     m.GetSectionBySectionNumber(It.IsAny <int>()))
            .Returns(new Section
            {
                SectionNumber = 1,
                Shelfs        = new List <Shelf>()
            });

            var libraryAPI  = new LibraryAPI(sectionManagerMock.Object, shelfManagerMock.Object, bookManagerMock.Object);
            var successfull = libraryAPI.RemoveSection(1);

            Assert.AreEqual(RemoveSectionCodes.Ok, successfull);
            sectionManagerMock.Verify(m =>
                                      m.RemoveSection(It.IsAny <int>()), Times.Once);
        }
Esempio n. 25
0
        public void TestAddSection()
        {
            var SectionManagerMock = new Mock <ISectionManager>();
            var shelfManagerMock   = new Mock <IShelfManager>();
            var BookManagerMock    = new Mock <IBookManager>();

            SectionManagerMock.Setup(m =>
                                     m.GetSectionBySectionNumber(It.IsAny <int>()))
            .Returns((Section)null);

            SectionManagerMock.Setup(m =>
                                     m.AddSection(It.IsAny <int>()));


            var libraryAPI  = new LibraryAPI(SectionManagerMock.Object, shelfManagerMock.Object, BookManagerMock.Object);
            var successfull = libraryAPI.AddSection(1);

            Assert.IsTrue(successfull);
            SectionManagerMock.Verify(
                m => m.AddSection(It.Is <int>(i => i == 1)),
                Times.Once());
        }
Esempio n. 26
0
        public void TestAddExistingShelf()
        {
            var sectionManagerMock = new Mock <ISectionManager>();
            var shelfManagerMock   = new Mock <IShelfManager>();
            var BookManagerMock    = new Mock <IBookManager>();

            shelfManagerMock.Setup(m =>
                                   m.GetShelfByShelfNumber(It.IsAny <int>()))
            .Returns(new Shelf());

            shelfManagerMock.Setup(m =>
                                   m.AddShelf(It.IsAny <int>()));


            var libraryAPI  = new LibraryAPI(sectionManagerMock.Object, shelfManagerMock.Object, BookManagerMock.Object);
            var successfull = libraryAPI.AddShelf(1);

            Assert.IsFalse(successfull);
            shelfManagerMock.Verify(
                m => m.AddShelf(It.Is <int>(i => i == 1)),
                Times.Never());
        }
Esempio n. 27
0
        public void TestRemoveAisleWithOneShelf()
        {
            var aisleManagerMock = new Mock <IAisleManager>();
            var shelfManagerMock = new Mock <IShelfManager>();

            aisleManagerMock.Setup(m =>
                                   m.GetAisleByAisleNumber(It.IsAny <int>()))
            .Returns(new Aisle
            {
                AisleNumber = 4,
                Shelf       = new List <Shelf>
                {
                    new Shelf()
                }
            });

            var libraryAPI  = new LibraryAPI(aisleManagerMock.Object, shelfManagerMock.Object, null, null);
            var successfull = libraryAPI.RemoveAisle(4);

            Assert.AreEqual(RemoveAisleErrorCodes.AisleHasShelves, successfull);
            aisleManagerMock.Verify(m =>
                                    m.RemoveAisle(It.IsAny <int>()), Times.Never);
        }
Esempio n. 28
0
        public void TestRemoveShelfWithOneBook()
        {
            var shelfManagerMock = new Mock <IShelfManager>();
            var bookManagerMock  = new Mock <IBookManager>();

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

            var libraryAPI  = new LibraryAPI(shelfManagerMock.Object, bookManagerMock.Object);
            var successfull = libraryAPI.RemoveShelf(101, 1);

            Assert.AreEqual(ShelfStatusCodes.ShelfHasBooks, successfull);
            shelfManagerMock.Verify(m =>
                                    m.RemoveShelf(It.IsAny <int>()), Times.Never);
        }
Esempio n. 29
0
        public void TestAddExistingBook()
        {
            var SectionManagerMock = new Mock <ISectionManager>();
            var shelfManagerMock   = new Mock <IShelfManager>();
            var BookManagerMock    = new Mock <IBookManager>();

            BookManagerMock.Setup(m =>
                                  m.GetBookByName(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <int>()))
            .Returns(new Book());

            BookManagerMock.Setup(m =>
                                  m.AddBook(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <long>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <int>()));


            var libraryAPI  = new LibraryAPI(SectionManagerMock.Object, shelfManagerMock.Object, BookManagerMock.Object);
            var successfull = libraryAPI.AddBook("Clean Code", 199, 9780132350884, true, true, 5);

            Assert.IsFalse(successfull);
            BookManagerMock.Verify(
                m => m.AddBook(It.Is <string>(i => i == "Clean Code"), It.Is <int>(i => i == 199), It.Is <long>(i => i == 9780132350884),
                               It.Is <bool>(i => i == true), It.Is <bool>(i => i == true), It.Is <int>(i => i == 5)),
                Times.Never());
        }