private void AssertItemRendersWithoutException(IdentifiableObjectData item, IdentifiableObjectData template) { string testPublicationId = TestContext.Properties["TestPublicationId"].ToString(); string localisedItemId = Client.GetTcmUri(item.Id, testPublicationId, null); string localisedTemplateId = Client.GetTcmUri(template.Id, testPublicationId, null); // We check if the template exists at this publication level as the schema where used query // might give us templates that might only exist elsewhere in the blueprint if (Client.IsExistingObject(localisedTemplateId) && !this.renderedTemplates.Contains(localisedTemplateId)) { try { this.renderedTemplates.Add(localisedTemplateId); RenderedItemData renderedItem = new RenderedItemData(); RenderInstructionData renderInstruction = new RenderInstructionData(); renderInstruction.RenderMode = RenderMode.PreviewStatic; PublishInstructionData previewInstruction = new PublishInstructionData(); ResolveInstructionData resolveInstruction = new ResolveInstructionData(); previewInstruction.RenderInstruction = renderInstruction; previewInstruction.ResolveInstruction = resolveInstruction; stopwatch.Restart(); renderedItem = Client.RenderItem(localisedItemId, localisedTemplateId, previewInstruction, "tcm:0-1-65537"); long timeToRender = stopwatch.ElapsedMilliseconds; if (renderedItem.Content != null) { string renderedContent = System.Text.Encoding.Default.GetString(renderedItem.Content); this.LogMessage(String.Format("Rendering with template \"{0}\" ({1}) succeeded and took {2} milliseconds.", template.Title, localisedTemplateId, timeToRender)); Assert.IsNotNull(renderedContent); } else { this.LogMessage(String.Format("ALERT: Rendering with template \"{0}\" ({1}) resulted in null content and took {2} milliseconds.", template.Title, localisedTemplateId, timeToRender)); } } catch (System.ServiceModel.FaultException ex) { string failMessage = String.Format("TEST FAILED! Failed when rendering item {0} ({1}) with template {2} ({3}) {4}. Exception: {5}", item.Id, item.Title, template.Id, template.Title, Environment.NewLine + Environment.NewLine, ex.Message); this.LogMessage(failMessage); Assert.Fail(failMessage); } } }
private string RenderItem(string itemId, string templateId) { try { this.OpenSession(); ResolveInstructionData resolveInstruction = new ResolveInstructionData() { IncludeWorkflow = true, IncludeComponentLinks = false, IncludeChildPublications = false, Purpose = ResolvePurpose.Publish, StructureResolveOption = StructureResolveOption.OnlyItems }; RenderInstructionData renderInstruction = new RenderInstructionData() { RenderMode = RenderMode.PreviewDynamic }; PublishInstructionData publishInstruction = new PublishInstructionData() { MaximumNumberOfRenderFailures = 0, ResolveInstruction = resolveInstruction, RenderInstruction = renderInstruction, StartAt = DateTime.UtcNow, DeployAt = DateTime.MinValue }; RenderedItemData result = session.RenderItem(itemId, templateId, publishInstruction, TcmUri.UriNull.ToString()); if (result.Content != null && result.Content.Length > 0) { string contents = System.Text.Encoding.UTF8.GetString(result.Content); return(contents); } } catch (Exception ex) { return(null); } finally { this.CloseSession(); } return(""); }