public Delete ( |
||
model | The page to remove. | |
return | int |
/// <summary> /// Deletes a page from the database. /// </summary> /// <param name="pageId">The id of the page to remove.</param> /// <exception cref="DatabaseException">An databaseerror occurred while deleting the page.</exception> public void DeletePage(int pageId) { try { // Avoid grabbing all the pagecontents coming back each time a page is requested, it has no inverse relationship. Page page = Repository.GetPageById(pageId); // Update the lucene index before we actually delete the page. try { PageViewModel model = new PageViewModel(Repository.GetLatestPageContent(page.Id), _markupConverter); _searchService.Delete(model); } catch (SearchException ex) { Log.Error(ex, "Unable to delete page with id {0} from the lucene index", pageId); } IList <PageContent> children = Repository.FindPageContentsByPageId(pageId).ToList(); for (int i = 0; i < children.Count; i++) { Repository.DeletePageContent(children[i]); } Repository.DeletePage(page); // Remove everything for now, to avoid reciprocal link issues _listCache.RemoveAll(); _pageViewModelCache.RemoveAll(); } catch (DatabaseException ex) { throw new DatabaseException(ex, "An error occurred while deleting the page id {0} from the database", pageId); } }
public void Delete_Should_Remove_Page_From_Index() { // Arrange SearchService searchService = new SearchService(_config, _repository, _pluginFactory); searchService.CreateIndex(); PageViewModel page1 = CreatePage(1, "admin", "homepage title", "homepage1, tag1", "title content"); PageViewModel page2 = CreatePage(2, "admin", "random name2", "tag1", "random name 2"); searchService.Add(page1); searchService.Add(page2); // Act searchService.Delete(page1); List<SearchResultViewModel> results = searchService.Search("homepage title").ToList(); // Assert Assert.That(results.Count, Is.EqualTo(0), "homepage title still appears after deletion"); }