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