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 ) ); } }
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); } }