public async Task DeleteForum_ForumDoesNotExist_DoesNotCallDelete() { A.CallTo(() => ForumRepository.Read(1)).Returns(null as Forum); await ForumService.Delete(1); A.CallTo(() => ForumRepository.Delete(A <Forum> .Ignored)).MustNotHaveHappened(); }
public async Task DeleteForum_UserDoesNotOwnForum_DoesNotDelete() { var forum = new Forum { UserId = "Id" }; A.CallTo(() => ForumRepository.Read(1)).Returns(forum); A.CallTo(() => UserService.Is(forum.UserId)).Returns(false); await ForumService.Delete(1); A.CallTo(() => ForumRepository.Delete(A <Forum> .Ignored)).MustNotHaveHappened(); }
public async Task <IActionResult> DeleteConfirmed(int id) { Forum forum = await _forumRep.GetForumIdAsync(id); foreach (Post post in _context.Post) { if (post.ForumId == forum) { _context.Post.Remove(post); } } _forumRep.Delete(forum); return(RedirectToAction(nameof(Index))); }
public async Task UpdateForum_UserIsAuthorized_ReturnsUpdatedForum() { var forum = new Forum { Id = 1, UserId = "User id", }; A.CallTo(() => ForumRepository.Read(1)).Returns(forum); A.CallTo(() => UserService.Is(forum.UserId)).Returns(true); await ForumService.Delete(1); A.CallTo(() => ForumRepository.Delete(A <Forum> .That.Matches(f => f.Id == forum.Id && f.UserId == forum.UserId ))).MustHaveHappenedOnceExactly(); }
protected override void ExecuteWorkImplementation() { foreach (var bookType in BookTypeHelper.GetBookTypeEnumsWithCategories()) { var category = m_categoryRepository.GetCategoryByExternalId((short)bookType); var forum = m_forumRepository.GetForumByExternalCategoryIdAndCategory(m_categoryId, category.CategoryID); if (forum == null) { throw new MainServiceException(MainServiceErrorCode.EntityNotFound, "The entity was not found", HttpStatusCode.NotFound); } if (forum.Forums.Count > 0) { throw new MainServiceException(MainServiceErrorCode.CategoryHasSubCategories, "Category has some sub-categories", HttpStatusCode.BadRequest); } var forumAccesses = m_forumRepository.GetAllAccessesForForum(forum.ForumID); m_forumRepository.DeleteAll(forumAccesses); m_forumRepository.Delete(forum); } }
protected override void ExecuteWorkImplementation() { IList <int> newCategories = m_categoryIds.Except(m_oldCategoryIds).ToList(); IList <int> deletedCategories = m_oldCategoryIds.Except(m_categoryIds).ToList(); var mainForum = m_forumRepository.GetMainForumByExternalProjectId(m_projectId); if (mainForum == null) { return; } var forumCategoriesToDelete = m_forumRepository.GetForumsByExternalCategoryIds(deletedCategories); var forums = m_forumRepository.GetForumsByExternalProjectId(m_projectId); foreach (var forum in forums) { if (forumCategoriesToDelete.Contains(forum.ParentForum)) { var forumAccesses = m_forumRepository.GetAllAccessesForForum(forum.ForumID); m_forumRepository.DeleteAll(forumAccesses); m_forumRepository.Delete(forum); } } var forumsToCreate = m_forumRepository.GetForumsByExternalCategoryIds(newCategories); foreach (var forum in forumsToCreate) { var tempForum = new Forum(mainForum.Name, forum.Category, (short)ForumTypeEnum.Forum) { ExternalProjectId = m_projectId, ParentForum = forum, RemoteURL = m_forumSiteUrlHelper.GetTopicsUrl(mainForum.ForumID) }; m_forumRepository.Create(tempForum); m_forumAccessSubwork.SetAdminAccessToForumForAdminGroup(tempForum); } }