예제 #1
0
        public void BookTest()
        {
            // arrange
            BookDAL dal = new BookDAL(MagicSetup.Connection);
            // act create
            int rv1 = dal.BookCreate("ISBN1", "Test1", 100, 20.0M, 1);

            Assert.IsTrue(rv1 > 0, $"BookCreate failed rv = {rv1}");

            Book a = dal.BookFindByID(rv1);

            Assert.IsNotNull(a, $"BookFindByID for ID {rv1} (just created) returned null");
            Assert.IsTrue(a.BookName == "Test1");
            Assert.IsTrue(a.Pages == 100);
            Assert.IsTrue(a.GenreID == 1);

            int countofBooks = dal.BooksObtainCount();

            Assert.IsTrue(countofBooks > 0, $"BooksObtainCount should be greater than 0 it is {countofBooks}");
            List <Book> Books = dal.BooksGetAll();

            Assert.IsTrue(Books.Count == countofBooks, $"BooksGetAll should have brought back {countofBooks} records, but it only found {Books.Count}");

            int number = dal.BookUpdateJust(rv1, "ISBN1New", "Test1New", 200, 20.0M, 0);

            Assert.IsTrue(number == 1);
            a = dal.BookFindByID(rv1);
            Assert.IsNotNull(a, $"BookFindByID for ID {rv1} (just updated) returned null");
            Assert.IsTrue(a.BookName == "Test1New");
            Assert.IsTrue(a.Pages == 200);
            Assert.IsTrue(a.GenreID == 0);
            number = dal.BookUpdateSafe(rv1, "ISBN1New", "Test1New", 200, 20.0M, 0, "ISBN1Newer", "1", 300, 30.0M, 3);
            Assert.IsTrue(number == 1);
            a = dal.BookFindByID(rv1);
            Assert.IsNotNull(a, $"BookFindByID for ID {rv1} (just safe updated) returned null");
            Assert.IsTrue(a.BookName == "1", $"bookname after safeupdate was expected to be '1' but was actually '{a.BookName}'");
            Assert.IsTrue(a.Pages == 300, $"pages after safeupdate was expected to be '200' but was actually '{a.Pages}'");
            Assert.IsTrue(a.GenreID == 3, $"genreID after safeupdate was expected to be 3 but was actually '{a.GenreID}'");
            number = dal.BookUpdateSafe(rv1, "X", "1", 30, 30.0M, 0, "Y", "3", 40, 40.0M, 4);
            Assert.IsTrue(number == 0, $"bookupdatesafe was expected to return 0, but it actually returned '{number}'");

            dal.BookDelete(rv1);
        }
        public int BookUpdateSafe(
            int BookID,
            string oldISBN,
            string oldName,
            int oldPages,
            decimal oldPrice,
            int oldGenreID,
            string newISBN,
            string newName,
            int newPages,
            decimal newPrice,
            int newGenreID)
        {
            BookDAL dal = new BookDAL(_connection);

            return(dal.BookUpdateSafe(BookID,
                                      oldISBN,
                                      oldName, oldPages, oldPrice, oldGenreID,
                                      newISBN,
                                      newName, newPages, newPrice, newGenreID));
        }