Example #1
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")
             );
     }
 }
 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);
 }
 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);
 }
        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);
        }
        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);
            }
        }