예제 #1
0
        protected override void ProcessRecord()
        {
            try
            {
                LibraryClient lc = new LibraryClient();

                bool updated = lc.UpdateBook(ISBN, BookName, Author, Description);
                if (updated)
                {
                    WriteObject("Successfully updated the book");
                }
                else
                {
                    throw new Exception("Book not updated");
                }
            }
            catch (Exception e)
            {
                WriteError(
                    new ErrorRecord(
                        e,
                        "UpdateBookException",
                        ErrorCategory.NotSpecified,
                        ISBN
                        )
                    );
            }
        }
예제 #2
0
        protected override void ProcessRecord()
        {
            try
            {
                LibraryClient lc = new LibraryClient();

                bool updated = lc.IssueBook(ISBN, EmpName);
                if (updated)
                {
                    WriteObject("Successfully issued the book");
                }
                else
                {
                    throw new Exception("book can't be issued");
                }
            }
            catch (Exception e)
            {
                WriteError(
                    new ErrorRecord(
                        e,
                        "IssueBookException",
                        ErrorCategory.NotSpecified,
                        ISBN
                        )
                    );
            }
        }
예제 #3
0
        protected override void ProcessRecord()
        {
            try
            {
                LibraryClient lc = new LibraryClient();

                bool returned = lc.ReturnBook(ISBN);
                if (returned)
                {
                    WriteObject("Successfully returned the book");
                }
                else
                {
                    throw new Exception("book can't be returned");
                }
            }
            catch (Exception e)
            {
                WriteError(
                    new ErrorRecord(
                        e,
                        "ReturnBookException",
                        ErrorCategory.NotSpecified,
                        ISBN
                        )
                    );
            }
        }
예제 #4
0
 protected override void ProcessRecord()
 {
     try
     {
         LibraryClient lc = new LibraryClient();
         List<Book> bookList = lc.GetAllBooks();
         if (bookList.Count() > 0)
         {
             WriteObject(bookList);
         }
         else
         {
             throw new Exception("Could not get the book list");
         }
     }
     catch (Exception e)
     {
         WriteError(
             new ErrorRecord(
                 e,
                 "GetAllBooksException",
                 ErrorCategory.NotSpecified, "GetAllBooks")
             );
     }
 }
예제 #5
0
 protected override void ProcessRecord()
 {
     try
     {
         LibraryClient lc = new LibraryClient();
         Book book = lc.GetBook(ISBN);
         if (book != null)
         {
             WriteObject(book);
         }
         else
         {
             throw new Exception("Could not get the book");
         }
     }
     catch (Exception e)
     {
         WriteError(
             new ErrorRecord(
                 e,
                 "GetAllBooksException",
                 ErrorCategory.NotSpecified, "GetAllBooks")
             );
     }
 }
예제 #6
0
        protected override void ProcessRecord()
        {
            try
            {
                LibraryClient lc = new LibraryClient();

                bool deleted = lc.DeleteBook(ISBN);
                if (deleted)
                {
                    WriteObject("Successfully deleted the book");
                }
                else
                {
                    throw new Exception("Could not delete the book");
                }
            }
            catch (Exception e)
            {
                WriteError(
                    new ErrorRecord(
                        e,
                        "DeleteBookException",
                        ErrorCategory.NotSpecified,
                        ISBN
                        )
                    );
            }
        }
예제 #7
0
        public void TestLoad()
        {
            TestSetup();
            LibraryClient lc = new LibraryClient();
            string isbn;
            string name;
            string author;
            string description;

            for (int i = 0; i < 1000; i++)
            {
                isbn = "" + i;
                name = "name" + i;
                author = "author" + i;
                description = "description" + i;
                Assert.IsTrue(lc.AddNewBook(isbn, name, author, description));
            }

            List<Book> books = lc.GetAllBooks();
            Assert.AreEqual(1000, books.Count);
            Assert.AreEqual("123", lc.GetBook("123").Isbn);
            Assert.AreEqual("999", lc.GetBook("999").Isbn);
        }
예제 #8
0
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            lc = new LibraryClient();
            this.cmdAdd.Click += new System.EventHandler(this.cmdAdd_Click);
            this.cmdUpdate.Click += new System.EventHandler(this.cmdUpdate_Click);
            this.cmdDelete.Click += new System.EventHandler(this.cmdDelete_Click);
            this.cmdIssue.Click += new System.EventHandler(this.cmdIssue_Click);
            this.cmdReturn.Click += new System.EventHandler(this.cmdReturn_Click);

            this.Load += new System.EventHandler(this.Page_Load);
        }
예제 #9
0
        public static void EntryPoint()
        {
            LibraryClient lc = new LibraryClient();
            string isbn;
            string name;
            string author;
            string description;

            for (int i = 0; i < 10; i++)
            {
                isbn = "" + i;
                name = "name" + i;
                author = "author" + i;
                description = "description" + i;
                try
                {
                    bool sucess = lc.AddNewBook(isbn, name, author, description);
                    if (!sucess)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception) {
                    count++;
                }

            }
        }
예제 #10
0
 public void TestSecurity()
 {
     TestSetup();
     LibraryClient lc = new LibraryClient();
     Assert.IsTrue(lc.AddNewBook("01", "name1", "author1", "desc1"));
     Assert.IsTrue(lc.AddNewBook("02", "name2", "author2", "desc2"));
     Assert.IsTrue(lc.AddNewBook("03", "name3", "author3", "desc3"));
     try
     {
         Book b = lc.GetBook("03' ; DELETE FROM tbl_book; select * from tbl_book where isbn = '01");
     }
     catch (Exception)
     {
     }
     Assert.AreEqual(3,lc.GetAllBooks().Count);
 }
예제 #11
0
        public void TestReturnBook()
        {
            TestSetup();
            LibraryClient lc = new LibraryClient();
            Assert.IsTrue(lc.AddNewBook("01", "name1", "author1", "desc1"));
            Assert.IsTrue(lc.AddNewBook("02", "name2", "author2", "desc2"));
            Assert.IsTrue(lc.AddNewBook("03", "name3", "author3", "desc3"));
            Assert.IsTrue(lc.IssueBook("01", "emp1"));
            Assert.IsTrue(lc.IssueBook("02", "emp1"));
            try
            {
                lc.IssueBook("02", "emp2");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("Book is already issued...!", e.Message);
            }
            Assert.IsTrue(lc.ReturnBook("02"));
            Assert.IsTrue(lc.IssueBook("02", "emp2"));
            Assert.AreEqual("emp2", lc.GetBook("02").Borrowed_by);

            try
            {
                lc.ReturnBook("sdfsffd");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("Wrong ISBN...!", e.Message);
            }

            try
            {
                lc.ReturnBook("");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("ISBN is required...!", e.Message);
            }

            try
            {
                lc.ReturnBook("03");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("Book is already returned...!", e.Message);
            }
        }
예제 #12
0
        public void TestIssueBook()
        {
            TestSetup();
            LibraryClient lc = new LibraryClient();
            Assert.IsTrue(lc.AddNewBook("01", "name1", "author1", "desc1"));
            Assert.IsTrue(lc.AddNewBook("02", "name2", "author2", "desc2"));
            Assert.IsTrue(lc.AddNewBook("03", "name3", "author3", "desc3"));
            Assert.IsTrue(lc.IssueBook("01", "emp1"));
            Assert.IsTrue(lc.IssueBook("02", "emp1"));
            try
            {
                lc.IssueBook("01", "emp2");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("Book is already issued...!", e.Message);
            }

            try
            {
                lc.IssueBook("", "emp2");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("ISBN is required...!", e.Message);
            }

            try
            {
                lc.IssueBook("werrwre", "emp2");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("Wrong ISBN...!", e.Message);
            }

            try
            {
                lc.IssueBook("03", "");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("Employee Name is required...!", e.Message);
            }
        }
예제 #13
0
 public void TestGetAllBooks()
 {
     TestSetup();
     LibraryClient lc = new LibraryClient();
     Assert.AreEqual(0, lc.GetAllBooks().Count);
     Assert.IsTrue(lc.AddNewBook("01", "name1", "author1", "desc1"));
     Assert.IsTrue(lc.AddNewBook("02", "name2", "author2", "desc2"));
     List<Book> actualBooks = lc.GetAllBooks();
     Assert.AreEqual(2, actualBooks.Count);
     Assert.AreEqual("author1", actualBooks.ElementAt(0).Author);
     Assert.AreEqual("name1", actualBooks.ElementAt(0).Name);
     Assert.AreEqual("desc1", actualBooks.ElementAt(0).Description);
     Assert.AreEqual("author2", actualBooks.ElementAt(1).Author);
     Assert.AreEqual("name2", actualBooks.ElementAt(1).Name);
     Assert.AreEqual("desc2", actualBooks.ElementAt(1).Description);
 }
예제 #14
0
        public void TestEditBook()
        {
            TestSetup();
            LibraryClient lc = new LibraryClient();
            Assert.IsTrue(lc.AddNewBook("01", "name1", "author1", "desc1"));
            Assert.IsTrue(lc.AddNewBook("03", "name3", "author3", "desc3"));
            Assert.IsTrue(lc.UpdateBook("01", "name2", "author2", "desc2"));
            Book actualBook = lc.GetBook("01");
            Assert.AreEqual("author2", actualBook.Author);
            Assert.AreEqual("name2", actualBook.Name);
            Assert.AreEqual("desc2", actualBook.Description);

            Book actualBook3 = lc.GetBook("03");
            Assert.AreEqual("author3", actualBook3.Author);
            Assert.AreEqual("name3", actualBook3.Name);
            Assert.AreEqual("desc3", actualBook3.Description);

            try
            {
                lc.UpdateBook("", "name2", "author2", "desc2");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("ISBN is required...!", e.Message);
            }

            try
            {
                lc.UpdateBook("456", "name2", "author2", "desc2");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("Wrong ISBN...!", e.Message);
            }
        }
예제 #15
0
        public void TestDeleteBook()
        {
            TestSetup();
            LibraryClient lc = new LibraryClient();
            Assert.IsTrue(lc.AddNewBook("01", "name1", "author1", "desc1"));
            Assert.IsTrue(lc.AddNewBook("02", "name2", "author2", "desc2"));
            Assert.IsTrue(lc.AddNewBook("03", "name3", "author3", "desc3"));
            Assert.AreEqual(3, lc.GetAllBooks().Count);
            Assert.IsTrue(lc.DeleteBook("02"));
            Assert.AreEqual(2, lc.GetAllBooks().Count);
            Assert.AreEqual(null, lc.GetBook("02"));

            try
            {
                lc.DeleteBook("");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("ISBN is required...!", e.Message);
            }

            try
            {
                lc.DeleteBook("56");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("Wrong ISBN...!", e.Message);
            }
        }
예제 #16
0
        public void TestAddBookAsBook()
        {
            TestSetup();
            LibraryClient lc = new LibraryClient();
            Book expectedBook = new Book() { Isbn = "01", Author = "author1", Description = "desc1", Name = "name1" };
            Assert.IsTrue(lc.AddNewBook(expectedBook));

            Book actualBook = lc.GetBook("01");
            Assert.AreEqual(expectedBook.Author, actualBook.Author);
            Assert.AreEqual(expectedBook.Name, actualBook.Name);
            Assert.AreEqual(expectedBook.Description, actualBook.Description);
        }
예제 #17
0
        public void TestAddBook()
        {
            TestSetup();
            LibraryClient lc = new LibraryClient();
            Assert.IsTrue(lc.AddNewBook("01", "name1", "author1", "desc1"));
            Book actualBook = lc.GetBook("01");
            Assert.AreEqual("author1", actualBook.Author);
            Assert.AreEqual("name1", actualBook.Name);
            Assert.AreEqual("desc1", actualBook.Description);

            Assert.IsTrue(lc.AddNewBook("02", "name2", "author2", "desc2"));
            Assert.IsTrue(lc.AddNewBook("03", "", "author2", "desc3"));
            Assert.IsTrue(lc.AddNewBook("04", "name4", "", "desc4"));
            Assert.IsTrue(lc.AddNewBook("05", "name5", "author5", ""));
            try
            {
                lc.AddNewBook("01", "author2", "desc2", "name2");
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("ISBN already exist...!", e.Message);
            }
        }