public void ContentItemService_Update_DontCatchException_Test() { // Arrange Mock <IContentItemDao> mock = new Mock <IContentItemDao>(MockBehavior.Strict); mock.Setup(setup => setup.Update(It.IsAny <ContentItem>())).Throws(new Exception()); ContentItemService target = new ContentItemService(mock.Object); // Act target.Update(new ContentItem()); }
public void ContentItemService_Update_Test() { // Arrange Mock <IContentItemDao> mock = new Mock <IContentItemDao>(MockBehavior.Strict); mock.Setup(setup => setup.Update(It.IsAny <ContentItem>())); ContentItemService target = new ContentItemService(mock.Object); ContentItem contentItem = new ContentItem(); // Act target.Update(contentItem); mock.Verify(verify => verify.Update(contentItem), Times.Once); }
public ActionResult Contribute(ContentItemEditModel model) { ContentItem item = model.AsContentItem(Request); var contentItemService = new ContentItemService(); string errorMessage = string.Empty; if (item.ContentItemId > 0) { if (!authorizer.CMS_EditContentItem(item)) { errorMessage = "没有权限编辑资讯:" + item.Title; return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "没有权限", StatusMessageType = StatusMessageType.Hint }, Request.RawUrl))); } } else { if (!authorizer.CMS_Contribute(out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "没有权限", StatusMessageType = StatusMessageType.Hint }, Request.RawUrl))); } } try { if (item.ContentItemId > 0) { contentItemService.Update(item); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功"); //清除标签 tagService.ClearTagsFromItem(item.ContentItemId, item.UserId); } else { if (!authorizer.CMS_ManageContentFolder(item.ContentFolder)) { item.IsContributed = true; } item.ReleaseDate = DateTime.UtcNow; contentItemService.Create(item); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "创建成功"); } } catch { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "创建或者更新失败,请重试"); TempData["ContentItemEditModel"] = model; return(Redirect(SiteUrls.Instance().Contribute(item.ContentItemId))); } string tags = string.Join(",", model.TagNames); if (!string.IsNullOrEmpty(tags)) { tagService.AddTagsToItem(tags, item.UserId, item.ContentItemId); } return(Redirect(SiteUrls.Instance().ContentItemDetail(item.ContentItemId))); }
public ActionResult Contribute(ContentItemEditModel model) { ContentItem item = model.AsContentItem(Request); var contentItemService = new ContentItemService(); string errorMessage = string.Empty; if (item.ContentItemId > 0) { if (!authorizer.CMS_EditContentItem(item)) { errorMessage = "没有权限编辑资讯:" + item.Title; return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "没有权限", StatusMessageType = StatusMessageType.Hint }, Request.RawUrl)); } } else { if (!authorizer.CMS_Contribute(out errorMessage)) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "没有权限", StatusMessageType = StatusMessageType.Hint }, Request.RawUrl)); } } try { if (item.ContentItemId > 0) { contentItemService.Update(item); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功"); //清除标签 tagService.ClearTagsFromItem(item.ContentItemId, item.UserId); } else { if (!authorizer.CMS_ManageContentFolder(item.ContentFolder)) item.IsContributed = true; item.ReleaseDate = DateTime.UtcNow; contentItemService.Create(item); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "创建成功"); } } catch { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "创建或者更新失败,请重试"); TempData["ContentItemEditModel"] = model; return Redirect(SiteUrls.Instance().Contribute(item.ContentItemId)); } string tags = string.Join(",", model.TagNames); if (!string.IsNullOrEmpty(tags)) { tagService.AddTagsToItem(tags, item.UserId, item.ContentItemId); } return Redirect(SiteUrls.Instance().ContentItemDetail(item.ContentItemId)); }