public void Publishes_Many_Ignores_Invalid_Items_And_Children() { var testData = CreateTestData(); //Create some other data which are descendants of Text Page 2 var mandatorContent = MockedContent.CreateSimpleContent( ServiceContext.ContentTypeService.GetContentType("umbMandatory"), "Invalid Content", testData.Single(x => x.Name == "Text Page 2").Id); mandatorContent.SetValue("author", string.Empty); ServiceContext.ContentService.Save(mandatorContent, 0); var subContent = MockedContent.CreateSimpleContent( ServiceContext.ContentTypeService.GetContentType("umbTextpage"), "Sub Sub Sub", mandatorContent.Id); ServiceContext.ContentService.Save(subContent, 0); var strategy = new PublishingStrategy(); //publish root and nodes at it's children level var listToPublish = ServiceContext.ContentService.GetDescendants(_homePage.Id).Concat(new[] { _homePage }); var result = strategy.PublishWithChildrenInternal(listToPublish, 0, true); Assert.AreEqual(listToPublish.Count() - 2, result.Count(x => x.Success)); Assert.IsTrue(result.Where(x => x.Success).Select(x => x.Result.ContentItem.Id) .ContainsAll(listToPublish.Where(x => x.Name != "Invalid Content" && x.Name != "Sub Sub Sub").Select(x => x.Id))); }
public void Publishes_Many_Ignores_Cancelled_Items_And_Children() { CreateTestData(); var strategy = new PublishingStrategy(); PublishingStrategy.Publishing +=PublishingStrategyPublishing; //publish root and nodes at it's children level var listToPublish = ServiceContext.ContentService.GetDescendants(_homePage.Id).Concat(new[] {_homePage}); var result = strategy.PublishWithChildrenInternal(listToPublish, 0); Assert.AreEqual(listToPublish.Count() - 2, result.Count(x => x.Success)); Assert.IsTrue(result.Where(x => x.Success).Select(x => x.Result.ContentItem.Id) .ContainsAll(listToPublish.Where(x => x.Name != "Text Page 2" && x.Name != "Text Page 3").Select(x => x.Id))); }
public void Publishes_Many_Ignores_Unpublished_Items() { CreateTestData(); var strategy = new PublishingStrategy(); //publish root and nodes at it's children level var result1 = strategy.Publish(_homePage, 0); Assert.IsTrue(result1); Assert.IsTrue(_homePage.Published); foreach (var c in ServiceContext.ContentService.GetChildren(_homePage.Id)) { var r = strategy.Publish(c, 0); Assert.IsTrue(r); Assert.IsTrue(c.Published); } //ok, all are published except the deepest descendant, we will pass in a flag to not include it to //be published var result = strategy.PublishWithChildrenInternal( ServiceContext.ContentService.GetDescendants(_homePage).Concat(new[] {_homePage}), 0, false); //all of them will be SuccessAlreadyPublished unless the unpublished one gets included, in that case //we'll have a 'Success' result which we don't want. Assert.AreEqual(0, result.Count(x => x.Result.StatusType == PublishStatusType.Success)); }
public void Publishes_Many_Does_Not_Ignore_Unpublished_Items() { CreateTestData(); var strategy = new PublishingStrategy(); //publish root and nodes at it's children level var result1 = strategy.Publish(_homePage, 0); Assert.IsTrue(result1); Assert.IsTrue(_homePage.Published); //NOTE (MCH) This isn't persisted, so not really a good test as it will look like the result should be something else. foreach (var c in ServiceContext.ContentService.GetChildren(_homePage.Id)) { var r = strategy.Publish(c, 0); Assert.IsTrue(r); Assert.IsTrue(c.Published); } //NOTE (MCH) when doing the test like this the Publish status will not actually have been persisted //since its only updating a property. The actual persistence and publishing is done through the ContentService. //So when descendants are fetched from the ContentService the Publish status will be "reset", which //means the result will be 1 'SuccessAlreadyPublished' and 3 'Success' because the Homepage is //inserted in the list and since that item has the status of already being Published it will be the one item //with 'SuccessAlreadyPublished' var descendants = ServiceContext.ContentService.GetDescendants(_homePage).Concat(new[] {_homePage}); var result = strategy.PublishWithChildrenInternal(descendants, 0, true); Assert.AreEqual(3, result.Count(x => x.Result.StatusType == PublishStatusType.Success)); Assert.AreEqual(1, result.Count(x => x.Result.StatusType == PublishStatusType.SuccessAlreadyPublished)); Assert.IsTrue(result.First(x => x.Result.StatusType == PublishStatusType.Success).Success); Assert.IsTrue(result.First(x => x.Result.StatusType == PublishStatusType.Success).Result.ContentItem.Published); }
public void Publishes_Many_Does_Not_Ignore_Unpublished_Items() { CreateTestData(); var strategy = new PublishingStrategy(); //publish root and nodes at it's children level var result1 = strategy.Publish(_homePage, 0); Assert.IsTrue(result1); Assert.IsTrue(_homePage.Published); foreach (var c in ServiceContext.ContentService.GetChildren(_homePage.Id)) { var r = strategy.Publish(c, 0); Assert.IsTrue(r); Assert.IsTrue(c.Published); } //ok, all are published except the deepest descendant, we will pass in a flag to include it to //be published var result = strategy.PublishWithChildrenInternal( ServiceContext.ContentService.GetDescendants(_homePage).Concat(new[] { _homePage }), 0, true); //there will be 4 here but only one "Success" the rest will be "SuccessAlreadyPublished" Assert.AreEqual(1, result.Count(x => x.Result.StatusType == PublishStatusType.Success)); Assert.AreEqual(3, result.Count(x => x.Result.StatusType == PublishStatusType.SuccessAlreadyPublished)); Assert.IsTrue(result.Single(x => x.Result.StatusType == PublishStatusType.Success).Success); Assert.IsTrue(result.Single(x => x.Result.StatusType == PublishStatusType.Success).Result.ContentItem.Published); }