public void InsertComboboxDropdownListItemsDynamically(SdtType sdtType)
        {
            const string template =
                "<<item[\"three\"] [\"3\"]>><<if [false]>><<item [\"four\"] [null]>><</if>><<item[\"five\"] [\"5\"]>>";

            SdtListItem[] staticItems =
            {
                new SdtListItem("1", "one"),
                new SdtListItem("2", "two")
            };

            Document doc = new Document();

            StructuredDocumentTag sdt = new StructuredDocumentTag(doc, sdtType, MarkupLevel.Block)
            {
                Title = template
            };

            foreach (SdtListItem item in staticItems)
            {
                sdt.ListItems.Add(item);
            }

            doc.FirstSection.Body.AppendChild(sdt);

            BuildReport(doc, new object(), "");

            doc.Save(ArtifactsDir + $"ReportingEngine.InsertComboboxDropdownListItemsDynamically_{sdtType}.docx");

            doc = new Document(ArtifactsDir +
                               $"ReportingEngine.InsertComboboxDropdownListItemsDynamically_{sdtType}.docx");

            sdt = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);

            SdtListItem[] expectedItems =
            {
                new SdtListItem("1", "one"),
                new SdtListItem("2", "two"),
                new SdtListItem("3", "three"),
                new SdtListItem("5", "five")
            };

            Assert.AreEqual(expectedItems.Length, sdt.ListItems.Count);

            for (int i = 0; i < expectedItems.Length; i++)
            {
                Assert.AreEqual(expectedItems[i].Value, sdt.ListItems[i].Value);
                Assert.AreEqual(expectedItems[i].DisplayText, sdt.ListItems[i].DisplayText);
            }
        }
Exemplo n.º 2
0
        private void SetupAndInsertSdt(RadFlowDocumentEditor editor, InlineBase inline, string text, SdtType sdtType, DocumentElementBase start = null, DocumentElementBase end = null)
        {
            if (sdtType == SdtType.RepeatingSection)
            {
                editor.MoveToParagraphStart(inline.Paragraph);
            }
            else
            {
                editor.MoveToInlineStart(inline);
            }

            SdtProperties sdt = new SdtProperties(sdtType)
            {
                // All SDTs should not allow deleting them
                Lock = Lock.SdtLocked
            };

            if (!string.IsNullOrEmpty(text))
            {
                // Add a placeholder if text for it is available.
                sdt.Placeholder = new Placeholder()
                {
                    PlaceholderText = text,
                    ShowPlaceholder = true
                };
            }

            if (start == null)
            {
                editor.InsertStructuredDocumentTag(sdt);
            }
            else
            {
                end = end ?? start;
                editor.InsertStructuredDocumentTag(sdt, start, end);
            }
        }