public void DeleteBook_FirstBookInEditableCollection_RemovedFromCollection() { AddBook(); var book = _collection.GetBookInfos().First(); var bookFolder = book.FolderPath; _collection.DeleteBook(book); Assert.IsFalse(_collection.GetBookInfos().Contains(book)); Assert.IsFalse(Directory.Exists(bookFolder)); }
public bool DeleteBook(Book.Book book, BookCollection collection = null) { if (collection == null) { collection = TheOneEditableCollection; } Debug.Assert(book.FolderPath == _bookSelection.CurrentSelection?.FolderPath); if (_bookSelection.CurrentSelection != null && _bookSelection.CurrentSelection.CanDelete) { if (IsCurrentBookInCollection()) { if (!_bookSelection.CurrentSelection.IsSaveable) { var msg = LocalizationManager.GetString("TeamCollection.CheckOutForDelete", "Please check out the book before deleting it."); ErrorReport.NotifyUserOfProblem(msg); return(false); } if (_tcManager.CannotDeleteBecauseDisconnected(_bookSelection.CurrentSelection.FolderPath)) { var msg = LocalizationManager.GetString("TeamCollection.ConnectForDelete", "Please connect to the Team Collection before deleting books that are part of it."); ErrorReport.NotifyUserOfProblem(msg); return(false); } } var bookName = _bookSelection.CurrentSelection.NameBestForUserDisplay; var confirmRecycleDescription = L10NSharp.LocalizationManager.GetString("CollectionTab.ConfirmRecycleDescription", "The book '{0}'"); if (ConfirmRecycleDialog.JustConfirm(string.Format(confirmRecycleDescription, bookName), false, "Palaso")) { // The sequence of these is a bit arbitrary. We'd like to delete the book in both places. // Either could conceivably fail. If something goes wrong with removing the selection // from it (very unlikely), we may as well leave nothing changed. If we delete it from // the local collection but fail to delete it from the repo, it will come back at the // next startup. If we delete it from the repo but fail to delete it locally, // it will just stick around, and at least the desired team collection result has // been achieved and the local result won't be a surprise later. So it seems marginally // better to do them in this order. _bookSelection.SelectBook(null); if (collection == TheOneEditableCollection) { _tcManager.CurrentCollection?.DeleteBookFromRepo(book.FolderPath); } collection.DeleteBook(book.BookInfo); return(true); } } return(false); }